EntityCreateComponet.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System;
  2. namespace ETModel
  3. {
  4. public partial class Entity
  5. {
  6. public static Entity Create(Type type, bool isFromPool)
  7. {
  8. Entity component;
  9. if (isFromPool)
  10. {
  11. component = (Entity)ObjectPool.Instance.Fetch(type);
  12. }
  13. else
  14. {
  15. component = (Entity)Activator.CreateInstance(type);
  16. }
  17. component.IsFromPool = isFromPool;
  18. component.IsCreate = true;
  19. component.Id = 0;
  20. return component;
  21. }
  22. private Entity CreateWithComponentParent(Type type, bool isFromPool = true)
  23. {
  24. Entity component = Create(type, isFromPool);
  25. component.Id = parent.Id;
  26. component.ComponentParent = parent;
  27. EventSystem.Instance.Awake(component);
  28. return component;
  29. }
  30. private T CreateWithComponentParent<T>(bool isFromPool = true) where T : Entity
  31. {
  32. Type type = typeof (T);
  33. Entity component = Create(type, isFromPool);
  34. component.Id = this.Id;
  35. component.ComponentParent = this;
  36. EventSystem.Instance.Awake(component);
  37. return (T)component;
  38. }
  39. private T CreateWithComponentParent<T, A>(A a, bool isFromPool = true) where T : Entity
  40. {
  41. Type type = typeof (T);
  42. Entity component = Create(type, isFromPool);
  43. component.Id = this.Id;
  44. component.ComponentParent = this;
  45. EventSystem.Instance.Awake(component, a);
  46. return (T)component;
  47. }
  48. private T CreateWithComponentParent<T, A, B>(A a, B b, bool isFromPool = true) where T : Entity
  49. {
  50. Type type = typeof (T);
  51. Entity component = Create(type, isFromPool);
  52. component.Id = this.Id;
  53. component.ComponentParent = this;
  54. EventSystem.Instance.Awake(component, a, b);
  55. return (T)component;
  56. }
  57. private T CreateWithComponentParent<T, A, B, C>(A a, B b, C c, bool isFromPool = true) where T : Entity
  58. {
  59. Type type = typeof (T);
  60. Entity component = Create(type, isFromPool);
  61. component.Id = this.Id;
  62. component.ComponentParent = this;
  63. EventSystem.Instance.Awake(component, a, b, c);
  64. return (T)component;
  65. }
  66. }
  67. }