コード例 #1
0
ファイル: MouseMonitor.cs プロジェクト: Geksogod/TPR
    private void LateUpdate()
    {
        RaycastHit hit;
        Ray        ray = mainCamera.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out hit))
        {
            if (hit.collider.gameObject.GetComponent <ITouchListener>() != null)
            {
                touchListener = hit.collider.gameObject.GetComponent <ITouchListener>();
                if (hit.collider.gameObject != currentGameObject)
                {
                    colliderEnter = false;
                }
                if (!colliderEnter)
                {
                    touchListener.MouseEnter();
                    currentGameObject = hit.collider.gameObject;
                    colliderEnter     = true;
                }
                if (Input.GetButtonDown("Fire1") && colliderEnter)
                {
                    touchListener.MouseDown();
                    lastChoseGameObject       = hit.collider.gameObject;
                    currentSelectedGameObject = lastChoseGameObject;
                }
                if (!Input.GetButtonDown("Fire1") && currentSelectedGameObject != null)
                {
                    currentSelectedGameObject = null;
                }
            }
            else if (colliderEnter)
            {
                colliderEnter = false;
                touchListener.MouseExit();
                touchListener             = null;
                currentGameObject         = null;
                currentSelectedGameObject = null;
            }
            else if (hit.collider == null && colliderEnter)
            {
                colliderEnter = false;
                touchListener.MouseExit();
                touchListener             = null;
                currentGameObject         = null;
                currentSelectedGameObject = null;
            }
        }
    }
コード例 #2
0
 private void CheckForColliderExit()
 {
     if (touchTarget != null)
     {
         touchTarget.MouseExit();
         lastTouchTarget = null;
         touchTarget     = null;
     }
 }