Mirror of Svelto.ECS because we're a fan of it
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MultiNodesEngine.cs 2.0KB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using Svelto.DataStructures;
  2. using Svelto.ECS.Internal;
  3. namespace Svelto.ECS.Internal
  4. {
  5. public abstract class MultiNodesEngine<T>:INodeEngine where T:NodeWithID
  6. {
  7. protected abstract void Add(T node);
  8. protected abstract void Remove(T node);
  9. public virtual void Add(NodeWithID node)
  10. {
  11. Add((T) node);
  12. }
  13. public virtual void Remove(NodeWithID node)
  14. {
  15. Remove((T) node);
  16. }
  17. }
  18. }
  19. namespace Svelto.ECS
  20. {
  21. public abstract class MultiNodesEngine<T, U> : MultiNodesEngine<T>
  22. where T:NodeWithID where U:NodeWithID
  23. {
  24. protected abstract void Add(U node);
  25. protected abstract void Remove(U node);
  26. public override void Add(NodeWithID node)
  27. {
  28. var castedNode = node as U;
  29. if (castedNode != null)
  30. {
  31. Add(castedNode);
  32. }
  33. else
  34. {
  35. base.Add(node);
  36. }
  37. }
  38. public override void Remove(NodeWithID node)
  39. {
  40. if (node is U)
  41. {
  42. Remove((U) node);
  43. }
  44. else
  45. {
  46. base.Remove(node);
  47. }
  48. }
  49. }
  50. public abstract class MultiNodesEngine<T, U, V> : MultiNodesEngine<T, U>
  51. where T: NodeWithID where U : NodeWithID where V:NodeWithID
  52. {
  53. protected abstract void Add(V node);
  54. protected abstract void Remove(V node);
  55. public override void Add(NodeWithID node)
  56. {
  57. var castedNode = node as V;
  58. if (castedNode != null)
  59. {
  60. Add(castedNode);
  61. }
  62. else
  63. base.Add(node);
  64. }
  65. public override void Remove(NodeWithID node)
  66. {
  67. var castedNode = node as V;
  68. if (castedNode != null)
  69. {
  70. Remove(castedNode);
  71. }
  72. else
  73. base.Remove(node);
  74. }
  75. }
  76. }