Exemplo n.º 1
0
        public static ent Create(GameObject prefab, BlueprintEntity bpAsset, bool pooled = false)
        {
            int  id;
            byte age = 0;

            if (ent.entityStackLength > 0)
            {
                var  pop    = ent.entityStack.Dequeue();
                byte ageOld = pop.age;
                id = pop.id;
                unchecked
                {
                    age = (byte)(ageOld + 1);
                }

                ent.entityStackLength--;
            }
            else
            {
                id = ent.lastID++;
            }

            var entity = new ent(id, age);

            Initialize(id, age, pooled);
            transforms[id] = pooled ? HelperFramework.SpawnInternal(Pool.Entities, prefab) : HelperFramework.SpawnInternal(prefab);
            bpAsset.Execute(entity);
            return(entity);
        }
Exemplo n.º 2
0
        //===============================//
        // Blueprints
        //===============================//

                #if ODIN_INSPECTOR
        public static ent Create(BlueprintEntity bpAsset)
        {
            int  id;
            byte age = 0;

            if (ent.entityStackLength > 0)
            {
                var  pop    = ent.entityStack.Dequeue();
                byte ageOld = pop.age;
                id = pop.id;
                unchecked
                {
                    age = (byte)(ageOld + 1);
                }

                ent.entityStackLength--;
            }
            else
            {
                id = ent.lastID++;
            }

            var entity = new ent(id, age);

            Initialize(id, age);
            bpAsset.Execute(entity);
            return(entity);
        }
Exemplo n.º 3
0
        public static ent Create(ModelComposer model)
        {
            int  id;
            byte age = 0;

            if (ent.entityStackLength > 0)
            {
                var  pop    = ent.entityStack.Dequeue();
                byte ageOld = pop.age;
                id = pop.id;
                unchecked
                {
                    age = (byte)(ageOld + 1);
                }

                ent.entityStackLength--;
            }
            else
            {
                id = ent.lastID++;
            }

            var entity = new ent(id, age);

            Initialize(id, age);

            model(entity, null);
            Delayed.Set(entity, 0, Delayed.Action.Activate);

            return(entity);
        }
Exemplo n.º 4
0
        public static ent CreateFor(GameObject prefab, ModelComposer model, bool pooled = false)
        {
            int  id;
            byte age = 0;

            if (ent.entityStackLength > 0)
            {
                var  pop    = ent.entityStack.Dequeue();
                byte ageOld = pop.age;
                id = pop.id;
                unchecked
                {
                    age = (byte)(ageOld + 1);
                }

                ent.entityStackLength--;
            }
            else
            {
                id = ent.lastID++;
            }

            var entity = new ent(id, age);

            Initialize(id, age, pooled);
            transforms[id] = prefab.transform;
            model(entity, null);
            Delayed.Set(entity, 0, Delayed.Action.Activate);
            return(entity);
        }
Exemplo n.º 5
0
        public static ent Create(string prefabID, ModelComposer model, Vector3 position, bool pooled = false)
        {
            int  id;
            byte age = 0;

            if (ent.entityStackLength > 0)
            {
                var  pop    = ent.entityStack.Dequeue();
                byte ageOld = pop.age;
                id = pop.id;
                unchecked
                {
                    age = (byte)(ageOld + 1);
                }

                ent.entityStackLength--;
            }
            else
            {
                id = ent.lastID++;
            }

            var entity = new ent(id, age);

            Initialize(id, age, pooled);
            transforms[id] = pooled ? HelperFramework.SpawnInternal(Pool.Entities, prefabID, position) : HelperFramework.SpawnInternal(prefabID, position);
            model(entity, null);
            Delayed.Set(entity, 0, Delayed.Action.Activate);

            return(entity);
        }
Exemplo n.º 6
0
        internal void Launch(ModelComposer model)
        {
            int  id;
            byte age = 0;

            if (ent.entityStackLength > 0)
            {
                var  pop    = ent.entityStack.Dequeue();
                byte ageOld = pop.age;
                id = pop.id;
                unchecked
                {
                    age = (byte)(ageOld + 1);
                }

                ent.entityStackLength--;
            }
            else
            {
                id = ent.lastID++;
            }

                        #if UNITY_EDITOR
            _entity = id;
                        #endif

            entity = new ent(id, age);
            Entity.Initialize(id, age, isPooled);
            Entity.transforms[id] = transform;
            Setup();

            model(entity, this);
            Entity.Delayed.Set(entity, 0, Entity.Delayed.Action.Activate);
        }
Exemplo n.º 7
0
        internal void Launch()
        {
            int  id;
            byte age = 0;

            if (ent.entityStackLength > 0)
            {
                var  pop    = ent.entityStack.Dequeue();
                byte ageOld = pop.age;
                id = pop.id;
                unchecked
                {
                    age = (byte)(ageOld + 1);
                }

                ent.entityStackLength--;
            }
            else
            {
                id = ent.lastID++;
            }

                        #if UNITY_EDITOR
            _entity = id;
                        #endif

            entity = new ent(id, age);
            Entity.Initialize(id, age, isPooled);
            Entity.transforms[id] = transform;
            Setup();

            if (buildFrom != null)
            {
                buildFrom.ExecuteOnStart(entity, this);
            }
            else if (isActiveAndEnabled)
            {
                Entity.Delayed.Set(entity, 0, Entity.Delayed.Action.Activate);
            }
        }
Exemplo n.º 8
0
        public static void ValueChange <TSource, TProp>(this TSource source, Func <TSource, TProp> propertySelector, Action <TProp> callback, ent e)
        {
            var w = new Wrap <TSource, TProp>();

            w.source   = source;
            w.prop     = propertySelector;
            w.callback = callback;

                        #if UNITY_EDITOR
            if (Comparers.storage.TryGetValue(typeof(TProp).GetHashCode(), out object comparer))
            {
                w.comparer = comparer as IEqualityComparer <TProp>;
            }
            else
            {
                Debug.LogError($"Comparer for {typeof(TProp)} not found.");
            }
                        #else
            w.comparer = Comparers.storage[typeof(TProp).GetHashCode()]  as IEqualityComparer <TProp>;
                        #endif

            ref var cObserver = ref e.AddGet <ComponentObserver>();
Exemplo n.º 9
0
        public static void ValueChange <TSource, TProp>(this TSource source, Func <TSource, TProp> propertySelector, Action <TProp> callback, ent e)
        {
            Wrap <TSource, TProp> w = new Wrap <TSource, TProp>();

            w.source   = source;
            w.prop     = propertySelector;
            w.callback = callback;

                        #if UNITY_EDITOR
            if (Comparers.storage.TryGetValue(typeof(TProp).GetHashCode(), out object comparer))
            {
                w.comparer = comparer as IEqualityComparer <TProp>;
            }
            else
            {
                Debug.LogError($"Comparer for {typeof(TProp)} not found.");
            }
                        #else
            w.comparer = Comparers.storage[typeof(TProp).GetHashCode()]  as IEqualityComparer <TProp>;
                        #endif

            var cObserver = e.Add <ComponentObserver>();

            if (cObserver.length == cObserver.wrappers.Length)
            {
                Array.Resize(ref cObserver.wrappers, cObserver.length << 1);
            }

            cObserver.wrappers[cObserver.length++] = w;
        }
Exemplo n.º 10
0
Arquivo: Entity.cs Projeto: bmjoy/ecs
        public static void RenameGameobject(this ent entity)
        {
            var tr = transforms[entity.id];

            tr.name = entity.id.ToString();
        }