/// <summary>
        /// Used to remove an EngineComponent from this.
        /// </summary>
        /// <param name="component">The EngineComponent to be removed.</param>
        public void RemoveComponent(EngineComponent component)
        {
            if (comps.Contains(component))
            {
                if (component is IDispose)
                {
                    ((IDispose)component).Dispose(true);
                    disposableComps.Remove(component as IDispose);
                }

                if (component is IUpdate)
                {
                    updateComps.Remove(component as IUpdate);
                }

                if (component is IRenderComponent)
                {
                    renderComps.Remove(component as IRenderComponent);
                }

                if (component is IPostRenderComponent)
                {
                    postRenderComps.Remove(component as IPostRenderComponent);
                }

                comps.Remove(component);
            }
        }
예제 #2
0
        /// <summary>
        /// Draws all of the IDrawItems that are to be drawn.
        /// </summary>
        public void Render()
        {
            if (layers.Layers > 0)
            {
                if (LightingManager.LightCount > 0 && CameraManager.CurrentCamera != null)
                {
                    Draw(DrawingStage.Colour);
                    Draw(DrawingStage.Normal);
                    Draw(DrawingStage.Distortion);
                    lighting.SetTargets(render.Texture, opaqueRender.Texture);
                    lighting.Draw();

                    final = lighting.Final;
                }
                else
                {
                    Draw(DrawingStage.Colour);

                    final = render.Texture;
                }
            }
            else
            {
                final = black;
            }

            EngineComponent comp = EngineComponentManager.Find("D2RenderFramework");

            if (comp != null)
            {
                comp.SendMessage("SetPostProcessing", new object[] { final,
                                                                     opaqueRender.Texture, distortionRender.Texture });
            }
        }
예제 #3
0
        internal static void AddComp(EngineComponent comp)
        {
            EngineComponent c = (from com in comps
                                 where com.ID == comp.ID
                                 select com).FirstOrDefault();

            if (c == null)
            {
                if (initialized)
                {
                    comp._Init();
                }

                comps.Add(comp);

                if (comp is IRenderComponent)
                {
                    renderComps.Add(comp as IRenderComponent);
                }

                if (comp is IUpdate)
                {
                    updateComps.Add(comp as IUpdate);
                }

                if (comp is IDispose)
                {
                    disposableComps.Add(comp as IDispose);
                }
            }
        }
        public static EngineComponent Find(Type type)
        {
            EngineComponent e = (from en in comps
                                 where en.GetType() == type
                                 select en).FirstOrDefault();

            return(e);
        }
        public static EngineComponent Find(string id)
        {
            EngineComponent e = (from en in comps
                                 where en.ID == id
                                 select en).FirstOrDefault();

            return(e);
        }
예제 #6
0
        public void StartTest_ShouldChangeIsRunningPropToTrue()
        {
            //Arrange
            EngineComponent engineComponent = new EngineComponent();

            //Act
            engineComponent.Start();

            //Assert
            Assert.IsTrue(engineComponent.IsRunning());
        }
        internal static void AddComp(EngineComponent comp)
        {
            EngineComponent c = (from com in comps
                                 where com.ID == comp.ID
                                 select com).FirstOrDefault();

            if (c == null)
            {
                comps.Add(comp);

                if (comp is IPostGameDraw)
                {
                    postGame.Add(comp as IPostGameDraw);
                }

                if (comp is IRenderComponent)
                {
                    renderComps.Add(comp as IRenderComponent);

                    List <IRenderComponent> temp;
                    SortHelper.SortList <IRenderComponent>(ref renderComps, out temp);

                    renderComps = temp;
                }

                if (comp is IPostRenderComponent)
                {
                    postRenderComps.Add(comp as IPostRenderComponent);

                    List <IPostRenderComponent> temp;
                    SortHelper.SortList <IPostRenderComponent>(ref postRenderComps, out temp);

                    postRenderComps = temp;
                }

                if (comp is IUpdate)
                {
                    updateComps.Add(comp as IUpdate);
                }

                if (comp is IDispose)
                {
                    disposableComps.Add(comp as IDispose);
                }

                if (initialized)
                {
                    comp._Init();
                }
            }
        }
예제 #8
0
        /// <summary>
        /// Creates an entity from an incoming message from the server.
        /// This is also added to the manager.
        /// </summary>
        /// <param name="message">Incoming Message.</param>
        /// <returns>Reference to created entity.</returns>
        public static Entity CreateEntityFromMessage
        (
            NetIncomingMessage message
        )
        {
            byte componentId;

            // Start creating new entity with given id
            Entity entity = new Entity(message.ReadInt32());

            // Components
            while ((componentId = message.ReadByte()) != 0)
            {
                IComponent component = null;
                switch ((ComponentId)componentId)
                {
                // Position component
                case ComponentId.Position:
                    component = new PositionComponent(entity);
                    break;

                // Animation component
                case ComponentId.Animation:
                    component = new AnimationComponent(entity);
                    break;

                case ComponentId.AffectedByBlackhole:
                    component = new AffectedByBlackholeComponent(entity);
                    break;

                case ComponentId.Engine:
                    component = new EngineComponent(entity);
                    break;
                }

                if (component != null)
                {
                    component.Deserialize(message);
                    entity.AddOrUpdateComponent(component);
                }
            }

            // Attempt to link all components, and add to manager.
            entity.LinkAllComponents();
            Add(entity);

            return(entity);
        }
예제 #9
0
        protected virtual void _LevelTransitionOn(string levelID)
        {
            EngineComponent comp = EngineComponentManager.Find("Camera2DManager");

            if (comp == null)
            {
                comp = EngineComponentManager.Find("Camera3DManager");

                if (comp != null)
                {
                    comp.SendMessage("LockToGameObject", position);
                }
            }
            else
            {
                comp.SendMessage("LockToGameObject", position, size);
            }
        }
예제 #10
0
    /// <summary>
    /// Set the part sprite for the engine
    /// </summary>
    /// <param name="partName">set the name for this sprite</param>
    /// <param name="partPath">set the image of this part</param>
    public void SetSprite(string partName, string partPath)
    {
        if (propComponents.ContainsKey(partName))
        {
            // if the part entry already exists then assign the new value to it
            propComponents[partName].ComponentSprite =
                Utilities.Instance.CreateSprite(partPath);
        }
        else
        {
            // create a new part entry if it doesnt exists
            EngineComponent comp = new EngineComponent
            {
                ComponentSprite = Utilities.Instance.CreateSprite(partPath)
            };

            // add entry to the collection
            propComponents.Add(partName, comp);
        }
    }
예제 #11
0
    /// <summary>
    /// this start method is private, it initializes the all engine component renderers, pariticle systems
    /// then calls the Initialize method, any specific engine code should go in Initialize instead
    /// </summary>
    private void Start()
    {
        // get the sprite renderer and transform for the main propulsion
        EngineComponent engine = new EngineComponent
        {
            ComponentTransform = transform,
            ComponentRenderer  = transform.GetComponent <SpriteRenderer>()
        };

        propComponents.Add("engine", engine);


        // get the sprite renderer and transform for the engine components
        foreach (Transform part in transform)
        {
            // get the engine effects renderer
            if (part.name == "engineEffect")
            {
                EngineComponent comp = new EngineComponent
                {
                    ComponentTransform = part,
                    ComponentRenderer  = part.GetComponent <SpriteRenderer>()
                };

                propComponents.Add("engineEffect", comp);
            }
            // get the particle system for engine effects
            else if (part.name == "engineParticles")
            {
                propParticles = part.GetComponent <ParticleSystem>();

                // set the particle system to the off state
                ParticleSystem.EmissionModule emission = propParticles.emission;
                emission.enabled = false;
            }
        }

        Initialize();
    }
예제 #12
0
        public override void Start()
        {
            engineComponent = FindObjectOfType <EngineComponent>();
            aimingComponent = FindObjectOfType <AimingComponent>();
            damageComponent = FindObjectOfType <DamageComponent>();

            aimingComponent.PropertyChanged += (sender, args) =>
                                               playerGun.ShootingAbility.shootingPeriodCoefficient = aimingComponent.Value;

            damageComponent.PropertyChanged += (sender, args) =>
                                               playerGun.ShootingAbility.bullet.damageCoefficient = damageComponent.Value;

            rb             = GetComponent <Rigidbody2D>();
            playerCollider = GetComponent <Collider2D>();
            playerGun      = GetComponentInChildren <GunController>();

            damagePart   = Vars.GetCarPart(PartType.Damage);
            shootingPart = Vars.GetCarPart(PartType.Shooting);
            armorPart    = Vars.GetCarPart(PartType.Armor);
            enginePart   = Vars.GetCarPart(PartType.Engine);
            base.Start();
            StartCoroutine(ApplyParts());
        }
예제 #13
0
 private void Awake()
 {
     engines = GetComponent <EngineComponent>();
     rb      = GetComponent <Rigidbody>();
 }
예제 #14
0
 public EngineComponent()
 {
     instance = this;
 }