diff --git a/Svelto.ECS/Dispatcher/DispatchOnChange.cs b/Svelto.ECS/Dispatcher/DispatchOnChange.cs index bfcf521..b6ddb5f 100644 --- a/Svelto.ECS/Dispatcher/DispatchOnChange.cs +++ b/Svelto.ECS/Dispatcher/DispatchOnChange.cs @@ -6,6 +6,9 @@ namespace Svelto.ECS { public DispatchOnChange(int senderID) : base(senderID) { } + + public DispatchOnChange(EGID senderID) : base(senderID) + { } public DispatchOnChange() {} diff --git a/Svelto.ECS/Dispatcher/DispatchOnSet.cs b/Svelto.ECS/Dispatcher/DispatchOnSet.cs index b8c5057..fddaba8 100644 --- a/Svelto.ECS/Dispatcher/DispatchOnSet.cs +++ b/Svelto.ECS/Dispatcher/DispatchOnSet.cs @@ -4,16 +4,20 @@ namespace Svelto.ECS { public class DispatchOnSet where T:struct { - public DispatchOnSet(int senderID) + public DispatchOnSet(int senderID):this() + { + _senderID = new EGID(senderID, ExclusiveGroup.StandardEntitiesGroup); + } + + public DispatchOnSet(EGID senderID):this() { _senderID = senderID; - _subscribers = new WeakEvent(); } public DispatchOnSet() { - _senderID = -1; - _subscribers = new WeakEvent(); + _senderID = new EGID(); + _subscribers = new WeakEvent(); } public T value @@ -30,20 +34,20 @@ namespace Svelto.ECS return _value; } } - - public void NotifyOnValueSet(System.Action action) + + public void NotifyOnValueSet(System.Action action) { _subscribers += action; } - public void StopNotify(System.Action action) + public void StopNotify(System.Action action) { _subscribers -= action; } protected T _value; - readonly int _senderID; + readonly EGID _senderID; - WeakEvent _subscribers; + WeakEvent _subscribers; } } diff --git a/Svelto.ECS/EGID.cs b/Svelto.ECS/EGID.cs index 7656ffe..b18c7d2 100644 --- a/Svelto.ECS/EGID.cs +++ b/Svelto.ECS/EGID.cs @@ -33,7 +33,12 @@ namespace Svelto.ECS static long MAKE_GLOBAL_ID(int entityId, int groupId) { - return (long)groupId << 32 | (((long)(uint)entityId) & 0xFFFFFFFF); + return (long)groupId << 32 | ((long)(uint)entityId & 0xFFFFFFFF); + } + + public static implicit operator int(EGID id) + { + return id.entityID; } } } \ No newline at end of file diff --git a/Svelto.ECS/ExclusiveGroups.cs b/Svelto.ECS/ExclusiveGroups.cs index d9c6980..2984efd 100644 --- a/Svelto.ECS/ExclusiveGroups.cs +++ b/Svelto.ECS/ExclusiveGroups.cs @@ -1,5 +1,16 @@ namespace Svelto.ECS { + /// + /// Exclusive Groups guarantee that the GroupID is unique. + /// + /// The best way to use it is like: + /// + /// public static class MyExclusiveGroups //(can be as many as you want) + /// { + /// public static MyExclusiveGroup1 = new ExclusiveGroup(); + /// } + /// + public class ExclusiveGroup { internal const int StandardEntitiesGroup = int.MaxValue; @@ -10,6 +21,9 @@ _globalId += 1; } + /// + /// Use this constructor to reserve N groups + /// public ExclusiveGroup(int range) { _id = _globalId; diff --git a/Svelto.ECS/Extensions/Unity/UnityEntityDescriptorHolder.cs b/Svelto.ECS/Extensions/Unity/UnityEntityDescriptorHolder.cs new file mode 100644 index 0000000..d6156b6 --- /dev/null +++ b/Svelto.ECS/Extensions/Unity/UnityEntityDescriptorHolder.cs @@ -0,0 +1,14 @@ +#if UNITY_5 || UNITY_5_3_OR_NEWER +namespace Svelto.ECS +{ + public class UnityEntityDescriptorHolder: + UnityEngine.MonoBehaviour , IEntityDescriptorHolder + where T: IEntityDescriptor, new() + { + public IEntityBuilder[] GetEntitiesToBuild() + { + return EntityDescriptorTemplate.descriptor.entitiesToBuild; + } + } +} +#endif \ No newline at end of file