コード例 #1
0
ファイル: Cv_ScriptComponent.cs プロジェクト: jocamar/Caravel
        private void OnExecuteScriptTimeout()
        {
            if (Owner == null)
            {
                return;
            }

            if (ScriptResource != null && ScriptResource != "")
            {
                Cv_ScriptResource scriptRes = Cv_ResourceManager.Instance.GetResource <Cv_ScriptResource>(ScriptResource, Owner.ResourceBundle);
                scriptRes.RunScript(Owner, RunInEditor);
            }

            m_bRanOnce = true;

            if (!ExecuteOnce)
            {
                m_Timer = new Cv_TimerProcess(Interval, OnExecuteScriptTimeout);
                Cv_ProcessManager.Instance.AttachProcess(m_Timer);
            }
        }
コード例 #2
0
        protected override void VGameOnUpdate(float time, float timeElapsed)
        {
            var cam = GetEntity(EditorView.EditorCamera);

            if (cam == null)
            {
                return;
            }

            var camTransf   = cam.GetComponent <Cv_TransformComponent>();
            var camSettings = cam.GetComponent <Cv_CameraComponent>();

            var mouseState    = Mouse.GetState();
            var keyboardState = Keyboard.GetState();
            var editorApp     = ((EditorApp)Caravel);
            var mousePos      = Cv_InputManager.Instance.GetMouseValues().MousePos;
            var mouseScroll   = Cv_InputManager.Instance.GetMouseValues().MouseWheelVal;

            //MOUSE ACTIONS
            if (Cv_InputManager.Instance.CommandActive("mouseLeftClick", Cv_Player.One))
            {
                if (editorApp.Mode == EditorApp.EditorMode.TRANSFORM)
                {
                    if (editorApp.EWindow != null &&
                        editorApp.EWindow.Focused &&
                        editorApp.EWindow.EditorForm.CanSelectEntities &&
                        mousePos.X > 0 && mousePos.Y > 0)
                    {
                        Cv_EntityID[] entities;
                        EditorView.Pick(mousePos, out entities);

                        if (Cv_InputManager.Instance.CommandActivated("mouseLeftClick", Cv_Player.One))
                        {
                            if (!Cv_InputManager.Instance.CommandActive("alternateMode", Cv_Player.One))
                            {
                                if (entities.Length > 0)
                                {
                                    if (entities[0] != editorApp.EForm.CurrentEntity)
                                    {
                                        editorApp.EForm.SetSelectedEntity(entities[0]);
                                    }

                                    if (!m_bMovingEntity)
                                    {
                                        m_EntityBeingMoved = GetEntity(editorApp.EForm.CurrentEntity);
                                    }
                                }
                                else
                                {
                                    var timer = new Cv_TimerProcess(100, DeselectEntity);
                                    Caravel.ProcessManager.AttachProcess(timer);
                                }
                            }
                            else if (editorApp.EForm.CurrentEntity != Cv_EntityID.INVALID_ENTITY)
                            {
                                if (!m_bMovingEntity)
                                {
                                    m_EntityBeingMoved = GetEntity(editorApp.EForm.CurrentEntity);
                                }
                            }
                        }

                        if (Cv_InputManager.Instance.CommandActive("mouseMove", Cv_Player.One) && m_EntityBeingMoved != null)
                        {
                            m_bMovingEntity = true;
                            var trasnfComp = m_EntityBeingMoved.GetComponent <Cv_TransformComponent>();

                            if (trasnfComp == null)
                            {
                                m_bMovingEntity    = false;
                                m_EntityBeingMoved = null;
                            }
                            else
                            {
                                var delta       = m_DeltaBuffer + (mousePos - m_PrevMousePos);
                                var deltaXscale = delta / (float)EditorView.EditorRenderer.Scale;
                                var entityDelta = deltaXscale / camSettings.Zoom;

                                var numStepsX = ((int)entityDelta.X) / EntityDragStepX;
                                var numStepsY = ((int)entityDelta.Y) / EntityDragStepY;

                                var finalDelta = new Vector3(numStepsX * EntityDragStepX, numStepsY * EntityDragStepY, 0);


                                m_DeltaBuffer = delta;
                                if (finalDelta != Vector3.Zero)
                                {
                                    trasnfComp.SetPosition(trasnfComp.Position + finalDelta);

                                    if (finalDelta.X != 0)
                                    {
                                        m_DeltaBuffer = new Vector2(0, m_DeltaBuffer.Y);
                                    }

                                    if (finalDelta.Y != 0)
                                    {
                                        m_DeltaBuffer = new Vector2(m_DeltaBuffer.X, 0);
                                    }
                                }
                            }
                        }
                    }
                }
                else if (editorApp.Mode == EditorApp.EditorMode.CAMERA &&
                         editorApp.EWindow != null &&
                         editorApp.EWindow.Focused && m_PrevMousePos.X != -1)
                {
                    var delta = m_PrevMousePos - mousePos;

                    camTransf.SetPosition(camTransf.Position + new Vector3(delta, 0) / (camSettings.Zoom * (float)EditorView.EditorRenderer.Scale));
                }
                else if (editorApp.Mode == EditorApp.EditorMode.CREATE)
                {
                    if (Cv_InputManager.Instance.CommandActivated("mouseLeftClick", Cv_Player.One))
                    {
                        var timer = new Cv_TimerProcess(100, PaintEntity);
                        Caravel.ProcessManager.AttachProcess(timer);
                    }
                }
            }
            else
            {
                if (editorApp.Mode == EditorApp.EditorMode.TRANSFORM)
                {
                    if (m_bMovingEntity)
                    {
                        m_bMovingEntity    = false;
                        m_EntityBeingMoved = null;
                        m_DeltaBuffer      = Vector2.Zero;
                        editorApp.EForm.UpdateEntityXml();
                    }
                }
            }

            if (Cv_InputManager.Instance.CommandActive("mouseWheelUp", Cv_Player.One) || Cv_InputManager.Instance.CommandActive("mouseWheelDown", Cv_Player.One))
            {
                m_iIdleTime = 0;
                var delta = mouseScroll - m_iPreviousScrollValue;

                if (editorApp.Mode == EditorApp.EditorMode.CAMERA)
                {
                    camSettings.Zoom += delta / 3000f;
                    editorApp.EForm.UpdateTools();
                }
                else if (editorApp.Mode == EditorApp.EditorMode.TRANSFORM)
                {
                    if (editorApp.EWindow != null &&
                        editorApp.EWindow.Focused &&
                        editorApp.EWindow.EditorForm.CanSelectEntities)
                    {
                        var entity = GetEntity(editorApp.EForm.CurrentEntity);

                        if (entity != null)
                        {
                            var trasnfComp = entity.GetComponent <Cv_TransformComponent>();

                            if (trasnfComp != null)
                            {
                                m_bRotatingEntity = true;
                                trasnfComp.SetRotation(trasnfComp.Rotation + delta / 3000f);
                            }
                        }
                    }
                }
            }
            else if (m_bRotatingEntity)
            {
                if (m_iIdleTime > 1000)
                {
                    m_bRotatingEntity = false;
                    editorApp.EForm.UpdateEntityXml();
                    m_iIdleTime = 0;
                }
                else
                {
                    m_iIdleTime += (int)(timeElapsed);
                }
            }

            //SAVE SHORTCUT
            if (Cv_InputManager.Instance.CommandActive("alternateMode", Cv_Player.One) && Cv_InputManager.Instance.CommandDeactivated("save", Cv_Player.One))
            {
                if (editorApp.EForm.CurrentSceneFile != null && editorApp.EForm.CurrentSceneFile != "")
                {
                    editorApp.EForm.SaveScene();
                }
            }


            //MOVE ENTITIES WITH ARROWS
            if (Cv_InputManager.Instance.CommandActivated("Left", Cv_Player.One))
            {
                if (editorApp.Mode == EditorApp.EditorMode.TRANSFORM)
                {
                    if (editorApp.EForm.CurrentEntity != Cv_EntityID.INVALID_ENTITY)
                    {
                        var e = GetEntity(editorApp.EForm.CurrentEntity);

                        if (e != null && e.GetComponent <Cv_TransformComponent>() != null)
                        {
                            var pos = e.GetComponent <Cv_TransformComponent>().Position;

                            e.GetComponent <Cv_TransformComponent>().SetPosition(new Vector3(pos.X - 1, pos.Y, pos.Z));
                        }
                    }
                }
            }

            if (Cv_InputManager.Instance.CommandActivated("Right", Cv_Player.One))
            {
                if (editorApp.Mode == EditorApp.EditorMode.TRANSFORM)
                {
                    if (editorApp.EForm.CurrentEntity != Cv_EntityID.INVALID_ENTITY)
                    {
                        var e = GetEntity(editorApp.EForm.CurrentEntity);

                        if (e != null && e.GetComponent <Cv_TransformComponent>() != null)
                        {
                            var pos = e.GetComponent <Cv_TransformComponent>().Position;

                            e.GetComponent <Cv_TransformComponent>().SetPosition(new Vector3(pos.X + 1, pos.Y, pos.Z));
                        }
                    }
                }
            }

            if (Cv_InputManager.Instance.CommandActivated("Up", Cv_Player.One))
            {
                if (editorApp.Mode == EditorApp.EditorMode.TRANSFORM)
                {
                    if (editorApp.EForm.CurrentEntity != Cv_EntityID.INVALID_ENTITY)
                    {
                        var e = GetEntity(editorApp.EForm.CurrentEntity);

                        if (e != null && e.GetComponent <Cv_TransformComponent>() != null)
                        {
                            var pos = e.GetComponent <Cv_TransformComponent>().Position;

                            e.GetComponent <Cv_TransformComponent>().SetPosition(new Vector3(pos.X, pos.Y - 1, pos.Z));
                        }
                    }
                }
            }

            if (Cv_InputManager.Instance.CommandActivated("Down", Cv_Player.One))
            {
                if (editorApp.Mode == EditorApp.EditorMode.TRANSFORM)
                {
                    if (editorApp.EForm.CurrentEntity != Cv_EntityID.INVALID_ENTITY)
                    {
                        var e = GetEntity(editorApp.EForm.CurrentEntity);

                        if (e != null && e.GetComponent <Cv_TransformComponent>() != null)
                        {
                            var pos = e.GetComponent <Cv_TransformComponent>().Position;

                            e.GetComponent <Cv_TransformComponent>().SetPosition(new Vector3(pos.X, pos.Y + 1, pos.Z));
                        }
                    }
                }
            }

            //DELETE KEY
            if (Cv_InputManager.Instance.CommandActivated("Delete", Cv_Player.One))
            {
                if (editorApp.Mode == EditorApp.EditorMode.TRANSFORM)
                {
                    if (editorApp.EForm.CurrentEntity != Cv_EntityID.INVALID_ENTITY)
                    {
                        editorApp.EForm.RemoveEntityFromEditor(editorApp.EForm.CurrentEntity);
                        editorApp.EForm.SetSelectedEntity(Cv_EntityID.INVALID_ENTITY);
                    }
                }
            }

            m_PrevMousePos         = mousePos;
            m_iPreviousScrollValue = mouseScroll;
        }