// 창 좌측의 인물 버튼 클릭
    public void OnClickCharacterButton()
    {
        conState = CLICK_STATE.CHARACTER;

        information.sprite = deactivatedSprite;
        character.sprite   = activatedSprite;
    }
    // 창 좌측의 문서 버튼 클릭
    public void OnClickInformationButton()
    {
        if (character == null)
        {
            information = transform.Find("InformationButton").GetComponent <Image>();
            character   = transform.Find("CharacterButton").GetComponent <Image>();
        }

        conState = CLICK_STATE.INFORMATION;

        information.sprite = activatedSprite;
        character.sprite   = deactivatedSprite;
    }
Ejemplo n.º 3
0
        private void Start()
        {
            pointerEventData = new PointerEventData(EventSystem.current);
            raycastResult    = new List <RaycastResult>();

            isLastClick = false;
            clickState  = CLICK_STATE.NONE;

            if (targetCamera == null)
            {
                targetCamera = Camera.main;
            }
        }
Ejemplo n.º 4
0
        void Update()
        {
            isPressUp = isPressDown = false;

            if ((leapProvider == null) ||
                (leapProvider.CurrentFixedFrame.Hands.Count == 0))
            {
                isLastClick = false;
                clickState  = CLICK_STATE.NONE;
                return;
            }

            Hand hand = leapProvider.CurrentFixedFrame.Hands[0];

            // 中指の根元の座標
            Finger  ringFinger = hand.Fingers[(int)Finger.FingerType.TYPE_RING];
            Vector3 fpos       = ringFinger.Bone(Bone.BoneType.TYPE_METACARPAL).NextJoint.ToVector3();
            // yzのベクトルを利用
            //// 第1, 3象限は、yとzのベクトルの長さ
            //// 第2, 4象限は、y+zの値
            Vector3 yz = fpos;

            yz.x  = 0f;
            yz.y -= visibleUnder;

            if ((yz.y >= 0) && (yz.z >= 0))
            {
                fpos.y = yz.magnitude;
            }
            else if ((yz.y < 0) && (yz.z < 0))
            {
                fpos.y = -yz.magnitude;
            }
            else
            {
                fpos.y = yz.y + yz.z;
            }

            fpos.z = 0f;
            fpos   = fpos * moveRate;
            if (clickState == CLICK_STATE.NONE)
            {
                // 先にカーソルが無効だったら、今回の座標にする
                viewportPosition = fpos;
            }
            else
            {
                // 前回も有効だった時は平均化
                viewportPosition = Vector3.Lerp(viewportPosition, fpos, flatRate);
            }

            // 人差し指と薬指の高さの差
            Bone    indexBone  = hand.Fingers[(int)Finger.FingerType.TYPE_INDEX].Bone(Bone.BoneType.TYPE_DISTAL);
            Vector3 indexPos   = indexBone.NextJoint.ToVector3();
            Vector3 ringPos    = ringFinger.Bone(Bone.BoneType.TYPE_DISTAL).NextJoint.ToVector3();
            float   clickDelta = indexPos.y - ringPos.y;

            // スクリーン座標に変換
            if (targetCamera != null)
            {
                screenPosition = targetCamera.ViewportToScreenPoint(viewportPosition);
            }

            // 手のバンク傾きが一定量を越えているか、ビューの外の時はクリックしない
            bool canClick = Mathf.Abs(hand.Rotation.z) < bankLimit;

            canClick &= ((fpos.x >= viewportClickLimit) && (fpos.x < 1f - viewportClickLimit));
            canClick &= ((fpos.y >= viewportClickLimit) && (fpos.y < 1f - viewportClickLimit));
            if (!canClick)
            {
                isPressUp   = isPress;
                isLastClick = false;
                clickState  = CLICK_STATE.STANDBY;
                return;
            }

            // クリックしている
            if (clickDelta < -clickThreshold)
            {
                if ((clickState == CLICK_STATE.NONE) ||
                    (clickState == CLICK_STATE.STANDBY))
                {
                    clickState = CLICK_STATE.WAIT_FIRSTFRAME;
                }
                else
                {
                    clickState = CLICK_STATE.CLICK;

                    // 今回、初クリック
                    if (!isLastClick)
                    {
                        isPressDown = true;

                        // クリック場所のUIを調査
                        raycastResult.Clear();
                        pointerEventData.position = screenPosition;
                        EventSystem.current.RaycastAll(pointerEventData, raycastResult);
                        for (int i = 0; i < raycastResult.Count; i++)
                        {
                            Button btn = raycastResult[i].gameObject.GetComponent <Button>();
                            if (btn == null)
                            {
                                btn = raycastResult[i].gameObject.GetComponentInChildren <Button>();
                            }
                            if (btn != null)
                            {
                                btn.onClick.Invoke();
                                break;
                            }
                        }
                    }

                    isLastClick = true;
                }
            }
            // クリックしてない
            else
            {
                clickState  = CLICK_STATE.STANDBY;
                isLastClick = false;
            }
        }