EntityFactory.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. using System;
  2. using ETModel;
  3. namespace ETHotfix
  4. {
  5. public static class EntityFactory
  6. {
  7. public static Entity CreateWithParent(Type type, Entity parent)
  8. {
  9. Entity component = Game.ObjectPool.Fetch(type);
  10. component.Domain = parent.Domain;
  11. component.Id = component.InstanceId;
  12. component.Parent = parent;
  13. Game.EventSystem.Awake(component);
  14. return component;
  15. }
  16. public static T CreateWithParent<T>(Entity parent) where T : Entity
  17. {
  18. Type type = typeof (T);
  19. T component = (T)Game.ObjectPool.Fetch(type);
  20. component.Domain = parent.Domain;
  21. component.Id = component.InstanceId;
  22. component.Parent = parent;
  23. Game.EventSystem.Awake(component);
  24. return component;
  25. }
  26. public static T CreateWithParent<T, A>(Entity parent, A a) where T : Entity
  27. {
  28. Type type = typeof (T);
  29. T component = (T)Game.ObjectPool.Fetch(type);
  30. component.Domain = parent.Domain;
  31. component.Id = component.InstanceId;
  32. component.Parent = parent;
  33. Game.EventSystem.Awake(component, a);
  34. return component;
  35. }
  36. public static T CreateWithParent<T, A, B>(Entity parent, A a, B b) where T : Entity
  37. {
  38. Type type = typeof (T);
  39. T component = (T)Game.ObjectPool.Fetch(type);
  40. component.Domain = parent.Domain;
  41. component.Id = component.InstanceId;
  42. component.Parent = parent;
  43. Game.EventSystem.Awake(component, a, b);
  44. return component;
  45. }
  46. public static T CreateWithParent<T, A, B, C>(Entity parent, A a, B b, C c, bool fromPool = true) where T : Entity
  47. {
  48. Type type = typeof (T);
  49. T component = (T)Game.ObjectPool.Fetch(type);
  50. component.Domain = parent.Domain;
  51. component.Id = component.InstanceId;
  52. component.Parent = parent;
  53. Game.EventSystem.Awake(component, a, b, c);
  54. return component;
  55. }
  56. 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
  57. {
  58. Type type = typeof(T);
  59. T component = (T)Game.ObjectPool.Fetch(type);
  60. component.Domain = parent.Domain;
  61. component.Id = component.InstanceId;
  62. component.Parent = parent;
  63. Game.EventSystem.Awake(component, a, b, c, d);
  64. return component;
  65. }
  66. public static Entity Create(Entity domain, Type type)
  67. {
  68. Entity component = Game.ObjectPool.Fetch(type);
  69. component.Domain = domain ?? component;
  70. component.Id = component.InstanceId;
  71. Game.EventSystem.Awake(component);
  72. return component;
  73. }
  74. public static T Create<T>(Entity domain) where T : Entity
  75. {
  76. Type type = typeof (T);
  77. T component = (T)Game.ObjectPool.Fetch(type);
  78. component.Domain = domain ?? component;
  79. component.Id = component.InstanceId;
  80. Game.EventSystem.Awake(component);
  81. return component;
  82. }
  83. public static T Create<T, A>(Entity domain, A a) where T : Entity
  84. {
  85. Type type = typeof (T);
  86. T component = (T)Game.ObjectPool.Fetch(type);
  87. component.Domain = domain ?? component;
  88. component.Id = component.InstanceId;
  89. Game.EventSystem.Awake(component, a);
  90. return component;
  91. }
  92. public static T Create<T, A, B>(Entity domain, A a, B b) where T : Entity
  93. {
  94. Type type = typeof (T);
  95. T component = (T)Game.ObjectPool.Fetch(type);
  96. component.Domain = domain ?? component;
  97. component.Id = component.InstanceId;
  98. Game.EventSystem.Awake(component, a, b);
  99. return component;
  100. }
  101. public static T Create<T, A, B, C>(Entity domain, A a, B b, C c) where T : Entity
  102. {
  103. Type type = typeof (T);
  104. T component = (T) Game.ObjectPool.Fetch(type);
  105. component.Domain = domain ?? component;
  106. component.Id = component.InstanceId;
  107. Game.EventSystem.Awake(component, a, b, c);
  108. return component;
  109. }
  110. public static T CreateWithId<T>(Entity domain, long id) where T : Entity
  111. {
  112. Type type = typeof (T);
  113. T component = (T)Game.ObjectPool.Fetch(type);
  114. component.Domain = domain ?? component;
  115. component.Id = id;
  116. Game.EventSystem.Awake(component);
  117. return component;
  118. }
  119. public static T CreateWithId<T, A>(Entity domain, long id, A a) where T : Entity
  120. {
  121. Type type = typeof (T);
  122. T component = (T)Game.ObjectPool.Fetch(type);
  123. component.Domain = domain ?? component;
  124. component.Id = id;
  125. Game.EventSystem.Awake(component, a);
  126. return component;
  127. }
  128. public static T CreateWithId<T, A, B>(Entity domain, long id, A a, B b) where T : Entity
  129. {
  130. Type type = typeof (T);
  131. T component = (T)Game.ObjectPool.Fetch(type);
  132. component.Domain = domain ?? component;
  133. component.Id = id;
  134. Game.EventSystem.Awake(component, a, b);
  135. return component;
  136. }
  137. public static T CreateWithId<T, A, B, C>(Entity domain, long id, A a, B b, C c) where T : Entity
  138. {
  139. Type type = typeof (T);
  140. T component = (T)Game.ObjectPool.Fetch(type);
  141. component.Domain = domain ?? component;
  142. component.Id = id;
  143. Game.EventSystem.Awake(component, a, b, c);
  144. return component;
  145. }
  146. public static Scene CreateScene(SceneType sceneType, string name, Scene parent = null,long id = 0)
  147. {
  148. Scene scene = (Scene)Game.ObjectPool.Fetch(typeof(Scene));
  149. scene.Id = id != 0 ? id : IdGenerater.GenerateId();
  150. scene.Name = name;
  151. scene.SceneType = sceneType;
  152. if (parent != null)
  153. {
  154. scene.Parent = parent;
  155. }
  156. scene.Domain = scene;
  157. return scene;
  158. }
  159. }
  160. }