ComponentFactory.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 = (Component)Game.ObjectPool.Fetch(type);
  9. component.Parent = parent;
  10. Game.EventSystem.Awake(component);
  11. return component;
  12. }
  13. public static T CreateWithParent<T>(Component parent) where T : Component
  14. {
  15. T component = Game.ObjectPool.Fetch<T>();
  16. component.Parent = parent;
  17. Game.EventSystem.Awake(component);
  18. return component;
  19. }
  20. public static T CreateWithParent<T, A>(Component parent, A a) where T : Component
  21. {
  22. T component = Game.ObjectPool.Fetch<T>();
  23. component.Parent = parent;
  24. Game.EventSystem.Awake(component, a);
  25. return component;
  26. }
  27. public static T CreateWithParent<T, A, B>(Component parent, A a, B b) where T : Component
  28. {
  29. T component = Game.ObjectPool.Fetch<T>();
  30. component.Parent = parent;
  31. Game.EventSystem.Awake(component, a, b);
  32. return component;
  33. }
  34. public static T CreateWithParent<T, A, B, C>(Component parent, A a, B b, C c) where T : Component
  35. {
  36. T component = Game.ObjectPool.Fetch<T>();
  37. component.Parent = parent;
  38. Game.EventSystem.Awake(component, a, b, c);
  39. return component;
  40. }
  41. public static T Create<T>() where T : Component
  42. {
  43. T component = Game.ObjectPool.Fetch<T>();
  44. Game.EventSystem.Awake(component);
  45. return component;
  46. }
  47. public static T Create<T, A>(A a) where T : Component
  48. {
  49. T component = Game.ObjectPool.Fetch<T>();
  50. Game.EventSystem.Awake(component, a);
  51. return component;
  52. }
  53. public static T Create<T, A, B>(A a, B b) where T : Component
  54. {
  55. T component = Game.ObjectPool.Fetch<T>();
  56. Game.EventSystem.Awake(component, a, b);
  57. return component;
  58. }
  59. public static T Create<T, A, B, C>(A a, B b, C c) where T : Component
  60. {
  61. T component = Game.ObjectPool.Fetch<T>();
  62. Game.EventSystem.Awake(component, a, b, c);
  63. return component;
  64. }
  65. public static T CreateWithId<T>(long id) where T : Component
  66. {
  67. T component = Game.ObjectPool.Fetch<T>();
  68. component.Id = id;
  69. Game.EventSystem.Awake(component);
  70. return component;
  71. }
  72. public static T CreateWithId<T, A>(long id, A a) where T : Component
  73. {
  74. T component = Game.ObjectPool.Fetch<T>();
  75. component.Id = id;
  76. Game.EventSystem.Awake(component, a);
  77. return component;
  78. }
  79. public static T CreateWithId<T, A, B>(long id, A a, B b) where T : Component
  80. {
  81. T component = Game.ObjectPool.Fetch<T>();
  82. component.Id = id;
  83. Game.EventSystem.Awake(component, a, b);
  84. return component;
  85. }
  86. public static T CreateWithId<T, A, B, C>(long id, A a, B b, C c) where T : Component
  87. {
  88. T component = Game.ObjectPool.Fetch<T>();
  89. component.Id = id;
  90. Game.EventSystem.Awake(component, a, b, c);
  91. return component;
  92. }
  93. }
  94. }