Beispiel #1
0
        /// <summary>
        /// Creates and begins tracking a new <see cref="Komodo.Core.ECS.Systems.Render3DSystem"/>.
        /// </summary>
        public Render3DSystem CreateRender3DSystem()
        {
            var system = new Render3DSystem(this);

            Render3DSystems.Add(system);
            return(system);
        }
Beispiel #2
0
        /// <summary>
        /// Adds a <see cref="Komodo.Core.ECS.Components.Component"/> to the relevant <see cref="Komodo.Core.ECS.Systems.ISystem"/>. <see cref="AddComponent(Component)"/> will also remove the <see cref="Komodo.Core.ECS.Components.Component"/> from any Entity and <see cref="Komodo.Core.ECS.Systems.ISystem"/> it was attached to before.
        /// </summary>
        /// <param name="component"><see cref="Komodo.Core.ECS.Components.Component"/> to add.</param>
        /// <returns>Whether or not the <see cref="Komodo.Core.ECS.Components.Component"/> was added to this Entity's <see cref="Components"/>. Returns false if the <see cref="Komodo.Core.ECS.Components.Component"/> already existed.</returns>
        public bool AddComponent([NotNull] Component component)
        {
            if (component == null)
            {
                return(false);
            }
            if (Components == null)
            {
                Components = new List <Component>();
            }
            if (Components.Contains(component))
            {
                return(false);
            }
            if (component.Parent != null)
            {
                component.Parent.RemoveComponent(component);
            }
            Components.Add(component);
            component.Parent = this;
            switch (component)
            {
            case BehaviorComponent componentToAdd:
                return(Game.BehaviorSystem.AddComponent(componentToAdd));

            case CameraComponent componentToAdd:
                return(Game.CameraSystem.AddComponent(componentToAdd));

            case Drawable2DComponent componentToAdd:
                if (Render2DSystem == null)
                {
                    Render2DSystem = Game.CreateRender2DSystem();
                }
                return(Render2DSystem.AddComponent(componentToAdd));

            case Drawable3DComponent componentToAdd:
                if (Render3DSystem == null)
                {
                    Render3DSystem = Game.CreateRender3DSystem();
                }
                return(Render3DSystem.AddComponent(componentToAdd));

            case PhysicsComponent componentToAdd:
                if (PhysicsSystem == null)
                {
                    PhysicsSystem = Game.CreatePhysicsSystem();
                }
                return(PhysicsSystem.AddComponent(componentToAdd));

            case SoundComponent componentToAdd:
                return(Game.SoundSystem.AddComponent(componentToAdd));

            default:
                return(false);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Removes an individual <see cref="Komodo.Core.ECS.Components.Component"/> from this Entity's <see cref="Components"/>.
        /// </summary>
        /// <param name="component"><see cref="Komodo.Core.ECS.Components.Component"/> to remove.</param>
        /// <returns>Whether or not the <see cref="Komodo.Core.ECS.Components.Component"/> was removed from this Entity's <see cref="Components"/>. Will return false if the <see cref="Komodo.Core.ECS.Components.Component"/> is not present in <see cref="Components"/>.</returns>
        public bool RemoveComponent([NotNull] Component component)
        {
            if (component == null)
            {
                return(false);
            }
            if (Components != null)
            {
                switch (component)
                {
                case BehaviorComponent componentToRemove:
                    if (!Game.BehaviorSystem.RemoveComponent(componentToRemove))
                    {
                        return(false);
                    }
                    break;

                case CameraComponent componentToRemove:
                    if (Render2DSystem.ActiveCamera == componentToRemove)
                    {
                        Render2DSystem.ActiveCamera = null;
                    }
                    if (Render3DSystem.ActiveCamera == componentToRemove)
                    {
                        Render3DSystem.ActiveCamera = null;
                    }
                    if (!Game.CameraSystem.RemoveComponent(componentToRemove))
                    {
                        return(false);
                    }
                    break;

                case Drawable2DComponent componentToRemove:
                    if (Render2DSystem != null)
                    {
                        if (!Render2DSystem.RemoveComponent(componentToRemove))
                        {
                            return(false);
                        }
                    }
                    break;

                case Drawable3DComponent componentToRemove:
                    if (Render3DSystem != null)
                    {
                        if (!Render3DSystem.RemoveComponent(componentToRemove))
                        {
                            return(false);
                        }
                    }
                    break;

                case PhysicsComponent componentToRemove:
                    if (PhysicsSystem != null)
                    {
                        if (!PhysicsSystem.RemoveComponent(componentToRemove))
                        {
                            return(false);
                        }
                    }
                    break;

                case SoundComponent componentToRemove:
                    if (!Game.SoundSystem.RemoveComponent(componentToRemove))
                    {
                        return(false);
                    }
                    break;

                default:
                    return(false);
                }
                component.Parent = null;
                return(Components.Remove(component));
            }
            return(false);
        }