コード例 #1
0
        public void DestroyComponent(IEntityComponent component)
        {
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }
            if (component.Entity == null)
            {
                throw new EntityComponentException("Malformed IEntityComponent, not attached to an Entity.");
            }
            if (component.EntityManager == null)
            {
                throw new ArgumentException("Can only register component with the EntityManagerComponent it's entity is managed by.", "component");
            }

            component.Components.RemoveComponent(component);

            if (_updateThread != null && System.Threading.Thread.CurrentThread == _updateThread)
            {
                //occurred during the main update thread while this Update method is running
                switch (_phase)
                {
                case UpdatePhase.None:
                case UpdatePhase.InitializingPhase:
                case UpdatePhase.StartingPhase:
                case UpdatePhase.UpdatingPhase:
                case UpdatePhase.CleanUp:
                    lock (_lock)
                    {
                        _componentInitializeCache.Remove(component);
                    }
                    break;
                }
            }
            else
            {
                lock (_lock)
                {
                    _componentInitializeCache.Remove(component);
                }
            }

            component.Dispose();
        }