EntityCreateComponet.cs 2.3 KB

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