コード例 #1
0
    void Update()
    {
        if (provider == null)
        {
            return;
        }

        if (placingArea)
        {
            BoundedPlane plane;
            if (provider.GetPlane(out plane))
            {
                playArea.transform.position = plane.Center;
                playArea.transform.rotation = plane.Pose.rotation;
                float scale = Mathf.Min(1f, plane.Size.x, plane.Size.y);
                playArea.transform.localScale = Vector3.one * scale;
                playArea.gameObject.SetActive(true);

                Vector3 forword = -playArea.transform.forward;
                forword.y = 0f;
                Vector3 look = Camera.main.transform.position - playArea.transform.position;
                look.y = 0f;
                float angle = Vector3.SignedAngle(look, forword, Vector3.up);
                if (angle > 135f || angle < -135f)
                {
                    playArea.transform.Rotate(playArea.transform.up, 180f);
                }
                else if (angle > 45f)
                {
                    playArea.transform.Rotate(playArea.transform.up, -90f);
                }
                else if (angle < -45f)
                {
                    playArea.transform.Rotate(playArea.transform.up, 90f);
                }

                HelpUI.ShowPlace();

                if (provider.GetClickDown())
                {
                    placingArea = false;
                    provider.holdAttachPoint.localPosition = provider.holdAttachPoint.localPosition * scale;
                    provider.holdAttachPoint.localScale    = Vector3.one * scale;
                    //UIManager.Instance.GoBackToUI(MainUI);
                    LoadingUI.SetActive(false);
                    HelpUI.gameObject.SetActive(false);
                    playArea.SetArea();
                    provider.FinishInit();
                }
            }
            else
            {
                playArea.gameObject.SetActive(false);
                HelpUI.ShowLooking();
            }
        }
        else if (heldBook != null)
        {
            if (provider.GetClickUp())
            {
                heldBook.transform.SetParent(playArea.transform);
                heldBook.PlaceBook();
                heldBook = null;
                HelpUI.gameObject.SetActive(false);
            }
        }
        else if (currentPlacing == null)
        {
            if (currentClickable == null)
            {
#if UNITY_EDITOR || UNITY_STANDALONE
                if (provider.GetClickDown())
#else
                if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began && !EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
#endif
                {
                    RaycastHit hit;
                    if (Physics.Raycast(provider.GetClickRay(), out hit, Mathf.Infinity, (1 << LayerMask.NameToLayer("Placable")) | (1 << LayerMask.NameToLayer("UI"))))
                    {
                        if (hit.collider.gameObject.layer == LayerMask.NameToLayer("Placable"))
                        {
                            currentClickable = hit.transform.GetComponentInParent <Clickable>();

                            if (currentClickable != null)
                            {
                                currentClickable.ClickDown(hit);
                            }
                            else if (currentArea.AllowMovement)
                            {
                                currentPlacing = hit.transform.GetComponentInParent <Placable>();
                                lastPos        = currentPlacing.transform.localPosition;
                                placingDown    = true;
                            }
                        }
                    }
                }
            }
            else
            {
                if (provider.GetClickUp())
                {
                    RaycastHit hit;
                    if (Physics.Raycast(provider.GetClickRay(), out hit, Mathf.Infinity, 1 << LayerMask.NameToLayer("Placable")))
                    {
                        Clickable upClickable = hit.transform.GetComponentInParent <Clickable>();
                        if (upClickable == currentClickable)
                        {
                            currentClickable.Click(hit);
                        }
                    }
                    currentClickable.ClickUp(hit);
                    currentClickable = null;
                }
            }
        }
        else
        {
            PlaceCurrent();
            if (provider.GetClickDown())
            {
                placingDown = true;
            }
            else if (placingDown && provider.GetClickUp())
            {
                if (placed)
                {
                    if (lastPos.HasValue)
                    {
                        if (currentArea != null)
                        {
                            currentArea.MoveInArea(currentPlacing);
                        }
                    }
                    else
                    {
                        if (currentArea != null)
                        {
                            currentArea.AddToArea(currentPlacing);
                            PlayerManager.Instance.RemoveInventory(currentPlacing.Data);
                        }
                    }
                    currentPlacing = null;
                    HelpUI.gameObject.SetActive(false);
                    playArea.ShowPlacing(false);
                    if (HelpManager.Instance.CurrentStep == TutorialStep.PlaceTreat)
                    {
                        HelpManager.Instance.CompleteTutorialStep(TutorialStep.PlaceTreat);
                    }
                    else if (HelpManager.Instance.CurrentStep == TutorialStep.PlaceToy)
                    {
                        HelpManager.Instance.CompleteTutorialStep(TutorialStep.PlaceToy);
                    }
                    placingDown = false;
                    SoundManager.Instance.PlayGroup("PlaceItem");
                    if (IsNonXR)
                    {
                        GrabBook(BookController.Instance);
                    }
                }

                /*else
                 * {
                 *  /*if (lastPos.HasValue)
                 *      currentPlacing.transform.localPosition = lastPos.Value;
                 *  else*
                 *  if (currentArea != null)
                 *      currentArea.RemoveFromArea(currentPlacing);
                 *  PlayerManager.Instance.AddInventory(currentPlacing.Data);
                 *  Destroy(currentPlacing.gameObject);
                 * }*/
            }
        }

        if (currentClickable == null)
        {
#if UNITY_EDITOR || UNITY_STANDALONE
            if (provider.GetClickDown())
#else
            if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began && !EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
#endif
            {
                RaycastHit hit;
                if (Physics.Raycast(provider.GetClickRay(), out hit, Mathf.Infinity))
                {
                    if (hit.collider.gameObject.layer == LayerMask.NameToLayer("Base"))
                    {
                        BookController.Instance.ReturnBook();
                    }
                }
            }
        }
    }