// Update is called once per frame
    void Update()
    {
        if (!bookIsOpen)
        {
            if (Input.GetMouseButtonDown(0))
            {
                RaycastHit hit;
                Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
                if (Physics.Raycast(ray, out hit, raycastDistance))
                {
                    if (hit.transform.parent != null && hit.transform.parent.GetComponent <PBook> () != null)
                    {
                        activePowerBook = hit.transform.parent.GetComponent <PBook> ();
                        activePowerBookOriginalLayer = activePowerBook.gameObject.layer;
                        SetLayer(activePowerBook.gameObject, LayerMask.NameToLayer(overlayLayer));
                        BoxCollider bookCollider = (BoxCollider)hit.collider;
                        activePowerBookOriginalPos         = hit.transform.position;
                        activePowerBookOriginalRot         = hit.transform.rotation;
                        activePowerBook.transform.position = new Vector3((bookCollider.size.y / 2) - 0.005f, 0, -bookCollider.size.z / 2);
                        activePowerBook.transform.rotation = Quaternion.Euler(perspectiveAngle, 0, 0);
                        overlayCam.transform.position      = new Vector3(0, ((bookCollider.size.z * 1.4f) - (bookCollider.size.y / 2)) - perspectiveAngle * 0.003f, -perspectiveAngle * 0.001f);
                        overlayCam.gameObject.SetActive(true);
                        if (autoOpenBook)
                        {
                            activePowerBook.OpenBook();
                        }
                        bookIsOpen = true;

                        foreach (GameObject go in disabledGameObjectsWhileReading)
                        {
                            go.SetActive(false);
                        }
                    }
                }
            }
        }
        else
        {
            if (Input.GetKey(openCloseKey))
            {
                if (activePowerBook.GetBookState() == PBook.BookState.CLOSED)
                {
                    activePowerBook.OpenBook();
                }
                else if (activePowerBook.GetBookState() == PBook.BookState.OPEN)
                {
                    CloseOverlay();
                }
            }
            if (Input.GetKey(nextPageKey))
            {
                activePowerBook.NextPage();
            }
            if (Input.GetKey(prevPageKey))
            {
                activePowerBook.PrevPage();
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (camWaypointIndex == 0 && rotateAround)
        {
            mainCam.transform.RotateAround(Vector3.zero, Vector3.up, 10 * Time.deltaTime);
        }

        if (camWaypointIndex == 2 || camWaypointIndex == 4)
        {
            if (overlayPowerBook != null && overlayPowerBook.GetBookState() == PBook.BookState.CLOSED)
            {
                if (camWaypointIndex == 2)
                {
                    stepTexts [camWaypointIndex].SetActive(true);
                    overlayPowerBook.transform.position = overlayBookOriginalPos;
                    overlayPowerBook.transform.rotation = overlayBookOriginalRot;
                    overlayCam.gameObject.SetActive(false);
                }
                if (camWaypointIndex == 4)
                {
                    stepTexts [camWaypointIndex].SetActive(true);
                }
                exampleUIController.gameObject.SetActive(false);
                exampleUIController.pBook = null;
                overlayPowerBook          = null;
            }

            if (Input.GetMouseButtonDown(0) && overlayPowerBook == null)
            {
                RaycastHit hit;
                Ray        ray = mainCam.ScreenPointToRay(Input.mousePosition);
                if (Physics.Raycast(ray, out hit))
                {
                    if (hit.transform.parent.GetComponent <PBook> () != null)
                    {
                        overlayPowerBook = hit.transform.parent.GetComponent <PBook> ();
                        if (camWaypointIndex == 2)
                        {
                            BoxCollider bookCollider = (BoxCollider)hit.collider;
                            overlayBookOriginalPos = hit.transform.position;
                            overlayBookOriginalRot = hit.transform.rotation;
                            overlayPowerBook.transform.position = new Vector3((bookCollider.size.y / 2) - 0.005f, 0, 9.875f);
                            overlayPowerBook.transform.rotation = Quaternion.identity;
                            overlayCam.gameObject.SetActive(true);
                        }
                        overlayPowerBook.OpenBook();
                        exampleUIController.gameObject.SetActive(true);
                        exampleUIController.pBook = overlayPowerBook;
                        stepTexts [camWaypointIndex].SetActive(false);
                    }
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            NextWaypoint();
        }
    }
    void Update()
    {
        if (openCloseKey != KeyCode.None && Input.GetKeyDown(openCloseKey))
        {
            if (pBook.GetBookState() == PBook.BookState.CLOSED)
            {
                pBook.OpenBook();
            }
            if (pBook.GetBookState() == PBook.BookState.OPEN)
            {
                pBook.CloseBook();
            }
        }

        if (nextPageKey != KeyCode.None && Input.GetKeyDown(nextPageKey))
        {
            pBook.NextPage();
        }

        if (prevPageKey != KeyCode.None && Input.GetKeyDown(prevPageKey))
        {
            pBook.PrevPage();
        }

        if (gotoLastPageKey != KeyCode.None && Input.GetKeyDown(gotoLastPageKey))
        {
            pBook.GoToLastPage(gotoSpeed);
        }

        if (gotoFirstPageKey != KeyCode.None && Input.GetKeyDown(gotoFirstPageKey))
        {
            pBook.GoToFirstPage(gotoSpeed);
        }

        if (jumpToLastPageKey != KeyCode.None && Input.GetKeyDown(jumpToLastPageKey))
        {
            pBook.JumpToLastPage(playSoundOnJump);
        }

        if (gotoFirstPageKey != KeyCode.None && Input.GetKeyDown(jumpToFirstPageKey))
        {
            pBook.JumpToFirstPage(playSoundOnJump);
        }
    }
    // Update is called once per frame
    void Update()
    {
        RaycastHit hit;

        pointer.color = Color.white;
        if (Physics.Raycast(camTr.position + (camTr.forward * raycastStartDistance), camTr.forward, out hit, raycastDistance, bookLayer.value))
        {
            if ((hit.transform.parent != null && hit.transform.parent.GetComponent <PBook> () != null) || (hit.transform.parent.parent != null && hit.transform.parent.parent.GetComponent <PBook> () != null))
            {
                pointer.color = Color.red;
            }
        }

        if (Input.GetKeyDown(openCloseBookKey) && activePowerBook == null)
        {
            if (Physics.Raycast(camTr.position + (camTr.forward * raycastStartDistance), camTr.forward, out hit, raycastDistance, bookLayer.value))
            {
                if (hit.transform.parent != null && hit.transform.parent.GetComponent <PBook> () != null)
                {
                    activePowerBook = hit.transform.parent.GetComponent <PBook> ();
                    if (activePowerBook.GetBookState() == PBook.BookState.CLOSED)
                    {
                        activePowerBook.OpenBook();
                    }
                    activePowerBook = null;
                }
            }

            if (Physics.Raycast(camTr.position + (camTr.forward * raycastStartDistance), camTr.forward, out hit, raycastDistance, bookLayer.value))
            {
                if (hit.transform.parent.parent != null && hit.transform.parent.parent.GetComponent <PBook> () != null)
                {
                    activePowerBook = hit.transform.parent.parent.GetComponent <PBook> ();
                    if (activePowerBook.GetBookState() == PBook.BookState.OPEN)
                    {
                        activePowerBook.CloseBook();
                    }
                    activePowerBook = null;
                }
            }
        }

        if (Input.GetKeyDown(prevPageKey) && activePowerBook == null)
        {
            if (Physics.Raycast(camTr.position + (camTr.forward * raycastStartDistance), camTr.forward, out hit, raycastDistance, bookLayer.value))
            {
                if (hit.transform.parent.parent != null && hit.transform.parent.parent.GetComponent <PBook> () != null)
                {
                    activePowerBook = hit.transform.parent.parent.GetComponent <PBook> ();
                    if (activePowerBook.GetBookState() == PBook.BookState.OPEN)
                    {
                        activePowerBook.PrevPage();
                    }
                    activePowerBook = null;
                }
            }
        }

        if (Input.GetKeyDown(nextPageKey) && activePowerBook == null)
        {
            if (Physics.Raycast(camTr.position + camTr.forward * raycastStartDistance, camTr.forward, out hit, raycastDistance, bookLayer.value))
            {
                if (hit.transform.parent.parent != null && hit.transform.parent.parent.GetComponent <PBook> () != null)
                {
                    activePowerBook = hit.transform.parent.parent.GetComponent <PBook> ();
                    if (activePowerBook.GetBookState() == PBook.BookState.OPEN)
                    {
                        activePowerBook.NextPage();
                    }
                    activePowerBook = null;
                }
            }
        }
    }
Exemple #5
0
    // Update is called once per frame
    void Update()
    {
        if (pBook != null)
        {
            RaycastHit hit;
            Ray        ray = cam.ScreenPointToRay(Input.mousePosition);

            // Left Mouse Btn (Open Book / Next Page / Prev Page)
            if (Input.GetMouseButtonDown(0) && dragstate == DragState.NODRAG)
            {
                if (Physics.Raycast(ray, out hit, raycastDistance, bookLayer))
                {
                    // Open Book Start
                    if (hit.transform.parent != null && hit.transform.parent.gameObject == pBook.gameObject)
                    {
                        dragStartPosition = hit.point;
                        if (pBook.GetBookState() == PBook.BookState.CLOSED)
                        {
                            float distance = hit.transform.InverseTransformPoint(hit.point).x * 2.25f;
                            distance           = Mathf.Clamp(distance, minDragDistance, distance);
                            dragTargetPosition = dragStartPosition - pBook.transform.right * distance;
                            maxDragDistance    = Mathf.Abs((Input.mousePosition - cam.WorldToScreenPoint(dragTargetPosition)).x);
                            dragstate          = DragState.OPENDRAG;
                        }
                    }
                    // Next Page Start
                    if (hit.transform.parent.parent != null && hit.transform.parent.parent.gameObject == pBook.gameObject && hit.transform.name == "PageCenterRight" && !pBook.IsLastPage())
                    {
                        dragStartPosition = hit.point;
                        if (pBook.GetBookState() == PBook.BookState.OPEN)
                        {
                            float distance = Mathf.Abs(hit.transform.parent.parent.InverseTransformPoint(hit.point).x * 2.5f);
                            distance           = Mathf.Clamp(distance, minDragDistance, distance);
                            dragTargetPosition = dragStartPosition - pBook.transform.right * distance;
                            maxDragDistance    = Mathf.Abs((Input.mousePosition - cam.WorldToScreenPoint(dragTargetPosition)).x);
                            dragstate          = DragState.NEXTDRAG;
                        }
                    }

                    // Prev Page Start
                    if (hit.transform.parent.parent != null && hit.transform.parent.parent.gameObject == pBook.gameObject && hit.transform.name == "PageCenterLeft" && !pBook.IsFirstPage())
                    {
                        dragStartPosition = hit.point;
                        if (pBook.GetBookState() == PBook.BookState.OPEN)
                        {
                            float distance = Mathf.Abs(hit.transform.parent.parent.InverseTransformPoint(hit.point).x * 1.9f);
                            distance           = Mathf.Clamp(distance, minDragDistance, distance);
                            dragTargetPosition = dragStartPosition + pBook.transform.right * distance;
                            maxDragDistance    = Mathf.Abs((Input.mousePosition - cam.WorldToScreenPoint(dragTargetPosition)).x);
                            dragstate          = DragState.PREVDRAG;
                        }
                    }
                }
            }

            // Right Mouse Btn (Close Book)
            if (Input.GetMouseButtonDown(1) && dragstate == DragState.NODRAG)
            {
                if (Physics.Raycast(ray, out hit, raycastDistance, bookLayer))
                {
                    // Close Book Start
                    if (hit.transform.parent.parent != null && hit.transform.parent.parent.gameObject == pBook.gameObject && hit.transform.name == "PageCenterLeft")
                    {
                        dragStartPosition = hit.point;
                        if (pBook.GetBookState() == PBook.BookState.OPEN)
                        {
                            float distance = Mathf.Abs(hit.transform.parent.parent.InverseTransformPoint(hit.point).x * 1.9f);
                            distance           = Mathf.Clamp(distance, minDragDistance, distance);
                            dragTargetPosition = dragStartPosition + pBook.transform.right * distance;
                            maxDragDistance    = Mathf.Abs((Input.mousePosition - cam.WorldToScreenPoint(dragTargetPosition)).x);
                            dragstate          = DragState.CLOSEDRAG;
                        }
                    }
                }
            }

            // Open Book Drag / Next Page Drag / Prev Page Drag
            if (Input.GetMouseButton(0) && (dragstate == DragState.OPENDRAG || dragstate == DragState.NEXTDRAG || dragstate == DragState.PREVDRAG))
            {
                float absDistance   = Mathf.Abs((Input.mousePosition - cam.WorldToScreenPoint(dragStartPosition)).x);
                float inputDistance = Mathf.Abs((Input.mousePosition - cam.WorldToScreenPoint(dragTargetPosition)).x);
                dragValue = 1 - (1 / maxDragDistance * inputDistance);
                dragValue = Mathf.Clamp(dragValue, 0, 1);
                if (absDistance <= maxDragDistance && dragstate == DragState.OPENDRAG)
                {
                    pBook.DragOpenBook(dragValue);
                }
                if (absDistance <= maxDragDistance && dragstate == DragState.NEXTDRAG)
                {
                    pBook.DragNextPage(dragValue);
                }
                if (absDistance <= maxDragDistance && dragstate == DragState.PREVDRAG)
                {
                    pBook.DragPrevPage(dragValue);
                }
            }

            // Close Book Drag
            if (Input.GetMouseButton(1) && dragstate == DragState.CLOSEDRAG)
            {
                float absDistance   = Mathf.Abs((Input.mousePosition - cam.WorldToScreenPoint(dragStartPosition)).x);
                float inputDistance = Mathf.Abs((Input.mousePosition - cam.WorldToScreenPoint(dragTargetPosition)).x);
                dragValue = 1 - (1 / maxDragDistance * inputDistance);
                dragValue = Mathf.Clamp(dragValue, 0, 1);
                if (absDistance <= maxDragDistance)
                {
                    pBook.DragCloseBook(dragValue);
                }
            }

            // Cancel Drag
            if (Input.GetMouseButtonUp(0) || Input.GetMouseButtonUp(1))
            {
                CancelDrag();
            }
            if (!Input.GetMouseButton(0) && !Input.GetMouseButton(1) && dragstate != DragState.NODRAG)
            {
                CancelDrag();
            }
        }
    }