Example #1
0
    /// <summary>
    /// 控制目标
    /// </summary>
    private void ControlTarget()
    {
        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            m_MouseDonw = true;
        }
        if (Input.GetKey(KeyCode.Mouse0))
        {
            float inputX = Input.GetAxis("Mouse X");
            float inputY = Input.GetAxis("Mouse Y");

            float x = 0;
            float y = 0;
            float z = 0;

            switch (m_SelectedAxis)
            {
            case RuntimeHandleAxis.None:
                break;

            case RuntimeHandleAxis.X:
                if (!m_LockX)
                {
                    x = m_CurrentHandle.GetTransformAxis(new Vector2(inputX, inputY), m_Target.right);
                }
                break;

            case RuntimeHandleAxis.Y:
                if (!m_LockY)
                {
                    y = m_CurrentHandle.GetTransformAxis(new Vector2(inputX, inputY), m_Target.up);
                }
                break;

            case RuntimeHandleAxis.Z:
                if (!m_LockZ)
                {
                    z = m_CurrentHandle.GetTransformAxis(new Vector2(inputX, inputY), m_Target.forward);
                }
                break;

            case RuntimeHandleAxis.XY:
                if (!m_LockX)
                {
                    x = m_CurrentHandle.GetTransformAxis(new Vector2(inputX, inputY), m_Target.right);
                }
                if (!m_LockY)
                {
                    y = m_CurrentHandle.GetTransformAxis(new Vector2(inputX, inputY), m_Target.up);
                }
                break;

            case RuntimeHandleAxis.XZ:
                if (!m_LockX)
                {
                    x = m_CurrentHandle.GetTransformAxis(new Vector2(inputX, inputY), m_Target.right);
                }
                if (!m_LockZ)
                {
                    z = m_CurrentHandle.GetTransformAxis(new Vector2(inputX, inputY), m_Target.forward);
                }
                break;

            case RuntimeHandleAxis.YZ:
                if (!m_LockY)
                {
                    y = m_CurrentHandle.GetTransformAxis(new Vector2(inputX, inputY), m_Target.up);
                }
                if (!m_LockZ)
                {
                    z = m_CurrentHandle.GetTransformAxis(new Vector2(inputX, inputY), m_Target.forward);
                }
                break;

            case RuntimeHandleAxis.XYZ:
                x = y = z = inputX;
                if (m_LockX)
                {
                    x = 0;
                }
                if (m_LockY)
                {
                    y = 0;
                }
                if (m_LockZ)
                {
                    z = 0;
                }
                break;

            default:
                break;
            }

            m_CurrentHandle.Transform(new Vector3(x, y, z) * m_ScreenScale);
        }
        if (Input.GetKeyUp(KeyCode.Mouse0))
        {
            m_MouseDonw = false;
        }
    }