Beispiel #1
0
        // Use this for initialization
        void OnEnable()
        {
            m_CameraTransform = this.transform;
            m_Parent          = this.transform.parent;

            m_TargetPos    = transform.position;
            m_Cam          = GetComponent <Camera>();
            m_Moving       = false;
            m_Debug        = false;
            m_ObjectSelect = false;
            m_Object       = null;
            m_ModuleMenu   = null;
        }
Beispiel #2
0
        void Update()
        {
            m_ScreenPoint = m_Cam.WorldToScreenPoint(Input.mousePosition);
            m_Offset      = m_ScreenPoint - m_Cam.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, hit.distance));


            //Moving objects
            if (Input.GetMouseButtonDown(0))
            {
                if (Physics.Raycast(m_Cam.ScreenPointToRay(Input.mousePosition), out hit))
                {
                    if (!(hit.transform.gameObject.GetComponent <Module.BasicModuleInfo>() && hit.transform.gameObject.GetComponent <Menu.ModuleMenu>()))
                    {
                        //if the cursor is not over a module then it has clicked empty space
                        return;
                    }
                    else if (hit.transform.gameObject.GetComponent <Module.BasicModuleInfo>() && hit.transform.gameObject.GetComponent <Menu.ModuleMenu>())
                    {
                        m_ObjectSelect = true;
                        m_Object       = hit.transform.gameObject;
                        m_ModuleMenu   = hit.transform.gameObject.GetComponent <Menu.ModuleMenu>();
                    }

                    /* Vector3 m_math = hit.transform.position - hit.point;//Vector3.Lerp(hit.transform.position, hit.point, 1f);
                     * float m_mathf = Mathf.Sqrt((m_math.x * m_math.x) + (m_math.y * m_math.y) + (m_math.z * m_math.z));
                     * m_distance = hit.distance + (m_mathf);//(hit.transform.localScale.z / 2);
                     * //print(m_mathf);*/
                }
                else
                {
                    m_ObjectSelect = false;
                    m_Object       = null;
                    m_ModuleMenu   = null;
                }
                if (enabled)
                {
                    if (m_Object != null)
                    {
                        print(m_Object.name);
                    }
                }
            }

            if (m_ModuleMenu == null)
            {
                m_MenuScroll = false;
            }
            else if (m_ModuleMenu != null)
            {
                m_MenuScroll = m_ModuleMenu.GetMouseOver();
                if (m_MenuScroll)
                {
                    m_ModuleMenu.SetShowMenu(true);
                }
            }

            //when input getmousebuttonup is released then remove the movable script;

            if (Input.GetMouseButtonDown(1))
            {
                //right click was pressed, set panning to be true, hide the cursor and lock it to the centre of the screen
                m_Panning        = true;
                Cursor.visible   = false;
                Cursor.lockState = CursorLockMode.Locked;
            }
            if (Input.GetMouseButtonUp(1))
            {
                //right click was released, panning becomes false, show the cursor and unlock it.
                m_Panning        = false;
                Cursor.visible   = true;
                Cursor.lockState = CursorLockMode.None;
            }
        }