Exemple #1
0
        public void ImportComponentValues(Entity currentEntity, XElement component)
        {
            //Component
            switch (component.Attribute("Type").Value)
            {
            case "Physics":
                PhysicsComponent physicsComponent = ((PhysicsComponent)currentEntity.GetComponentOfType(typeof(PhysicsComponent)));
                physicsComponent.SetEnable(true);
                physicsComponent.masse              = int.Parse(component.Element("masse").Value);
                physicsComponent.useGravity         = bool.Parse(component.Element("useGravity").Value);
                physicsComponent.useAirFriction     = bool.Parse(component.Element("useAirFriction").Value);
                physicsComponent.airFrictionTweaker = float.Parse(component.Element("airFrictionTweaker").Value);
                break;

            case "BoxCollision":
                BoxCollisionComponent boxCollisionComponent = ((BoxCollisionComponent)currentEntity.GetComponentOfType(typeof(BoxCollisionComponent)));
                boxCollisionComponent.SetEnable(true);
                boxCollisionComponent.size.X    = float.Parse(component.Element("sizeX").Value);
                boxCollisionComponent.size.Y    = float.Parse(component.Element("sizeY").Value);
                boxCollisionComponent.isTrigger = bool.Parse(component.Element("isTrigger").Value);
                break;

            case "Position":
                PositionComponent positionComponent = ((PositionComponent)currentEntity.GetComponentOfType(typeof(PositionComponent)));
                positionComponent.SetEnable(true);
                positionComponent.position.X  = float.Parse(component.Element("posX").Value);
                positionComponent.position.Y  = float.Parse(component.Element("posY").Value);
                positionComponent.orientation = float.Parse(component.Element("orientation").Value);
                break;

            case "Velocity":
                VelocityComponent velocityComponent = ((VelocityComponent)currentEntity.GetComponentOfType(typeof(VelocityComponent)));
                velocityComponent.SetEnable(true);
                velocityComponent.maxVelocity = float.Parse(component.Element("maxVelocity").Value);
                break;

            case "Render":
                RenderComponent renderComponent = ((RenderComponent)currentEntity.GetComponentOfType(typeof(RenderComponent)));
                renderComponent.SetEnable(true);
                renderComponent.image  = component.Element("image").Value;
                renderComponent.size.X = int.Parse(component.Element("sizeX").Value);
                renderComponent.size.Y = int.Parse(component.Element("sizeY").Value);
                break;

            case "Script":
                ScriptComponent scriptComponent = ((ScriptComponent)currentEntity.GetComponentOfType(typeof(ScriptComponent)));
                scriptComponent.SetEnable(true);
                scriptComponent.scriptName = component.Element("scriptName").Value;
                break;

            default:
                throw new Exception("Undefined Component");
            }
        }
Exemple #2
0
        private void UpdateComponentProperties()
        {
            int indexScene     = GameEngineEditor.instance.sceneComboBox.SelectedIndex;
            int indexEntity    = GameEngineEditor.instance.entityComboBox.SelectedIndex;
            int indexComponent = GameEngineEditor.instance.componentComboBox.SelectedIndex;

            HideComponentPanel();

            if (indexScene >= 0 && indexEntity >= 0 && indexComponent >= 0)
            {
                string componentPanelComboBoxText = GameEngineEditor.instance.componentComboBox.SelectedItem.ToString();
                switch (componentPanelComboBoxText)
                {
                case ("Physics"):
                    GameEngineEditor.instance.physicsCompPanel.Visible = true;
                    PhysicsComponent physicsComponent = (PhysicsComponent)(_scenes[indexScene].GetEntities()[indexEntity].GetComponentOfType(typeof(PhysicsComponent)));
                    GameEngineEditor.instance.physicsEnableCheckBox.Checked      = physicsComponent.componentEnable;
                    GameEngineEditor.instance.physicsMasseTextBox.Text           = physicsComponent.masse.ToString();
                    GameEngineEditor.instance.physicsGravityCheckBox.Checked     = physicsComponent.useGravity;
                    GameEngineEditor.instance.physicsAirFrictionCheckBox.Checked = physicsComponent.useAirFriction;
                    GameEngineEditor.instance.physicsAirTweakerTextBox.Text      = physicsComponent.airFrictionTweaker.ToString();

                    break;

                case ("BoxCollision"):
                    GameEngineEditor.instance.boxColliderCompPanel.Visible = true;
                    BoxCollisionComponent boxCollisionComponent = (BoxCollisionComponent)(_scenes[indexScene].GetEntities()[indexEntity].GetComponentOfType(typeof(BoxCollisionComponent)));
                    GameEngineEditor.instance.boxColliderEnableCheckBox.Checked = boxCollisionComponent.componentEnable;
                    GameEngineEditor.instance.boxColliderSizeXTextBox.Text      = boxCollisionComponent.size.X.ToString();
                    GameEngineEditor.instance.boxColliderSizeYTextBox.Text      = boxCollisionComponent.size.Y.ToString();
                    GameEngineEditor.instance.isTriggerCheckBox.Checked         = boxCollisionComponent.isTrigger;
                    break;

                case ("Position"):
                    GameEngineEditor.instance.positionCompPanel.Visible = true;
                    PositionComponent positionComponent = (PositionComponent)(_scenes[indexScene].GetEntities()[indexEntity].GetComponentOfType(typeof(PositionComponent)));
                    GameEngineEditor.instance.positionXTextBox.Text       = positionComponent.position.X.ToString();
                    GameEngineEditor.instance.positionYTextBox.Text       = positionComponent.position.Y.ToString();
                    GameEngineEditor.instance.positionAngularTextBox.Text = positionComponent.orientation.ToString();
                    break;

                case ("Velocity"):
                    GameEngineEditor.instance.velocityCompPanel.Visible = true;
                    VelocityComponent velocityComponent = (VelocityComponent)(_scenes[indexScene].GetEntities()[indexEntity].GetComponentOfType(typeof(VelocityComponent)));
                    GameEngineEditor.instance.velocityEnableCheckBox.Checked = velocityComponent.componentEnable;
                    GameEngineEditor.instance.velocityMaxTextBox.Text        = velocityComponent.maxVelocity.ToString();
                    break;

                case ("Render"):
                    GameEngineEditor.instance.renderCompPanel.Visible = true;
                    RenderComponent renderComponent = (RenderComponent)(_scenes[indexScene].GetEntities()[indexEntity].GetComponentOfType(typeof(RenderComponent)));
                    GameEngineEditor.instance.renderEnableCheckBox.Checked = renderComponent.componentEnable;
                    GameEngineEditor.instance.renderImageTextBox.Text      = renderComponent.image.ToString();
                    GameEngineEditor.instance.renderSizeXTextBox.Text      = renderComponent.size.X.ToString();
                    GameEngineEditor.instance.renderSizeYTextBox.Text      = renderComponent.size.Y.ToString();
                    break;

                case ("Script"):
                    GameEngineEditor.instance.scriptCompPanel.Visible = true;
                    ScriptComponent scriptComponent = (ScriptComponent)(_scenes[indexScene].GetEntities()[indexEntity].GetComponentOfType(typeof(ScriptComponent)));
                    GameEngineEditor.instance.scriptEnableCheckBox.Checked = scriptComponent.componentEnable;
                    GameEngineEditor.instance.scriptNameTextBox.Text       = scriptComponent.scriptName?.ToString();
                    break;

                default:
                    break;
                }
            }
        }