public int AddComponent <T>(T component) where T : IComponent
        {
            int index = ComponentIndex <T> .FindIn(_contextInfo);

            AddComponent(index, component);
            return(index);
        }
        //
        // kamran : Get an index from Entitas
        //
        public int GetIndex <T>(bool useExisted = true) where T : IComponent, new()
        {
            //T component;

            int index = ComponentIndex <T> .FindIn(_contextInfo);

            return(index);
        }
Example #3
0
        /// replace Component with a NEW one
        public T ReplaceNew <T>() where T : IComponent, new()
        {
            int index = ComponentIndex <T> .FindIn(_contextInfo);

            T component = CreateComponent <T>(index);

            ReplaceComponent(index, component);

            return(component);
        }
Example #4
0
        /// replace Component with a NEW one
        public static T ReplaceNewComponent <T>(this Entity entity) where T : IComponent, new()
        {
            int index = ComponentIndex <T> .FindIn(entity.contextInfo);

            T component = entity.CreateComponent <T>(index);

            entity.ReplaceComponent(index, component);

            return(component);
        }
Example #5
0
        public void Remove <T>(bool ignoreNotFound = true) where T : IComponent
        {
            int index = ComponentIndex <T> .FindIn(_contextInfo);

            if (ignoreNotFound && !HasComponent(index))
            {
                return;
            }

            RemoveComponent(index);
        }
Example #6
0
        public static void RemoveComponent <T>(this Entity entity, bool ignoreNotExists = false) where T : IComponent
        {
            int index = ComponentIndex <T> .FindIn(entity.contextInfo);

            if (ignoreNotExists && !entity.HasComponent(index))
            {
                return;
            }

            entity.RemoveComponent(index);
        }
Example #7
0
        /// add a new Component, return the old one if exists
        public T Add <T>(bool useExisted = true) where T : IComponent, new()
        {
            T component;

            int index = ComponentIndex <T> .FindIn(_contextInfo);

            if (useExisted && HasComponent(index))
            {
                component = (T)GetComponent(index);
                FireModifiedEvent(index, component);
            }
            else
            {
                component = CreateComponent <T>(index);
                AddComponent(index, component);
            }

            return(component);
        }
Example #8
0
        /// add a new Component, return the old one if exists
        public static T AddComponent <T>(this Entity entity, bool keepOldIfExists = false) where T : IComponent, new()
        {
            int index = ComponentIndex <T> .FindIn(entity.contextInfo);

            T component;

            if (keepOldIfExists && entity.HasComponent(index))
            {
                component = (T)entity.GetComponent(index);
                entity.MarkUpdated(index);
            }
            else
            {
                component = entity.CreateComponent <T>(index);
                entity.AddComponent(index, component);
            }

            return(component);
        }
Example #9
0
        /// Get Component for modification, mark automatically
        public T Modify <T>() where T : IComponent
        {
            int index = ComponentIndex <T> .FindIn(_contextInfo);

            return((T)ModifyComponent(index));
        }
Example #10
0
        public T Get <T>() where T : IComponent
        {
            int index = ComponentIndex <T> .FindIn(_contextInfo);

            return((T)GetComponent(index));
        }
Example #11
0
        public bool Has <T>() where T : IComponent
        {
            int index = ComponentIndex <T> .FindIn(_contextInfo);

            return(HasComponent(index));
        }
Example #12
0
        /// Mark component modified, trigger GroupEvent and ReactiveSystem
        public void SetModified <T>() where T : IComponent, new()
        {
            int index = ComponentIndex <T> .FindIn(_contextInfo);

            SetModified(index);
        }
Example #13
0
        /// Mark component-updated, trigger GroupEvent and ReactiveSystem
        public static void MarkUpdated <T>(this Entity entity) where T : IComponent, new()
        {
            int index = ComponentIndex <T> .FindIn(entity.contextInfo);

            entity.MarkUpdated(index);
        }
Example #14
0
        /// shorter version of GetComponent<T>
        public static T Get <T>(this Entity entity) where T : IComponent
        {
            int index = ComponentIndex <T> .FindIn(entity.contextInfo);

            return((T)entity.GetComponent(index));
        }
Example #15
0
        public static bool HasComponent <T>(this Entity entity) where T : IComponent
        {
            int index = ComponentIndex <T> .FindIn(entity.contextInfo);

            return(entity.HasComponent(index));
        }