Пример #1
0
    void OnCollisionEnter(Collision collision)
    {
        Debug.Log("Collide");
        if (canCollide && (collision.gameObject.GetComponent <TrolleyManager> () != null))
        {
            Debug.Log("Handing to trolley");

// TODO : replace with remove all handlers.
            if (collision.gameObject.GetComponent <TrolleyManager> ().addBook(this.gameObject.GetComponent <BookProperties> ().props))
            {
                if (currentMoveController != null)
                {
                    currentMoveController.removeHandler(bookMove, currentMoveControllerObj);
                }
                if (currentRetrieveController != null)
                {
                    currentRetrieveController.removeHandler(bookRetrieve, currentRetrieveControllerObj);
                }
                if (currentRotateController != null)
                {
                    currentRotateController.removeHandler(bookRotate, currentRotateControllerObj);
                }
                hideMenu();
                Destroy(this.gameObject);
            }
        }
    }
Пример #2
0
    // Book moves backwards or forwards along the line between controller and its original position. Aiming the controller up or down controls distance.
    public void bookRetrieve(ControlInput controller, ControlInput.ControllerDescription controllerObject, bool trigger, bool debounceTrigger, Vector3 direction, Vector3 position, GameObject avatar, bool touchpad, Vector2 touchposition)
    {
//           print ("Retrievingbook " + bookDistance + " " + direction);
        if (!debounceTrigger)
        {
            triggerCleared = true;
        }
        if (debounceTrigger && triggerCleared)
        {
            controller.removeHandler(bookRetrieve, controllerObject);
        }

        transform.position = avatar.transform.position + bookDirection * bookDistance * Mathf.Pow(2.0f, 5.0f * direction.y);
    }
Пример #3
0
    // Set the rotation of the book to match the controller's orientation.
    public void bookRotate(ControlInput controller, ControlInput.ControllerDescription controllerObject, bool trigger, bool debounceTrigger, Vector3 direction, Vector3 position, GameObject avatar, bool touchpad, Vector2 touchposition)
    {
//           print ("Rotatingbook " + bookDistance + " " + direction);
        if (!debounceTrigger)
        {
            triggerCleared = true;
        }
        if (debounceTrigger && triggerCleared)
        {
            controller.removeHandler(bookRotate, controllerObject);
            GetComponentInChildren <BoxCollider> ().enabled = true;
        }

        transform.transform.rotation = controllerObject.controllerObject.transform.rotation;
    }
Пример #4
0
    public void bookScale(ControlInput controller, ControlInput.ControllerDescription controllerObject, bool trigger, bool debounceTrigger, Vector3 direction, Vector3 position, GameObject avatar, bool touchpad, Vector2 touchposition)
    {
        if (!debounceTrigger)
        {
            triggerCleared = true;
        }
        if (debounceTrigger && triggerCleared)
        {
            controller.removeHandler(bookScale, controllerObject);
        }

        float s = Mathf.Abs(5.0f * direction.y);

        transform.localScale = new Vector3(s, s, s);
    }
Пример #5
0
    // Move the book at a constant distance from the controller, and still facing the controller.
    public void bookMove(ControlInput controller, ControlInput.ControllerDescription controllerObject, bool trigger, bool debounceTrigger, Vector3 direction, Vector3 position, GameObject avatar, bool touchpad, Vector2 touchposition)
    {
        //  print ("Movingbook " + bookDistance + " " + direction);
        if (!debounceTrigger)
        {
            triggerCleared = true;
        }
        if (debounceTrigger && triggerCleared)
        {
            currentMoveController = null;
            controller.removeHandler(bookMove, controllerObject);
            canCollide = true;
            GetComponentInChildren <BoxCollider> ().enabled = true;
        }

        transform.position = position + bookDistance * direction;
        transform.up       = Vector3.up;
        transform.forward  = direction;
    }
Пример #6
0
    // deprecated. Use the touchpad to control book size and position. Turned out to be
    // awkward to control.
    public void bookManipulate(ControlInput controller, ControlInput.ControllerDescription controllerObject, bool trigger, bool debounceTrigger, Vector3 direction, Vector3 position, GameObject avatar, bool touchpad, Vector2 touchposition)
    {
//           print ("BM");
        if (!debounceTrigger)
        {
            triggerCleared = true;
        }
        if (debounceTrigger && triggerCleared)
        {
            controller.removeHandler(bookManipulate, controllerObject);
        }

        //transform.forward = -direction;
        float scale  = Mathf.Pow(6.0f, touchposition.x);
        float offset = 3.0f * touchposition.y;

        gameObject.transform.Find("BookShape").localScale    = new Vector3(scale, scale, scale);
        gameObject.transform.Find("BookShape").localPosition = new Vector3(0, 0, offset);
    }
Пример #7
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);
        }
    }
Пример #8
0
 override public void handleUnfocus(ControlInput controller, ControlInput.ControllerDescription controllerObject)
 {
     Debug.Log("No touch");
     controller.removeHandler(checkScroll, controllerObject);
 }