コード例 #1
0
        public int AddEntity(NetEntity entity, bool setIndex = true)
        {
            if (Entities.Contains(entity))
            {
                return(-1);
            }

            if (entity.Started)
            {
                return(-1);
            }

            Entities.Add(entity);

            if (setIndex)
            {
                entity.EntityId = NextEntityIndex;

                // do this so clients can create their own client-side entities
                // and its id wont overlap with server-side entities
                if (!Game.IsHost)
                {
                    entity.EntityId *= -1;
                }
            }

            entity.Start();

            OnEntityAdded?.Invoke(entity);

            return(entity.EntityId);
        }
コード例 #2
0
 void AddEntity(Entity <T> entity, Type type, T component)
 {
     if (AddEntitySilently(entity))
     {
         OnEntityAdded?.Invoke(this, entity, type, component);
     }
 }
コード例 #3
0
        public Entity CreateEntity(string entityName)
        {
            //Entity newEnt =  Factory.CreateEntityFromTemplate(entityName);
            Entity newEnt = Factory.CreateEntityFromPool(entityName);

            OnEntityAdded?.Invoke(newEnt);
            return(newEnt);
        }
コード例 #4
0
 /// This is used by the pool to manage the group.
 public void UpdateEntity(Entity <T> entity, Type type, T previousComponent, T newComponent)
 {
     if (_entities.Contains(entity))
     {
         OnEntityRemoved?.Invoke(this, entity, type, previousComponent);
         OnEntityAdded?.Invoke(this, entity, type, newComponent);
         OnEntityUpdated?.Invoke(this, entity, type, previousComponent, newComponent);
     }
 }
コード例 #5
0
 /// This is used by the context to manage the group.
 public void UpdateEntity(TEntity entity, int index, IComponent previousComponent, IComponent newComponent)
 {
     if (_entities.Contains(entity))
     {
         OnEntityRemoved?.Invoke(this, entity, index, previousComponent);
         OnEntityAdded?.Invoke(this, entity, index, newComponent);
         OnEntityUpdated?.Invoke(this, entity, index, previousComponent, newComponent);
     }
 }
コード例 #6
0
        public Entity CreateEntity(string name, HashSet <Type> set)
        // where each Type obj : is typeof(IComponent)
        {
            Entity e = new Entity(name, set);

            entities.Add(name, e);

            OnEntityAdded?.Invoke(e);

            return(e);
        }
コード例 #7
0
        /// <summary>
        /// Dispatches entity adding logic
        /// </summary>
        internal void ProcessEntitiesForAdding()
        {
            while (EntitiesForAdding.Count != 0)
            {
                Entity entity = EntitiesForAdding.Dequeue();

                Entities[entity.Id] = entity;

                OnEntityAdded?.Invoke(entity);
            }
        }
コード例 #8
0
 private void AddEntity(TEntity entity, int index, IComponent component)
 {
     if (AddEntitySilently(entity))
     {
         OnEntityAdded?.Invoke(
             this,
             entity,
             index,
             component);
     }
 }
コード例 #9
0
 public void Dispose()
 {
     if (OnEntityAdded != null)
     {
         OnEntityAdded.Dispose();
     }
     if (OnEntityRemoved != null)
     {
         OnEntityRemoved.Dispose();
     }
     _subscriptions.DisposeAll();
 }
コード例 #10
0
        public void OnEntityAddedToPool(EntityAddedEvent args)
        {
            if (!args.Entity.Components.Any())
            {
                return;
            }

            var matchesGroup = args.Entity.HasComponents(ComponentTypes);

            if (matchesGroup)
            {
                OnEntityAdded.OnNext(args.Entity);
            }
        }
コード例 #11
0
        public void AddEntity(ECSEntity entity)
        {
            if (!entities.Contains(entity))
            {
                entities.Add(entity);
                OnEntityAdded?.Invoke(entity);

                entity.OnComponentAdded += cmp =>
                {
                    OnComponentAddedToEntity?.Invoke(entity, cmp);
                };

                entity.OnComponentRemoved += cmp => OnComponentRemovedToEntity?.Invoke(entity, cmp);
            }
        }
コード例 #12
0
        public void Add <T>(T t) where T : IDbEntity
        {
            AddType <T>();

            Type type = typeof(T);

            int id = ++IndexTracker[type];

            t.EntityId = id;
            Database[type].Add(t);

            ApplyChanges();

            OnDatabaseChanged?.Invoke(this);

            OnEntityAdded?.Invoke(t);
        }
コード例 #13
0
ファイル: ParcelScene.cs プロジェクト: menduz/explorer
        public DecentralandEntity CreateEntity(string id)
        {
            SceneController.i.OnMessageDecodeStart?.Invoke("CreateEntity");
            tmpCreateEntityMessage.id = id;
            SceneController.i.OnMessageDecodeEnds?.Invoke("CreateEntity");

            if (entities.ContainsKey(tmpCreateEntityMessage.id))
            {
                return(entities[tmpCreateEntityMessage.id]);
            }

            var newEntity = new DecentralandEntity();

            newEntity.entityId = tmpCreateEntityMessage.id;

            // We need to manually create the Pool for empty game objects if it doesn't exist
            if (!PoolManager.i.ContainsPool(EMPTY_GO_POOL_NAME))
            {
                GameObject go   = new GameObject();
                Pool       pool = PoolManager.i.AddPool(EMPTY_GO_POOL_NAME, go, maxPrewarmCount: ENTITY_POOL_PREWARM_COUNT);
                pool.ForcePrewarm();
            }

            // As we know that the pool already exists, we just get one gameobject from it
            PoolableObject po = PoolManager.i.Get(EMPTY_GO_POOL_NAME);

            newEntity.gameObject      = po.gameObject;
            newEntity.gameObject.name = "ENTITY_" + tmpCreateEntityMessage.id;
            newEntity.gameObject.transform.SetParent(gameObject.transform, false);
            newEntity.gameObject.SetActive(true);
            newEntity.scene = this;

            newEntity.OnCleanupEvent += po.OnCleanup;

            if (SceneController.i.useBoundariesChecker)
            {
                newEntity.OnShapeUpdated += SceneController.i.boundariesChecker.AddEntityToBeChecked;
            }

            entities.Add(tmpCreateEntityMessage.id, newEntity);

            OnEntityAdded?.Invoke(newEntity);

            return(newEntity);
        }
コード例 #14
0
        public void OnEntityComponentAdded(ComponentAddedEvent args)
        {
            var originalComponentTypes = args.Entity.Components.Select(x => x.GetType()).ToList();

            originalComponentTypes.Remove(args.Component.GetType());

            var previouslyMatched = ComponentTypes.All(x => originalComponentTypes.Contains(x));

            if (previouslyMatched)
            {
                return;
            }

            var newComponentMatches = ComponentTypes.Contains(args.Component.GetType());

            if (newComponentMatches)
            {
                OnEntityAdded.OnNext(args.Entity);
            }
        }
コード例 #15
0
ファイル: ParcelScene.cs プロジェクト: yemel/explorer
        public DecentralandEntity CreateEntity(string id)
        {
            SceneController.i.OnMessageDecodeStart?.Invoke("CreateEntity");
            SceneController.i.OnMessageDecodeEnds?.Invoke("CreateEntity");

            if (entities.ContainsKey(id))
            {
                return(entities[id]);
            }

            var newEntity = new DecentralandEntity();

            newEntity.entityId = id;

            SceneController.i.EnsureEntityPool();

            // As we know that the pool already exists, we just get one gameobject from it
            PoolableObject po = PoolManager.i.Get(SceneController.EMPTY_GO_POOL_NAME);

            newEntity.gameObject = po.gameObject;

#if UNITY_EDITOR
            newEntity.gameObject.name = "ENTITY_" + id;
#endif
            newEntity.gameObject.transform.SetParent(gameObject.transform, false);
            newEntity.gameObject.SetActive(true);
            newEntity.scene = this;

            newEntity.OnCleanupEvent += po.OnCleanup;

            if (SceneController.i.useBoundariesChecker)
            {
                newEntity.OnShapeUpdated += SceneController.i.boundariesChecker.AddEntityToBeChecked;
            }

            entities.Add(id, newEntity);

            OnEntityAdded?.Invoke(newEntity);

            return(newEntity);
        }
コード例 #16
0
        public IDCLEntity CreateEntity(string id)
        {
            if (entities.ContainsKey(id))
            {
                return(entities[id]);
            }

            var newEntity = new DecentralandEntity();

            newEntity.entityId = id;

            Environment.i.world.sceneController.EnsureEntityPool();

            // As we know that the pool already exists, we just get one gameobject from it
            PoolableObject po = PoolManager.i.Get(SceneController.EMPTY_GO_POOL_NAME);

            newEntity.meshesInfo.innerGameObject = po.gameObject;
            newEntity.gameObject = po.gameObject;
            newEntity.transform  = po.gameObject.transform;

#if UNITY_EDITOR
            newEntity.gameObject.name = "ENTITY_" + id;
#endif
            newEntity.gameObject.transform.SetParent(gameObject.transform, false);
            newEntity.gameObject.SetActive(true);
            newEntity.scene = this;

            newEntity.OnCleanupEvent += po.OnCleanup;

            if (Environment.i.world.sceneBoundsChecker.enabled)
            {
                newEntity.OnShapeUpdated += Environment.i.world.sceneBoundsChecker.AddEntityToBeChecked;
            }

            entities.Add(id, newEntity);

            OnEntityAdded?.Invoke(newEntity);

            return(newEntity);
        }
コード例 #17
0
 /// <summary>
 /// Adds an entity to this pool
 /// </summary>
 public void Add(Entity entity)
 {
     entities.Add(entity);
     OnEntityAdded?.Invoke(this, entity);
 }
コード例 #18
0
 public void TriggerEntityAdded(Entity entity)
 {
     OnEntityAdded?.Invoke(entity);
 }
コード例 #19
0
        public void AddNewEntity(Entity entity)
        {
            entities.Add(entity.Name, entity);

            OnEntityAdded?.Invoke(entity);
        }
コード例 #20
0
 internal static void RaiseEntityAdded(Entity entity)
 {
     OnEntityAdded?.Invoke(entity);
 }