GenAttributes.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * Tencent is pleased to support the open source community by making xLua available.
  3. * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
  4. * Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
  5. * http://opensource.org/licenses/MIT
  6. * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
  7. */
  8. using System;
  9. using System.Collections.Generic;
  10. namespace XLua
  11. {
  12. public enum GenFlag
  13. {
  14. No = 0,
  15. [Obsolete("use GCOptimizeAttribute instead")]
  16. GCOptimize = 1
  17. }
  18. //如果你要生成Lua调用CSharp的代码,加这个标签
  19. public class LuaCallCSharpAttribute : Attribute
  20. {
  21. GenFlag flag;
  22. public GenFlag Flag {
  23. get
  24. {
  25. return flag;
  26. }
  27. }
  28. public LuaCallCSharpAttribute(GenFlag flag = GenFlag.No)
  29. {
  30. this.flag = flag;
  31. }
  32. }
  33. //生成CSharp调用Lua,加这标签
  34. //[AttributeUsage(AttributeTargets.Delegate | AttributeTargets.Interface)]
  35. public class CSharpCallLuaAttribute : Attribute
  36. {
  37. }
  38. //如果某属性、方法不需要生成,加这个标签
  39. public class BlackListAttribute : Attribute
  40. {
  41. }
  42. [Flags]
  43. public enum OptimizeFlag
  44. {
  45. Default = 0,
  46. PackAsTable = 1
  47. }
  48. //如果想对struct生成免GC代码,加这个标签
  49. public class GCOptimizeAttribute : Attribute
  50. {
  51. OptimizeFlag flag;
  52. public OptimizeFlag Flag
  53. {
  54. get
  55. {
  56. return flag;
  57. }
  58. }
  59. public GCOptimizeAttribute(OptimizeFlag flag = OptimizeFlag.Default)
  60. {
  61. this.flag = flag;
  62. }
  63. }
  64. //如果想在反射下使用,加这个标签
  65. public class ReflectionUseAttribute : Attribute
  66. {
  67. }
  68. //只能标注Dictionary<Type, List<string>>的field或者property
  69. public class DoNotGenAttribute : Attribute
  70. {
  71. }
  72. public class AdditionalPropertiesAttribute : Attribute
  73. {
  74. }
  75. [Flags]
  76. public enum HotfixFlag
  77. {
  78. Stateless = 0,
  79. [Obsolete("use xlua.util.state instead!", true)]
  80. Stateful = 1,
  81. ValueTypeBoxing = 2,
  82. IgnoreProperty = 4,
  83. IgnoreNotPublic = 8,
  84. Inline = 16,
  85. IntKey = 32,
  86. AdaptByDelegate = 64,
  87. IgnoreCompilerGenerated = 128,
  88. NoBaseProxy = 256,
  89. }
  90. public class HotfixAttribute : Attribute
  91. {
  92. HotfixFlag flag;
  93. public HotfixFlag Flag
  94. {
  95. get
  96. {
  97. return flag;
  98. }
  99. }
  100. public HotfixAttribute(HotfixFlag e = HotfixFlag.Stateless)
  101. {
  102. flag = e;
  103. }
  104. }
  105. [AttributeUsage(AttributeTargets.Delegate)]
  106. internal class HotfixDelegateAttribute : Attribute
  107. {
  108. }
  109. #if !XLUA_GENERAL
  110. public static class SysGenConfig
  111. {
  112. [GCOptimize]
  113. static List<Type> GCOptimize
  114. {
  115. get
  116. {
  117. return new List<Type>() {
  118. typeof(UnityEngine.Vector2),
  119. typeof(UnityEngine.Vector3),
  120. typeof(UnityEngine.Vector4),
  121. typeof(UnityEngine.Color),
  122. typeof(UnityEngine.Quaternion),
  123. typeof(UnityEngine.Ray),
  124. typeof(UnityEngine.Bounds),
  125. typeof(UnityEngine.Ray2D),
  126. };
  127. }
  128. }
  129. [AdditionalProperties]
  130. static Dictionary<Type, List<string>> AdditionalProperties
  131. {
  132. get
  133. {
  134. return new Dictionary<Type, List<string>>()
  135. {
  136. { typeof(UnityEngine.Ray), new List<string>() { "origin", "direction" } },
  137. { typeof(UnityEngine.Ray2D), new List<string>() { "origin", "direction" } },
  138. { typeof(UnityEngine.Bounds), new List<string>() { "center", "extents" } },
  139. };
  140. }
  141. }
  142. }
  143. #endif
  144. }