コード例 #1
0
 private void FixedUpdate()
 {
     if (_heldItem != null)
     {
         _heldItem.OnDrag(_mousePositionInWorldSpace);
     }
 }
コード例 #2
0
        public void OnDrag(PointerEventData eventData)
        {
            if (draggable == null)
            {
                return;
            }

            draggable.OnDrag(eventData.delta);
        }
コード例 #3
0
ファイル: InputManager.cs プロジェクト: Chessel/GAM245-game
    // #endif

    private void CheckTouch(Touch touchInfo)
    {
        // Extract the position of that finger's touch.
        Vector2 touchPosition = touchInfo.position;

        // Convert the mouse position to world space
        Ray mouseCursorRay = my_camera.ScreenPointToRay(touchPosition);

        // Declare a RaycastHit object to recieve our results
        RaycastHit hitInfo;

        // perform the actual raycast
        if (Physics.Raycast(mouseCursorRay, out hitInfo) == true)
        {
            Collider objectWeHit = hitInfo.collider;
            Debug.Log(objectWeHit);
            if (objectWeHit.tag == "circle")
            {
                Debug.Log("we hit the circle");
                objectWeHit.SendMessage("OnClick", SendMessageOptions.DontRequireReceiver);
                objectWeHit.SendMessage("AddToPile", SendMessageOptions.DontRequireReceiver);
            }

            // extract the touch phase
            TouchPhase touchPhase = touchInfo.phase;

            switch (touchPhase)
            {
            case TouchPhase.Began:
                // Debug.Log("touch began");
                break;

            case TouchPhase.Moved:
                // search the object we hit for any script that implements IDraggable
                IDraggable draggableScript = objectWeHit.GetComponent <IDraggable>();
                // NOTE:  GetComponent returns null if no matches
                if (draggableScript != null)
                {
                    // Debug.Log("touch phase moved heard");
                    // call OnDrag() on whatever script we found
                    draggableScript.OnDrag(hitInfo.point, touchInfo.deltaPosition);
                }
                break;

            case TouchPhase.Stationary:
            {
                // Debug.Log("touch phase stationary");
                // search the object we hit for any script that implements ITappable
                ITappable tappableScript = objectWeHit.GetComponent <ITappable>();

                if (tappableScript != null)
                {
                    tappableScript.OnTap(hitInfo.point);
                }
                break;
            }

            case TouchPhase.Ended:
                // Debug.Log("Touch phase ended");
                break;
            } // ends switch
        }     // ends if RaycastHit
    } // ends CheckTouch()