using System.Collections.Generic; using System.Runtime.CompilerServices; using Unity.Entities; using UnityEngine; using UnityEngine.Profiling; [DisableAutoCreation] public abstract class BaseComponentSystem : ComponentSystem { protected BaseComponentSystem(GameWorld world) { m_world = world; } readonly protected GameWorld m_world; } [DisableAutoCreation] public abstract class BaseComponentSystem : BaseComponentSystem where T1 : MonoBehaviour { ComponentGroup Group; protected ComponentType[] ExtraComponentRequirements; string name; public BaseComponentSystem(GameWorld world) : base(world) {} protected override void OnCreateManager(int capacity) { base.OnCreateManager(capacity); name = GetType().Name; var list = new List(6); if(ExtraComponentRequirements != null) list.AddRange(ExtraComponentRequirements); list.AddRange(new ComponentType[] { typeof(T1) } ); Group = GetComponentGroup(list.ToArray()); } protected override void OnUpdate() { Profiler.BeginSample(name); var entityArray = Group.GetEntityArray(); var dataArray = Group.GetComponentArray(); for (var i = 0; i < entityArray.Length; i++) { Update(entityArray[i], dataArray[i]); } Profiler.EndSample(); } protected abstract void Update(Entity entity,T1 data); } [DisableAutoCreation] public abstract class BaseComponentSystem : BaseComponentSystem where T1 : MonoBehaviour where T2 : MonoBehaviour { ComponentGroup Group; protected ComponentType[] ExtraComponentRequirements; string name; public BaseComponentSystem(GameWorld world) : base(world) {} protected override void OnCreateManager(int capacity) { base.OnCreateManager(capacity); name = GetType().Name; var list = new List(6); if(ExtraComponentRequirements != null) list.AddRange(ExtraComponentRequirements); list.AddRange(new ComponentType[] { typeof(T1), typeof(T2) } ); Group = GetComponentGroup(list.ToArray()); } protected override void OnUpdate() { Profiler.BeginSample(name); var entityArray = Group.GetEntityArray(); var dataArray1 = Group.GetComponentArray(); var dataArray2 = Group.GetComponentArray(); for (var i = 0; i < entityArray.Length; i++) { Update(entityArray[i], dataArray1[i], dataArray2[i]); } Profiler.EndSample(); } protected abstract void Update(Entity entity,T1 data1,T2 data2); } [DisableAutoCreation] public abstract class BaseComponentSystem : BaseComponentSystem where T1 : MonoBehaviour where T2 : MonoBehaviour where T3 : MonoBehaviour { ComponentGroup Group; protected ComponentType[] ExtraComponentRequirements; string name; public BaseComponentSystem(GameWorld world) : base(world) {} protected override void OnCreateManager(int capacity) { base.OnCreateManager(capacity); name = GetType().Name; var list = new List(6); if(ExtraComponentRequirements != null) list.AddRange(ExtraComponentRequirements); list.AddRange(new ComponentType[] { typeof(T1), typeof(T2), typeof(T3) } ); Group = GetComponentGroup(list.ToArray()); } protected override void OnUpdate() { Profiler.BeginSample(name); var entityArray = Group.GetEntityArray(); var dataArray1 = Group.GetComponentArray(); var dataArray2 = Group.GetComponentArray(); var dataArray3 = Group.GetComponentArray(); for (var i = 0; i < entityArray.Length; i++) { Update(entityArray[i], dataArray1[i], dataArray2[i], dataArray3[i]); } Profiler.EndSample(); } protected abstract void Update(Entity entity,T1 data1,T2 data2,T3 data3); } [DisableAutoCreation] public abstract class BaseComponentDataSystem : BaseComponentSystem where T1 : struct,IComponentData { ComponentGroup Group; protected ComponentType[] ExtraComponentRequirements; string name; public BaseComponentDataSystem(GameWorld world) : base(world) {} protected override void OnCreateManager(int capacity) { base.OnCreateManager(capacity); name = GetType().Name; var list = new List(6); if(ExtraComponentRequirements != null) list.AddRange(ExtraComponentRequirements); list.AddRange(new ComponentType[] { typeof(T1) } ); Group = GetComponentGroup(list.ToArray()); } protected override void OnUpdate() { Profiler.BeginSample(name); var entityArray = Group.GetEntityArray(); var dataArray = Group.GetComponentDataArray(); for (var i = 0; i < entityArray.Length; i++) { Update(entityArray[i], dataArray[i]); } Profiler.EndSample(); } protected abstract void Update(Entity entity,T1 data); } [DisableAutoCreation] public abstract class BaseComponentDataSystem : BaseComponentSystem where T1 : struct,IComponentData where T2 : struct,IComponentData { ComponentGroup Group; protected ComponentType[] ExtraComponentRequirements; private string name; public BaseComponentDataSystem(GameWorld world) : base(world) {} protected override void OnCreateManager(int capacity) { name = GetType().Name; base.OnCreateManager(capacity); var list = new List(6); if(ExtraComponentRequirements != null) list.AddRange(ExtraComponentRequirements); list.AddRange(new ComponentType[] { typeof(T1), typeof(T2) } ); Group = GetComponentGroup(list.ToArray()); } protected override void OnUpdate() { Profiler.BeginSample(name); var entityArray = Group.GetEntityArray(); var dataArray1 = Group.GetComponentDataArray(); var dataArray2 = Group.GetComponentDataArray(); for (var i = 0; i < entityArray.Length; i++) { Update(entityArray[i], dataArray1[i], dataArray2[i]); } Profiler.EndSample(); } protected abstract void Update(Entity entity,T1 data1,T2 data2); } [DisableAutoCreation] public abstract class BaseComponentDataSystem : BaseComponentSystem where T1 : struct,IComponentData where T2 : struct,IComponentData where T3 : struct,IComponentData { ComponentGroup Group; protected ComponentType[] ExtraComponentRequirements; string name; public BaseComponentDataSystem(GameWorld world) : base(world) {} protected override void OnCreateManager(int capacity) { base.OnCreateManager(capacity); name = GetType().Name; var list = new List(6); if(ExtraComponentRequirements != null) list.AddRange(ExtraComponentRequirements); list.AddRange(new ComponentType[] { typeof(T1), typeof(T2), typeof(T3) } ); Group = GetComponentGroup(list.ToArray()); } protected override void OnUpdate() { Profiler.BeginSample(name); var entityArray = Group.GetEntityArray(); var dataArray1 = Group.GetComponentDataArray(); var dataArray2 = Group.GetComponentDataArray(); var dataArray3 = Group.GetComponentDataArray(); for (var i = 0; i < entityArray.Length; i++) { Update(entityArray[i], dataArray1[i], dataArray2[i], dataArray3[i]); } Profiler.EndSample(); } protected abstract void Update(Entity entity,T1 data1,T2 data2,T3 data3); } [DisableAutoCreation] public abstract class BaseComponentDataSystem : BaseComponentSystem where T1 : struct,IComponentData where T2 : struct,IComponentData where T3 : struct,IComponentData where T4 : struct,IComponentData { ComponentGroup Group; protected ComponentType[] ExtraComponentRequirements; string name; public BaseComponentDataSystem(GameWorld world) : base(world) {} protected override void OnCreateManager(int capacity) { base.OnCreateManager(capacity); name = GetType().Name; var list = new List(6); if(ExtraComponentRequirements != null) list.AddRange(ExtraComponentRequirements); list.AddRange(new ComponentType[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4) } ); Group = GetComponentGroup(list.ToArray()); } protected override void OnUpdate() { Profiler.BeginSample(name); var entityArray = Group.GetEntityArray(); var dataArray1 = Group.GetComponentDataArray(); var dataArray2 = Group.GetComponentDataArray(); var dataArray3 = Group.GetComponentDataArray(); var dataArray4 = Group.GetComponentDataArray(); for (var i = 0; i < entityArray.Length; i++) { Update(entityArray[i], dataArray1[i], dataArray2[i], dataArray3[i], dataArray4[i]); } Profiler.EndSample(); } protected abstract void Update(Entity entity,T1 data1,T2 data2,T3 data3,T4 data4); } [DisableAutoCreation] public abstract class BaseComponentDataSystem : BaseComponentSystem where T1 : struct,IComponentData where T2 : struct,IComponentData where T3 : struct,IComponentData where T4 : struct,IComponentData where T5 : struct,IComponentData { ComponentGroup Group; protected ComponentType[] ExtraComponentRequirements; string name; public BaseComponentDataSystem(GameWorld world) : base(world) {} protected override void OnCreateManager(int capacity) { base.OnCreateManager(capacity); name = GetType().Name; var list = new List(6); if(ExtraComponentRequirements != null) list.AddRange(ExtraComponentRequirements); list.AddRange(new ComponentType[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5) } ); Group = GetComponentGroup(list.ToArray()); } protected override void OnUpdate() { Profiler.BeginSample(name); var entityArray = Group.GetEntityArray(); var dataArray1 = Group.GetComponentDataArray(); var dataArray2 = Group.GetComponentDataArray(); var dataArray3 = Group.GetComponentDataArray(); var dataArray4 = Group.GetComponentDataArray(); var dataArray5 = Group.GetComponentDataArray(); for (var i = 0; i < entityArray.Length; i++) { Update(entityArray[i], dataArray1[i], dataArray2[i], dataArray3[i], dataArray4[i], dataArray5[i]); } Profiler.EndSample(); } protected abstract void Update(Entity entity,T1 data1,T2 data2,T3 data3,T4 data4, T5 data5); } [DisableAutoCreation] [AlwaysUpdateSystem] public abstract class InitializeComponentSystem : BaseComponentSystem where T : MonoBehaviour { struct SystemState : IComponentData {} ComponentGroup IncomingGroup; string name; public InitializeComponentSystem(GameWorld world) : base(world) {} protected override void OnCreateManager(int capacity) { base.OnCreateManager(capacity); name = GetType().Name; IncomingGroup = GetComponentGroup(typeof(T),ComponentType.Subtractive()); } protected override void OnUpdate() { Profiler.BeginSample(name); var incomingEntityArray = IncomingGroup.GetEntityArray(); if (incomingEntityArray.Length > 0) { var incomingComponentArray = IncomingGroup.GetComponentArray(); for (var i = 0; i < incomingComponentArray.Length; i++) { var entity = incomingEntityArray[i]; PostUpdateCommands.AddComponent(entity,new SystemState()); Initialize(entity, incomingComponentArray[i]); } } Profiler.EndSample(); } protected abstract void Initialize(Entity entity, T component); } [DisableAutoCreation] [AlwaysUpdateSystem] public abstract class InitializeComponentDataSystem : BaseComponentSystem where T : struct, IComponentData { struct SystemState : IComponentData{} ComponentGroup IncomingGroup; string name; public InitializeComponentDataSystem(GameWorld world) : base(world) {} protected override void OnCreateManager(int capacity) { base.OnCreateManager(capacity); name = GetType().Name; IncomingGroup = GetComponentGroup(typeof(T),ComponentType.Subtractive()); } protected override void OnUpdate() { Profiler.BeginSample(name); var incomingEntityArray = IncomingGroup.GetEntityArray(); if (incomingEntityArray.Length > 0) { var incomingComponentDataArray = IncomingGroup.GetComponentDataArray(); for (var i = 0; i < incomingComponentDataArray.Length; i++) { var entity = incomingEntityArray[i]; PostUpdateCommands.AddComponent(entity,new SystemState()); Initialize(entity, incomingComponentDataArray[i]); } } Profiler.EndSample(); } protected abstract void Initialize(Entity entity, T component); } [DisableAutoCreation] [AlwaysUpdateSystem] public abstract class DeinitializeComponentSystem : BaseComponentSystem where T : MonoBehaviour { ComponentGroup OutgoingGroup; string name; public DeinitializeComponentSystem(GameWorld world) : base(world) {} protected override void OnCreateManager(int capacity) { base.OnCreateManager(capacity); name = GetType().Name; OutgoingGroup = GetComponentGroup(typeof(T), typeof(DespawningEntity)); } protected override void OnUpdate() { Profiler.BeginSample(name); var outgoingComponentArray = OutgoingGroup.GetComponentArray(); var outgoingEntityArray = OutgoingGroup.GetEntityArray(); for (var i = 0; i < outgoingComponentArray.Length; i++) { Deinitialize(outgoingEntityArray[i], outgoingComponentArray[i]); } Profiler.EndSample(); } protected abstract void Deinitialize(Entity entity, T component); } [DisableAutoCreation] [AlwaysUpdateSystem] public abstract class DeinitializeComponentDataSystem : BaseComponentSystem where T : struct, IComponentData { ComponentGroup OutgoingGroup; string name; public DeinitializeComponentDataSystem(GameWorld world) : base(world) {} protected override void OnCreateManager(int capacity) { base.OnCreateManager(capacity); name = GetType().Name; OutgoingGroup = GetComponentGroup(typeof(T), typeof(DespawningEntity)); } protected override void OnUpdate() { Profiler.BeginSample(name); var outgoingComponentArray = OutgoingGroup.GetComponentDataArray(); var outgoingEntityArray = OutgoingGroup.GetEntityArray(); for (var i = 0; i < outgoingComponentArray.Length; i++) { Deinitialize(outgoingEntityArray[i], outgoingComponentArray[i]); } Profiler.EndSample(); } protected abstract void Deinitialize(Entity entity, T component); } [DisableAutoCreation] [AlwaysUpdateSystem] public abstract class InitializeComponentGroupSystem : BaseComponentSystem where T : MonoBehaviour where S : struct, IComponentData { ComponentGroup IncomingGroup; string name; public InitializeComponentGroupSystem(GameWorld world) : base(world) {} protected override void OnCreateManager(int capacity) { base.OnCreateManager(capacity); name = GetType().Name; IncomingGroup = GetComponentGroup(typeof(T),ComponentType.Subtractive()); } protected override void OnUpdate() { Profiler.BeginSample(name); var incomingEntityArray = IncomingGroup.GetEntityArray(); if (incomingEntityArray.Length > 0) { for (var i = 0; i < incomingEntityArray.Length; i++) { var entity = incomingEntityArray[i]; PostUpdateCommands.AddComponent(entity,new S()); } Initialize(ref IncomingGroup); } Profiler.EndSample(); } protected abstract void Initialize(ref ComponentGroup group); } [DisableAutoCreation] [AlwaysUpdateSystem] public abstract class DeinitializeComponentGroupSystem : BaseComponentSystem where T : MonoBehaviour { ComponentGroup OutgoingGroup; string name; public DeinitializeComponentGroupSystem(GameWorld world) : base(world) {} protected override void OnCreateManager(int capacity) { base.OnCreateManager(capacity); name = GetType().Name; OutgoingGroup = GetComponentGroup(typeof(T), typeof(DespawningEntity)); } protected override void OnUpdate() { Profiler.BeginSample(name); if (OutgoingGroup.CalculateLength() > 0) Deinitialize(ref OutgoingGroup); Profiler.EndSample(); } protected abstract void Deinitialize(ref ComponentGroup group); }