Exemplo n.º 1
0
 // deprecated - to be removed.
 public void positionBook(ControlInput controller, ControlInput.ControllerDescription controllerObject, GameObject button, GameObject avatar, bool initialize = false)
 {
     if (!initialize)
     {
         triggerCleared = false;
         controller.addHandler(bookManipulate, controllerObject);
     }
 }
Exemplo n.º 2
0
 public void scaleBook(ControlInput controller, ControlInput.ControllerDescription controllerObject, GameObject button, GameObject avatar, bool initialize = false)
 {
     if (!initialize)
     {
         triggerCleared = false;
         controller.addHandler(bookScale, controllerObject, true);
     }
 }
Exemplo n.º 3
0
 // Rotate the book to get the best reading angle.
 public void rotateBook(ControlInput controller, ControlInput.ControllerDescription controllerObject, GameObject button, GameObject avatar, bool initialize = false)
 {
     if (!initialize)
     {
         triggerCleared = false;
         GetComponentInChildren <BoxCollider> ().enabled = false;
         controller.addHandler(bookRotate, controllerObject, true);
     }
 }
Exemplo n.º 4
0
 // Move the book closer.
 public void retrieveBook(ControlInput controller, ControlInput.ControllerDescription controllerObject, GameObject button, GameObject avatar, bool initialize = false)
 {
     if (!initialize)
     {
         triggerCleared = false;
         bookDirection  = transform.position - controller.avatar.transform.position;
         bookDistance   = bookDirection.magnitude;
         bookDirection  = Vector3.Normalize(bookDirection);
         controller.addHandler(bookRetrieve, controllerObject, true);
     }
 }
Exemplo n.º 5
0
    // Activate the book positioning process.
    public void moveBook(ControlInput controller, ControlInput.ControllerDescription controllerObject, GameObject button, GameObject avatar, bool initialize = false)
    {
        if (!initialize)
        {
            triggerCleared = false;
            bookDistance   = (transform.position - controllerObject.controllerObject.transform.position).magnitude;

            // Disable collider while moving so that it doesn't interfere with other objects.
            GetComponentInChildren <BoxCollider> ().enabled = false;

            controller.addHandler(bookMove, controllerObject, true);
        }
    }
Exemplo n.º 6
0
    // Check for interactions with the menu, and call any handlers as required.
    virtual public void handleControllerInput(ControlInput controller, ControlInput.ControllerDescription controllerObject, bool trigger, bool debounceTrigger, Vector3 direction, Vector3 position, GameObject avatar, bool touchpad, Vector2 touchposition)
    {
        if (menu == null)
        {
            initializeMenu();
        }

        if (!activeButtons.ContainsKey(controllerObject))
        {
            activeButtons[controllerObject] = null;
        }

        // Ray cast in the direction of the controller, and trigger any button affected.
        MenuItem whichButton = null;

        RaycastHit hit;

        if (Physics.Raycast(position, direction, out hit))
        {
//             print ("Hit " +  hit.point + " " + hit.transform.gameObject.name + " " + hit.collider.name);

            // Find the button. Loop efficiency could be improved with a hash table,
            // or tagging the hit object with some menu information. Not an issue until
            // menus become very big though.
            foreach (MenuItem menuOption in menuItems)
            {
                if (menuOption.button.transform == hit.collider.transform)
                {
                    // If a button is touched, then provide feedback to the user.
                    whichButton = menuOption;

                    if (menuOption.pointerOverHandler != null)
                    {
                        menuOption.pointerOverHandler(menuOption, controller, controllerObject, avatar);
                    }
                    break;
                }
            }
        }

        // If the trigger is pressed and released, then activate the button by calling its handler.
        if (debounceTrigger)
        {
            if ((activeButtons[controllerObject] == null) && (whichButton != null))
            {
                activeButtons[controllerObject] = whichButton;
                controller.addHandler(handleControllerInput, controllerObject);
            }
        }

        if (!trigger)
        {
            // trigger not pressed.
            if (activeButtons[controllerObject] != null)
            {
//       Debug.Log ("PressRelease " + (activeButton == whichButton));
                if (whichButton == activeButtons[controllerObject])
                {
                    // release while still over the same button.
                    activeButtons[controllerObject].handler(controller, controllerObject, activeButtons[controllerObject].button, avatar);
                }
                else
                { // a button was pressed, but we're not on it when releasing.
                  // otherwise, release somewhere else. Maybe this is a scroll?
                    if (activeButtons[controllerObject].scrollHandler != null)
                    {
                        Vector3 toButton = activeButtons[controllerObject].button.transform.position - position;
                        Debug.Log(toButton + " " + direction);
                        // scroll is component of direction perpendicular vector to button.
                        Vector3 perp   = toButton.magnitude * (toButton.normalized - Vector3.Project(direction.normalized, toButton.normalized));
                        Vector2 scroll = new Vector2(-Vector3.Dot(perp, controllerObject.controllerObject.transform.right), -Vector3.Dot(perp, controllerObject.controllerObject.transform.up));
//             Debug.Log ("Scroll " + 100.0f * scroll);
                        activeButtons[controllerObject].scrollHandler(activeButtons[controllerObject], scroll);
                    }
                }
            }
            activeButtons[controllerObject] = null;
            controller.removeHandler(handleControllerInput, controllerObject);
        }
    }
Exemplo n.º 7
0
 override public void handleFocus(ControlInput controller, ControlInput.ControllerDescription controllerObject)
 {
     Debug.Log("Have touch");
     controller.addHandler(checkScroll, controllerObject, false);
 }