Exemplo n.º 1
0
        protected override void OnToolUpdate()
        {
            if (m_nextAction != ToolAction.None)
            {
                return;
            }

            if (m_pauseMenu != null && m_pauseMenu.isVisible)
            {
                if (ToolState == ToolStates.Default || ToolState == ToolStates.MouseDragging || ToolState == ToolStates.DrawingSelection)
                {
                    ToolsModifierControl.SetTool <DefaultTool>();
                }

                StopCloning();
                StopAligning();

                ToolState = ToolStates.Default;

                UIView.library.Hide("PauseMenu");

                return;
            }

            lock (ActionQueue.instance)
            {
                bool isInsideUI = this.m_toolController.IsInsideUI;

                if (m_leftClickTime == 0 && Input.GetMouseButton(0))
                {
                    if (!isInsideUI)
                    {
                        m_leftClickTime = Stopwatch.GetTimestamp();
                        OnLeftMouseDown();
                    }
                }

                if (m_leftClickTime != 0)
                {
                    long elapsed = ElapsedMilliseconds(m_leftClickTime);

                    if (!Input.GetMouseButton(0))
                    {
                        m_leftClickTime = 0;

                        if (elapsed < 200)
                        {
                            OnLeftClick();
                        }
                        else
                        {
                            OnLeftDragStop();
                        }

                        OnLeftMouseUp();
                    }
                    else if (elapsed >= 200)
                    {
                        OnLeftDrag();
                    }
                }

                if (m_rightClickTime == 0 && Input.GetMouseButton(1))
                {
                    if (!isInsideUI)
                    {
                        m_rightClickTime = Stopwatch.GetTimestamp();
                        OnRightMouseDown();
                    }
                }

                if (m_rightClickTime != 0)
                {
                    long elapsed = ElapsedMilliseconds(m_rightClickTime);

                    if (!Input.GetMouseButton(1))
                    {
                        m_rightClickTime = 0;

                        if (elapsed < 200)
                        {
                            OnRightClick();
                        }
                        else
                        {
                            OnRightDragStop();
                        }

                        OnRightMouseUp();
                    }
                    else if (elapsed >= 200)
                    {
                        OnRightDrag();
                    }
                }

                if (!isInsideUI && Cursor.visible)
                {
                    Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);

                    m_hoverInstance    = null;
                    m_marqueeInstances = null;
                    m_segmentGuide     = default(NetSegment);

                    switch (ToolState)
                    {
                    case ToolStates.Default:
                    case ToolStates.Aligning:
                    case ToolStates.Picking:
                    {
                        RaycastHoverInstance(mouseRay);
                        break;
                    }

                    case ToolStates.MouseDragging:
                    {
                        TransformAction action = ActionQueue.instance.current as TransformAction;

                        Vector3 newMove      = action.moveDelta;
                        float   newAngle     = action.angleDelta;
                        float   newSnapAngle = 0f;

                        if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
                        {
                            if (dragging)
                            {
                                foreach (Instance i in Action.selection)
                                {
                                    if (i is MoveableBuilding mb)
                                    {
                                        mb.Virtual = !fastMove;
                                    }
                                }
                            }
                        }
                        else
                        {
                            foreach (Instance i in Action.selection)
                            {
                                if (i is MoveableBuilding mb)
                                {
                                    mb.Virtual = fastMove;
                                }
                            }
                        }


                        if (m_leftClickTime > 0)
                        {
                            float y = action.moveDelta.y;
                            newMove   = m_startPosition + RaycastMouseLocation(mouseRay) - m_mouseStartPosition;
                            newMove.y = y;
                        }


                        if (m_rightClickTime > 0)
                        {
                            newAngle = ushort.MaxValue * 9.58738E-05f * (Input.mousePosition.x - m_mouseStartX) / Screen.width;
                            if (Event.current.control)
                            {
                                float quarterPI = Mathf.PI / 4;
                                newAngle = quarterPI * Mathf.Round(newAngle / quarterPI);
                            }
                            newAngle += m_startAngle;
                        }

                        if (snapping)
                        {
                            newMove = GetSnapDelta(newMove, newAngle, action.center, out action.autoCurve);

                            if (action.autoCurve)
                            {
                                action.segmentCurve = m_segmentGuide;
                            }
                        }
                        else
                        {
                            action.autoCurve = false;
                        }

                        if (action.moveDelta != newMove || action.angleDelta != newAngle || action.snapAngle != newSnapAngle)
                        {
                            action.moveDelta     = newMove;
                            action.angleDelta    = newAngle;
                            action.snapAngle     = newSnapAngle;
                            action.followTerrain = followTerrain;
                            m_nextAction         = ToolAction.Do;
                        }

                        UIToolOptionPanel.RefreshSnapButton();
                        break;
                    }

                    case ToolStates.Cloning:
                    {
                        if (m_rightClickTime != 0)
                        {
                            break;
                        }

                        CloneAction action = ActionQueue.instance.current as CloneAction;

                        float   y       = action.moveDelta.y;
                        Vector3 newMove = RaycastMouseLocation(mouseRay) - action.center;
                        newMove.y = y;

                        if (snapping)
                        {
                            newMove = GetSnapDelta(newMove, action.angleDelta, action.center, out bool autoCurve);
                        }

                        if (action.moveDelta != newMove)
                        {
                            action.moveDelta = newMove;
                        }

                        UIToolOptionPanel.RefreshSnapButton();
                        break;
                    }

                    case ToolStates.RightDraggingClone:
                    {
                        CloneAction action = ActionQueue.instance.current as CloneAction;

                        float newAngle = ushort.MaxValue * 9.58738E-05f * (Input.mousePosition.x - m_mouseStartX) / Screen.width;
                        if (Event.current.control)
                        {
                            float quarterPI = Mathf.PI / 4;
                            newAngle = quarterPI * Mathf.Round(newAngle / quarterPI);
                        }
                        newAngle += m_startAngle;

                        if (action.angleDelta != newAngle)
                        {
                            action.angleDelta = newAngle;
                        }

                        UIToolOptionPanel.RefreshSnapButton();
                        break;
                    }

                    case ToolStates.DrawingSelection:
                    {
                        RaycastHoverInstance(mouseRay);
                        m_marqueeInstances = GetMarqueeList(mouseRay);
                        break;
                    }
                    }
                }
            }
        }