// Update is called once per frame void Update() { switch (tapStatus) { case TAP_STATUS.UP: if (Input.touchCount > 0) { Touch touch = Input.GetTouch(0); if (touch.fingerId == 0) { Rect rect = new Rect(x, y, w, h); bool contain = rect.Contains(touch.position); if (contain) { tapStatusNext = TAP_STATUS.TAP; } else { tapStatusNext = TAP_STATUS.DOWN; } } } break; case TAP_STATUS.TAP: if (Input.touchCount == 0 || foundFingerId() == false) { tapStatusNext = TAP_STATUS.END; } else { Touch touch = Input.GetTouch(0); Rect rect = new Rect(x, y, w, h); bool contain = rect.Contains(touch.position); if (contain == false) { tapStatusNext = TAP_STATUS.CANCEL; } } break; case TAP_STATUS.DOWN: case TAP_STATUS.CANCEL: if (Input.touchCount == 0 || foundFingerId() == false) { tapStatusNext = TAP_STATUS.UP; } break; case TAP_STATUS.END: tapStatusNext = TAP_STATUS.UP; break; } while (tapStatusNext != TAP_STATUS.NONE) { tapStatus = tapStatusNext; tapStatusNext = TAP_STATUS.NONE; switch (tapStatus) { case TAP_STATUS.TAP: callbackFunction(); break; case TAP_STATUS.DOWN: break; case TAP_STATUS.END: break; case TAP_STATUS.CANCEL: break; } } }
void Update() { switch (tapStatus) { case TAP_STATUS.UP: if (Input.GetMouseButtonDown(0)) { // マウスの座標はスクリーン座標で Unityのオブジェクトはワールド座標なので変換する Vector2 position = Input.mousePosition; Vector2 screenToWorldPointPosition = Camera.main.ScreenToWorldPoint(position); // 対象のキャンバスがCanvas Scalerのため拡大率が変わっているため、取得した座標を拡大する screenToWorldPointPosition *= 1f / GameObject.Find("Canvas").transform.localScale.x; Rect rect = new Rect(x, y, w, h); bool contain = rect.Contains(screenToWorldPointPosition); // Debug.Log(screenToWorldPointPosition); if (contain) { tapStatusNext = TAP_STATUS.Began; } } break; case TAP_STATUS.Began: if (Input.GetMouseButtonUp(0)) { tapStatusNext = TAP_STATUS.Ended; } break; case TAP_STATUS.Ended: tapStatusNext = TAP_STATUS.UP; break; } while (tapStatusNext != TAP_STATUS.NONE) { tapStatus = tapStatusNext; tapStatusNext = TAP_STATUS.NONE; switch (tapStatus) { case TAP_STATUS.Began: break; case TAP_STATUS.Ended: tap = true; break; } } if (m_textController.IsCompleteDisplayText) { soul.SetActive(true); if (m_currentLine < m_scenarios.Length) { if (!m_isCallPreload) { m_commandController.PreScenario(m_scenarios[m_currentLine]); m_isCallPreload = true; } if (tap) { tap = false; RequestNextLine(); } } } else { if (tap) { tap = false; m_textController.ForceCompleteDisplayText(); } } }