Attributes.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. using CommonLang;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. namespace CommonAI.Zone.Attributes
  6. {
  7. //-----------------------------------------------------------
  8. [AttributeUsage(AttributeTargets.Field)]
  9. public class ColorValueAttribute : System.Attribute
  10. {
  11. public static readonly int COLOR_GREEN = FromARGB(0xff, 0x00, 0xff, 0x00);
  12. public static readonly int COLOR_LIGHT_GREEN = FromARGB(0xff, 0x80, 0xff, 0x80);
  13. public static readonly int COLOR_DARK_GRAY = FromARGB(0xff, 0x40, 0x40, 0x40);
  14. public static readonly int COLOR_RED = FromARGB(0xff, 0xff, 0x00, 0x00);
  15. public static readonly int COLOR_LIGHT_BLUE = FromARGB(0xff, 0x80, 0x80, 0xff);
  16. public static int FromARGB(float a, float r, float g, float b)
  17. {
  18. int ARGB = 0;
  19. ARGB |= ((int)CMath.getInRange(a * 255, 0, 255)) << 24;
  20. ARGB |= ((int)CMath.getInRange(r * 255, 0, 255)) << 16;
  21. ARGB |= ((int)CMath.getInRange(g * 255, 0, 255)) << 8;
  22. ARGB |= ((int)CMath.getInRange(b * 255, 0, 255));
  23. return ARGB;
  24. }
  25. public static int FromARGB(int a, int r, int g, int b)
  26. {
  27. int ARGB = 0;
  28. ARGB |= ((int)CMath.getInRange(a, 0, 255)) << 24;
  29. ARGB |= ((int)CMath.getInRange(r, 0, 255)) << 16;
  30. ARGB |= ((int)CMath.getInRange(g, 0, 255)) << 8;
  31. ARGB |= ((int)CMath.getInRange(b, 0, 255));
  32. return ARGB;
  33. }
  34. }
  35. //-----------------------------------------------------------
  36. /// <summary>
  37. /// 标识 Field Int32 字段为 类型的模板ID
  38. /// </summary>
  39. [AttributeUsage(AttributeTargets.Field)]
  40. public class TemplateIDAttribute : System.Attribute
  41. {
  42. private Type templateType;
  43. public TemplateIDAttribute(Type templateType)
  44. {
  45. this.templateType = templateType;
  46. }
  47. public Type TemplateType
  48. {
  49. get { return templateType; }
  50. }
  51. }
  52. //-----------------------------------------------------------
  53. /// <summary>
  54. /// 标识 Field Int32 字段为 UnitInfo 模板ID的等级
  55. /// </summary>
  56. [AttributeUsage(AttributeTargets.Field)]
  57. public class TemplateLevelAttribute : System.Attribute
  58. {
  59. public TemplateLevelAttribute()
  60. {
  61. }
  62. }
  63. //-----------------------------------------------------------
  64. /// <summary>
  65. /// 标识 Field 数组或List字段为 Int32 类型的模板ID
  66. /// </summary>
  67. [AttributeUsage(AttributeTargets.Field)]
  68. public class TemplatesIDAttribute : System.Attribute
  69. {
  70. private Type templateType;
  71. public TemplatesIDAttribute(Type templateType)
  72. {
  73. this.templateType = templateType;
  74. }
  75. public Type TemplateType
  76. {
  77. get { return templateType; }
  78. }
  79. }
  80. //-----------------------------------------------------------
  81. /// <summary>
  82. /// 标识 Field 字段为资源文件
  83. /// </summary>
  84. [AttributeUsage(AttributeTargets.Field)]
  85. public class ResourceIDAttribute : System.Attribute
  86. {
  87. }
  88. //-----------------------------------------------------------
  89. /// <summary>
  90. /// 标识 Field 字段为场景单位 Name
  91. /// </summary>
  92. [AttributeUsage(AttributeTargets.Field)]
  93. public class SceneObjectIDAttribute : System.Attribute
  94. {
  95. private Type objectType;
  96. public SceneObjectIDAttribute(Type objectType)
  97. {
  98. this.objectType = objectType;
  99. }
  100. public Type ObjectType
  101. {
  102. get { return objectType; }
  103. }
  104. }
  105. //-----------------------------------------------------------
  106. /// <summary>
  107. /// 标识 Field 字段为场景事件触发 Name
  108. /// </summary>
  109. [AttributeUsage(AttributeTargets.Field)]
  110. public class SceneEventIDAttribute : System.Attribute
  111. {
  112. }
  113. //-----------------------------------------------------------
  114. /// <summary>
  115. /// 标识 Field 字段为场景环境变量 Key
  116. /// </summary>
  117. [AttributeUsage(AttributeTargets.Field)]
  118. public class SceneVarIDAttribute : System.Attribute
  119. {
  120. public readonly Type VarType;
  121. public SceneVarIDAttribute(Type varType)
  122. {
  123. this.VarType = varType;
  124. }
  125. }
  126. /// <summary>
  127. /// 标识 Field 字段为临时变量 Key
  128. /// </summary>
  129. [AttributeUsage(AttributeTargets.Field)]
  130. public class LocalVarIDAttribute : System.Attribute
  131. {
  132. public readonly Type VarType;
  133. public LocalVarIDAttribute(Type varType)
  134. {
  135. this.VarType = varType;
  136. }
  137. }
  138. //-----------------------------------------------------------
  139. /// <summary>
  140. /// 标识 Field 字段为 脚本文件
  141. /// </summary>
  142. [AttributeUsage(AttributeTargets.Field)]
  143. public class SceneScriptIDAttribute : System.Attribute
  144. {
  145. }
  146. //-----------------------------------------------------------
  147. /// <summary>
  148. /// 标识 UnitTrigger (单位被动系) 触发类型。
  149. /// </summary>
  150. [AttributeUsage(AttributeTargets.Class)]
  151. public class UnitTriggerEventTypeAttribute : System.Attribute
  152. {
  153. private Type[] delegateTypes;
  154. public UnitTriggerEventTypeAttribute(params Type[] delegateTypes)
  155. {
  156. this.delegateTypes = delegateTypes;
  157. }
  158. public Type[] DelegateTypes
  159. {
  160. get { return delegateTypes; }
  161. }
  162. }
  163. //-----------------------------------------------------------
  164. //-----------------------------------------------------------
  165. /// <summary>
  166. /// 标识 Field 字段为单位事件触发 Name
  167. /// </summary>
  168. [AttributeUsage(AttributeTargets.Field)]
  169. public class UnitEventIDAttribute : System.Attribute
  170. {
  171. }
  172. //-----------------------------------------------------------
  173. /// <summary>
  174. /// 标记对象字段名字,用于AbstractValue取Field
  175. /// </summary>
  176. [AttributeUsage(AttributeTargets.Field)]
  177. public class ObjectMemberNameAttribute : System.Attribute
  178. {
  179. public readonly Type ObjectType;
  180. public readonly Type FieldType;
  181. public ObjectMemberNameAttribute(Type fieldType)
  182. {
  183. this.ObjectType = null;
  184. this.FieldType = fieldType;
  185. }
  186. public ObjectMemberNameAttribute(Type objType, Type fieldType)
  187. {
  188. this.ObjectType = objType;
  189. this.FieldType = fieldType;
  190. }
  191. }
  192. //-----------------------------------------------------------
  193. /// <summary>
  194. /// 标记对象字段名字,用于生成Language.csv
  195. /// </summary>
  196. [AttributeUsage(AttributeTargets.Field)]
  197. public class LocalizationTextAttribute : System.Attribute
  198. {
  199. public LocalizationTextAttribute()
  200. {
  201. }
  202. }
  203. //-----------------------------------------------------------
  204. /// <summary>
  205. /// 标记对象字段名字,用于AbstractValue取QuestID
  206. /// </summary>
  207. [AttributeUsage(AttributeTargets.Field)]
  208. public class QuestIDAttribute : System.Attribute
  209. {
  210. public QuestIDAttribute()
  211. {
  212. }
  213. }
  214. //-----------------------------------------------------------
  215. /// <summary>
  216. /// 标记 event 是否可以在编辑时反射成事件触发器
  217. /// </summary>
  218. [AttributeUsage(AttributeTargets.Event | AttributeTargets.Property | AttributeTargets.Field)]
  219. public class EventTriggerDescAttribute : System.Attribute
  220. {
  221. public string Description { get; private set; }
  222. public EventTriggerDescAttribute(string desc)
  223. {
  224. this.Description = desc;
  225. }
  226. }
  227. //-----------------------------------------------------------
  228. //-----------------------------------------------------------
  229. }