Ejemplo n.º 1
0
        public override void Update(EditorWorldRaycastResult worldIntersection, float deltaTime)
        {
            if (Input.GetMouseButtonUp(MouseButton.Left))
            {
                transHandles.LetGo();
            }
            else if (Input.GetMouseButtonDown(MouseButton.Left) &&
                     !GUISystem.HandledMouseOver && selectedObject != null)
            {
                transHandles.TryGrab(Camera.Active);
            }

            if (!GUISystem.HandledMouseOver && Input.GetMouseButtonDown(MouseButton.Left) && !transHandles.HasHold)
            {
                if (worldIntersection.HitEditorObject)
                {
                    EditorObjectRaycastResult intersection = worldIntersection.EditorObjectResult;
                    selectedObject = intersection.EditorObject;
                }
                else
                {
                    selectedObject = null;
                }

                window.SetObject(selectedObject);
            }

            if (selectedObject != null)
            {
                Vector3 delta = transHandles.Update(Camera.Active, 16);
                if (!canMove)
                {
                    delta = Vector3.Zero;
                }

                AxisAlignedBoundingBox aabb = selectedObject.GetCollider();
                transHandles.PositionToMinMax(aabb.Min, aabb.Max, Vector3.Zero);

                if (canMove)
                {
                    if (transHandles.HasHold)
                    {
                        if (Input.WrapCursor())
                        {
                            canMove = false;
                        }
                    }
                }
                else
                {
                    Camera.Active.Update(deltaTime);
                    transHandles.ResetStartPos(Camera.Active);
                    canMove = true;
                }

                selectedObject.Transform.Position += delta;
            }
        }
Ejemplo n.º 2
0
        public override void Update(EditorWorldRaycastResult intersection, float deltaTime)
        {
            // Grab first because of how many times were using it
            EditorSelectionBox selectionBox = TerrainEditor.SelectionBox;

            if (Input.GetMouseButtonUp(MouseButton.Left))
            {
                transHandles.LetGo();
            }
            else if (Input.GetMouseButtonDown(MouseButton.Left))
            {
                transHandles.TryGrab(Camera.Active);
            }

            if (TerrainEditor.IsSelecting)
            {
                startSelectionBox.SetPrimary(selectionBox.Primary);
                startSelectionBox.SetSecondary(selectionBox.Secondary);
            }

            IndexPosition delta = transHandles.Update(Block.CUBE_SIZE, Camera.Active);

            if (!canMove)
            {
                delta = IndexPosition.Zero;
            }

            if (Input.IsControlHeld)
            {
                selectionBox.SetMinMax(selectionBox.Min, selectionBox.Max + delta);
                startSelectionBox.SetMinMax(startSelectionBox.Min, startSelectionBox.Max + delta);
            }
            else if (Input.IsAltHeld)
            {
                selectionBox.SetMinMax(selectionBox.Min + delta, selectionBox.Max);
                startSelectionBox.SetMinMax(startSelectionBox.Min + delta, startSelectionBox.Max);
            }
            else
            {
                selectionBox.Translate(delta);
            }

            transHandles.PositionToMinMax(selectionBox.Min, selectionBox.Max, Block.CUBE_SIZE, Block.CUBE_3D_SIZE);

            if (canMove)
            {
                if (transHandles.HasHold)
                {
                    if (Input.WrapCursor())
                    {
                        canMove = false;
                    }
                }
            }
            else
            {
                Camera.Active.Update(deltaTime);
                transHandles.ResetStartPos(Camera.Active);
                canMove = true;
            }

            if (Input.GetKeyDown(Key.Enter))
            {
                MoveSelection();
            }
            else if (Input.GetKeyDown(Key.Delete))
            {
                DeleteSelection();
            }

            if (Input.IsControlHeld)
            {
                if (Input.GetKeyDown(Key.C))
                {
                    CopySelection();
                }
                else if (Input.GetKeyDown(Key.X))
                {
                    CopySelection();
                    DeleteSelection();
                }
                else if (copy != null && Input.GetKeyDown(Key.V))
                {
                    PasteSelection();
                }
            }
        }