EntityFactory.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. using System;
  2. namespace ET
  3. {
  4. public static class EntityFactory
  5. {
  6. public static Entity CreateWithParent(Type type, Entity parent)
  7. {
  8. Entity component = Entity.Create(type, true);
  9. component.Id = IdGenerater.GenerateId();
  10. component.Parent = parent;
  11. EventSystem.Instance.Awake(component);
  12. return component;
  13. }
  14. public static T CreateWithParent<T>(Entity parent) where T : Entity
  15. {
  16. Type type = typeof (T);
  17. T component = (T)Entity.Create(type, true);
  18. component.Id = IdGenerater.GenerateId();
  19. component.Parent = parent;
  20. EventSystem.Instance.Awake(component);
  21. return component;
  22. }
  23. public static T CreateWithParent<T, A>(Entity parent, A a) where T : Entity
  24. {
  25. Type type = typeof (T);
  26. T component = (T)Entity.Create(type, true);
  27. component.Id = IdGenerater.GenerateId();
  28. component.Parent = parent;
  29. EventSystem.Instance.Awake(component, a);
  30. return component;
  31. }
  32. public static T CreateWithParent<T, A, B>(Entity parent, A a, B b) where T : Entity
  33. {
  34. Type type = typeof (T);
  35. T component = (T)Entity.Create(type, true);
  36. component.Id = IdGenerater.GenerateId();
  37. component.Parent = parent;
  38. EventSystem.Instance.Awake(component, a, b);
  39. return component;
  40. }
  41. public static T CreateWithParent<T, A, B, C>(Entity parent, A a, B b, C c, bool fromPool = true) where T : Entity
  42. {
  43. Type type = typeof (T);
  44. T component = (T)Entity.Create(type, true);
  45. component.Id = IdGenerater.GenerateId();
  46. component.Parent = parent;
  47. EventSystem.Instance.Awake(component, a, b, c);
  48. return component;
  49. }
  50. public static T CreateWithParent<T, A, B, C, D>(Entity parent, A a, B b, C c, D d, bool fromPool = true) where T : Entity
  51. {
  52. Type type = typeof(T);
  53. T component = (T)Entity.Create(type, true);
  54. component.Id = IdGenerater.GenerateId();
  55. component.Parent = parent;
  56. EventSystem.Instance.Awake(component, a, b, c, d);
  57. return component;
  58. }
  59. public static Entity CreateWithParentAndId(Type type, Entity parent, long id)
  60. {
  61. Entity component = Entity.Create(type, true);
  62. component.Id = id;
  63. component.Parent = parent;
  64. EventSystem.Instance.Awake(component);
  65. return component;
  66. }
  67. public static T CreateWithParentAndId<T>(Entity parent, long id) where T : Entity
  68. {
  69. Type type = typeof (T);
  70. T component = (T)Entity.Create(type, true);
  71. component.Id = id;
  72. component.Parent = parent;
  73. EventSystem.Instance.Awake(component);
  74. return component;
  75. }
  76. public static T CreateWithParentAndId<T, A>(Entity parent, long id, A a) where T : Entity
  77. {
  78. Type type = typeof (T);
  79. T component = (T)Entity.Create(type, true);
  80. component.Id = id;
  81. component.Parent = parent;
  82. EventSystem.Instance.Awake(component, a);
  83. return component;
  84. }
  85. public static T CreateWithParentAndId<T, A, B>(Entity parent, long id, A a, B b) where T : Entity
  86. {
  87. Type type = typeof (T);
  88. T component = (T)Entity.Create(type, true);
  89. component.Id = id;
  90. component.Parent = parent;
  91. EventSystem.Instance.Awake(component, a, b);
  92. return component;
  93. }
  94. public static T CreateWithParentAndId<T, A, B, C>(Entity parent, long id, A a, B b, C c, bool fromPool = true) where T : Entity
  95. {
  96. Type type = typeof (T);
  97. T component = (T)Entity.Create(type, true);
  98. component.Id = id;
  99. component.Parent = parent;
  100. EventSystem.Instance.Awake(component, a, b, c);
  101. return component;
  102. }
  103. public static T CreateWithParentAndId<T, A, B, C, D>(Entity parent, long id, A a, B b, C c, D d, bool fromPool = true) where T : Entity
  104. {
  105. Type type = typeof(T);
  106. T component = (T)Entity.Create(type, true);
  107. component.Id = id;
  108. component.Parent = parent;
  109. EventSystem.Instance.Awake(component, a, b, c, d);
  110. return component;
  111. }
  112. public static Entity Create(Entity domain, Type type)
  113. {
  114. Entity component = Entity.Create(type, true);
  115. component.Domain = domain;
  116. component.Id = IdGenerater.GenerateId();
  117. EventSystem.Instance.Awake(component);
  118. return component;
  119. }
  120. public static T Create<T>(Entity domain) where T : Entity
  121. {
  122. Type type = typeof (T);
  123. T component = (T)Entity.Create(type, true);
  124. component.Domain = domain;
  125. component.Id = IdGenerater.GenerateId();
  126. EventSystem.Instance.Awake(component);
  127. return component;
  128. }
  129. public static T Create<T, A>(Entity domain, A a) where T : Entity
  130. {
  131. Type type = typeof (T);
  132. T component = (T)Entity.Create(type, true);
  133. component.Domain = domain;
  134. component.Id = IdGenerater.GenerateId();
  135. EventSystem.Instance.Awake(component, a);
  136. return component;
  137. }
  138. public static T Create<T, A, B>(Entity domain, A a, B b) where T : Entity
  139. {
  140. Type type = typeof (T);
  141. T component = (T)Entity.Create(type, true);
  142. component.Domain = domain;
  143. component.Id = IdGenerater.GenerateId();
  144. EventSystem.Instance.Awake(component, a, b);
  145. return component;
  146. }
  147. public static T Create<T, A, B, C>(Entity domain, A a, B b, C c) where T : Entity
  148. {
  149. Type type = typeof (T);
  150. T component = (T)Entity.Create(type, true);
  151. component.Domain = domain;
  152. component.Id = IdGenerater.GenerateId();
  153. EventSystem.Instance.Awake(component, a, b, c);
  154. return component;
  155. }
  156. public static T CreateWithId<T>(Entity domain, long id) where T : Entity
  157. {
  158. Type type = typeof (T);
  159. T component = (T)Entity.Create(type, true);
  160. component.Domain = domain;
  161. component.Id = id;
  162. EventSystem.Instance.Awake(component);
  163. return component;
  164. }
  165. public static T CreateWithId<T, A>(Entity domain, long id, A a) where T : Entity
  166. {
  167. Type type = typeof (T);
  168. T component = (T)Entity.Create(type, true);
  169. component.Domain = domain;
  170. component.Id = id;
  171. EventSystem.Instance.Awake(component, a);
  172. return component;
  173. }
  174. public static T CreateWithId<T, A, B>(Entity domain, long id, A a, B b) where T : Entity
  175. {
  176. Type type = typeof (T);
  177. T component = (T)Entity.Create(type, true);
  178. component.Domain = domain;
  179. component.Id = id;
  180. EventSystem.Instance.Awake(component, a, b);
  181. return component;
  182. }
  183. public static T CreateWithId<T, A, B, C>(Entity domain, long id, A a, B b, C c) where T : Entity
  184. {
  185. Type type = typeof (T);
  186. T component = (T)Entity.Create(type, true);
  187. component.Domain = domain;
  188. component.Id = id;
  189. EventSystem.Instance.Awake(component, a, b, c);
  190. return component;
  191. }
  192. }
  193. }