EntityCreateComponet.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System;
  2. using ETModel;
  3. namespace ETHotfix
  4. {
  5. public partial class Entity
  6. {
  7. private Entity CreateWithComponentParent(Type type)
  8. {
  9. Entity component;
  10. if (type.IsDefined(typeof (NoObjectPool), false))
  11. {
  12. component = (Entity)Activator.CreateInstance(type);
  13. }
  14. else
  15. {
  16. component = Game.ObjectPool.Fetch(type);
  17. }
  18. this.Domain = parent.Domain;
  19. component.Id = parent.Id;
  20. component.ComponentParent = parent;
  21. Game.EventSystem.Awake(component);
  22. return component;
  23. }
  24. private T CreateWithComponentParent<T>(bool isFromPool = true) where T : Entity
  25. {
  26. Type type = typeof (T);
  27. Entity component;
  28. if (!isFromPool)
  29. {
  30. component = (Entity)Activator.CreateInstance(type);
  31. }
  32. else
  33. {
  34. component = Game.ObjectPool.Fetch(type);
  35. }
  36. component.Domain = this.Domain;
  37. component.Id = this.Id;
  38. component.ComponentParent = this;
  39. Game.EventSystem.Awake(component);
  40. return (T)component;
  41. }
  42. private T CreateWithComponentParent<T, A>(A a, bool isFromPool = true) where T : Entity
  43. {
  44. Type type = typeof (T);
  45. Entity component;
  46. if (!isFromPool)
  47. {
  48. component = (Entity)Activator.CreateInstance(type);
  49. }
  50. else
  51. {
  52. component = Game.ObjectPool.Fetch(type);
  53. }
  54. component.Domain = this.Domain;
  55. component.Id = this.Id;
  56. component.ComponentParent = this;
  57. Game.EventSystem.Awake(component, a);
  58. return (T)component;
  59. }
  60. private T CreateWithComponentParent<T, A, B>(A a, B b, bool isFromPool = true) where T : Entity
  61. {
  62. Type type = typeof (T);
  63. Entity component;
  64. if (!isFromPool)
  65. {
  66. component = (Entity)Activator.CreateInstance(type);
  67. }
  68. else
  69. {
  70. component = Game.ObjectPool.Fetch(type);
  71. }
  72. component.Domain = this.Domain;
  73. component.Id = this.Id;
  74. component.ComponentParent = this;
  75. Game.EventSystem.Awake(component, a, b);
  76. return (T)component;
  77. }
  78. private T CreateWithComponentParent<T, A, B, C>(A a, B b, C c, bool isFromPool = true) where T : Entity
  79. {
  80. Type type = typeof (T);
  81. Entity component;
  82. if (!isFromPool)
  83. {
  84. component = (Entity)Activator.CreateInstance(type);
  85. }
  86. else
  87. {
  88. component = Game.ObjectPool.Fetch(type);
  89. }
  90. component.Domain = this.Domain;
  91. component.Id = this.Id;
  92. component.ComponentParent = this;
  93. Game.EventSystem.Awake(component, a, b, c);
  94. return (T)component;
  95. }
  96. }
  97. }