コード例 #1
0
        public void DestroyEntity(SimulationEntity entity)
        {
            if (!initialized)
            {
                throw new InvalidOperationException("Can't remove entities from simulations that haven't been initialized");
            }

            if (entity.Destroyed)
            {
                throw new InvalidOperationException("Can't remove a destroyed entity");
            }

            if (simulationListener != null)
            {
                simulationListener.EntityRemoved(entity);
            }

            for (int i = 0; i < entity.components.Count; i++)
            {
                for (int j = 0; j < componentManagers.Count; j++)
                {
                    componentManagers[j].ComponentRemoved(entity.components[i]);
                }
            }

            entity.Destroy();

            entities.Remove(entity);
        }
コード例 #2
0
        public SimulationEntity AddEntity(EntityTemplate template)
        {
            if (!initialized)
            {
                throw new InvalidOperationException("Can't add entities to simulations that haven't been initialized");
            }

            SimulationEntity entity = new SimulationEntity();

            entities.Add(entity);

            entity.Init(this, nextEntityId++, template);

            for (int i = 0; i < entity.components.Count; i++)
            {
                for (int j = 0; j < componentManagers.Count; j++)
                {
                    componentManagers[j].ComponentAdded(entity.components[i]);
                }
            }

            if (simulationListener != null)
            {
                simulationListener.EntityAdded(entity);
            }

            return(entity);
        }
コード例 #3
0
        internal void Destroy()
        {
            OnDestroy();

            this.entity = null;
        }
コード例 #4
0
        public void InitDependencies(SimulationEntity entity)
        {
            this.entity = entity;

            OnInitDependencies();
        }