ComponentFactory.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. using System;
  2. namespace ETHotfix
  3. {
  4. public static class ComponentFactory
  5. {
  6. public static Component CreateWithParent(Type type, Component parent)
  7. {
  8. Component component = Game.ObjectPool.Fetch(type);
  9. component.Parent = parent;
  10. ComponentWithId componentWithId = component as ComponentWithId;
  11. if (componentWithId != null)
  12. {
  13. componentWithId.Id = component.InstanceId;
  14. }
  15. Game.EventSystem.Awake(component);
  16. return component;
  17. }
  18. public static T CreateWithParent<T>(Component parent) where T : Component
  19. {
  20. T component = Game.ObjectPool.Fetch<T>();
  21. component.Parent = parent;
  22. ComponentWithId componentWithId = component as ComponentWithId;
  23. if (componentWithId != null)
  24. {
  25. componentWithId.Id = component.InstanceId;
  26. }
  27. Game.EventSystem.Awake(component);
  28. return component;
  29. }
  30. public static T CreateWithParent<T, A>(Component parent, A a) where T : Component
  31. {
  32. T component = Game.ObjectPool.Fetch<T>();
  33. component.Parent = parent;
  34. ComponentWithId componentWithId = component as ComponentWithId;
  35. if (componentWithId != null)
  36. {
  37. componentWithId.Id = component.InstanceId;
  38. }
  39. Game.EventSystem.Awake(component, a);
  40. return component;
  41. }
  42. public static T CreateWithParent<T, A, B>(Component parent, A a, B b) where T : Component
  43. {
  44. T component = Game.ObjectPool.Fetch<T>();
  45. component.Parent = parent;
  46. ComponentWithId componentWithId = component as ComponentWithId;
  47. if (componentWithId != null)
  48. {
  49. componentWithId.Id = component.InstanceId;
  50. }
  51. Game.EventSystem.Awake(component, a, b);
  52. return component;
  53. }
  54. public static T CreateWithParent<T, A, B, C>(Component parent, A a, B b, C c) where T : Component
  55. {
  56. T component = Game.ObjectPool.Fetch<T>();
  57. component.Parent = parent;
  58. ComponentWithId componentWithId = component as ComponentWithId;
  59. if (componentWithId != null)
  60. {
  61. componentWithId.Id = component.InstanceId;
  62. }
  63. Game.EventSystem.Awake(component, a, b, c);
  64. return component;
  65. }
  66. public static T Create<T>() where T : Component
  67. {
  68. T component = Game.ObjectPool.Fetch<T>();
  69. ComponentWithId componentWithId = component as ComponentWithId;
  70. if (componentWithId != null)
  71. {
  72. componentWithId.Id = component.InstanceId;
  73. }
  74. Game.EventSystem.Awake(component);
  75. return component;
  76. }
  77. public static T Create<T, A>(A a) where T : Component
  78. {
  79. T component = Game.ObjectPool.Fetch<T>();
  80. ComponentWithId componentWithId = component as ComponentWithId;
  81. if (componentWithId != null)
  82. {
  83. componentWithId.Id = component.InstanceId;
  84. }
  85. Game.EventSystem.Awake(component, a);
  86. return component;
  87. }
  88. public static T Create<T, A, B>(A a, B b) where T : Component
  89. {
  90. T component = Game.ObjectPool.Fetch<T>();
  91. ComponentWithId componentWithId = component as ComponentWithId;
  92. if (componentWithId != null)
  93. {
  94. componentWithId.Id = component.InstanceId;
  95. }
  96. Game.EventSystem.Awake(component, a, b);
  97. return component;
  98. }
  99. public static T Create<T, A, B, C>(A a, B b, C c) where T : Component
  100. {
  101. T component = Game.ObjectPool.Fetch<T>();
  102. ComponentWithId componentWithId = component as ComponentWithId;
  103. if (componentWithId != null)
  104. {
  105. componentWithId.Id = component.InstanceId;
  106. }
  107. Game.EventSystem.Awake(component, a, b, c);
  108. return component;
  109. }
  110. public static T CreateWithId<T>(long id) where T : ComponentWithId
  111. {
  112. T component = Game.ObjectPool.Fetch<T>();
  113. component.Id = id;
  114. Game.EventSystem.Awake(component);
  115. return component;
  116. }
  117. public static T CreateWithId<T, A>(long id, A a) where T : ComponentWithId
  118. {
  119. T component = Game.ObjectPool.Fetch<T>();
  120. component.Id = id;
  121. Game.EventSystem.Awake(component, a);
  122. return component;
  123. }
  124. public static T CreateWithId<T, A, B>(long id, A a, B b) where T : ComponentWithId
  125. {
  126. T component = Game.ObjectPool.Fetch<T>();
  127. component.Id = id;
  128. Game.EventSystem.Awake(component, a, b);
  129. return component;
  130. }
  131. public static T CreateWithId<T, A, B, C>(long id, A a, B b, C c) where T : ComponentWithId
  132. {
  133. T component = Game.ObjectPool.Fetch<T>();
  134. component.Id = id;
  135. Game.EventSystem.Awake(component, a, b, c);
  136. return component;
  137. }
  138. }
  139. }