示例#1
0
        void Update()
        {
            RaycastHit    hit;
            Button        button = null;
            GamePiece     piece  = null;
            BoardPosition pos    = null;

            // do a forward raycast to see if we hit a selectable object
            bool hitSomething = Physics.Raycast(transform.position, transform.forward, out hit, 50f);

            if (hitSomething)
            {
                button = hit.collider.GetComponent <Button>();
                piece  = hit.collider.GetComponent <GamePiece>();
                pos    = hit.collider.GetComponent <BoardPosition>();
            }

            if (m_currentButton != button)
            {
                if (m_eventSystem != null)
                {
                    m_eventSystem.SetSelectedGameObject(null);
                }
                m_currentButton = button;
                if (m_currentButton != null)
                {
                    m_currentButton.Select();
                }
            }

            if (m_currentPiece != piece)
            {
                if (m_currentPiece != null)
                {
                    m_gameController.StoppedLookingAtPiece();
                }
                m_currentPiece = piece;
                if (m_currentPiece != null)
                {
                    m_gameController.StartedLookingAtPiece(m_currentPiece);
                }
            }

            if (m_boardPosition != pos)
            {
                m_boardPosition = pos;
                if (m_boardPosition != null)
                {
                    m_gameController.StartedLookingAtPosition(m_boardPosition);
                }
            }

            // clear the potential move if they gaze off the board
            if (hit.collider == m_gazeTracker)
            {
                m_gameController.ClearProposedMove();
            }

            // moves the camera with the mouse - very useful for debugging in to 2D mode.
            if (Input.GetButton("Fire2"))
            {
                var v = Input.GetAxis("Mouse Y");
                var h = Input.GetAxis("Mouse X");
                transform.rotation *= Quaternion.AngleAxis(h, Vector3.up);
                transform.rotation *= Quaternion.AngleAxis(-v, Vector3.right);
                Vector3 eulers = transform.eulerAngles;
                eulers.z = 0;
                transform.eulerAngles = eulers;
            }
        }