[SerializeField] bool unityRemote = false; // テスト用 UnityRemoteで動作確認するときはInspecter上でtrueにする public override void InstallBindings() { // 携帯端末だったらタッチ操作 if (true == PlatformInfo.IsMobile() || true == unityRemote) { Debug.Log("Bind TouchInputProvider as IInputProvider"); Container.Bind <IInputProvider>().To <TouchInputProvider>().AsCached(); Container.Bind <TouchOperation>().FromNewComponentOnNewGameObject().AsCached(); } // そうでなければマウス+キーボード操作 else { Debug.Log("Bind PCInputProvider as IInputProvider"); Container.Bind <IInputProvider>().To <PCInputProvider>().AsCached(); Container.Bind <MouseOperation>().FromNewComponentOnNewGameObject().AsCached(); Container.Bind <KeyOperation>().FromNewComponentOnNewGameObject().AsCached(); } // 入力受け付けクラスのBind 参照されないのでNonLazyで生成 Container.Bind <InputPresenter>().AsSingle().NonLazy(); }
// Update is called once per frame void Update() { // タッチ情報を保持しておく マウスの左クリックもタッチ情報に変換 if (PlatformInfo.IsMobile()) { // タッチ情報をそのまま保持(最大でボタン数まで) TouchCount = Input.touchCount; if (CommonSettings.ButtonNum < TouchCount) { Debug.Log("Input.touchCount <- too many counts..."); TouchCount = CommonSettings.ButtonNum; } for (int count = 0; count < TouchCount; count++) { touchInfo[count] = Input.GetTouch(count); // 範囲外だったら離され扱い if (!touchRect.Contains(touchInfo[count].position)) { touchInfo[count].phase = TouchPhase.Ended; } } } else { TouchCount = 0; if (Input.GetMouseButtonDown(0)) { // 左クリックされたら位置を確認し、エリア内だったら情報保持 if (touchRect.Contains(Input.mousePosition)) { Debug.Log(Input.mousePosition); // 情報保持 TouchCount = 1; touchInfo[0].position = Input.mousePosition; touchInfo[0].phase = TouchPhase.Began; } } if (Input.GetMouseButton(0)) { TouchCount = 1; touchInfo[0].position = Input.mousePosition; // 左クリックされていたら位置を確認 if (touchRect.Contains(Input.mousePosition)) { // エリア内だったら移動情報保持 TouchCount = 1; touchInfo[0].position = Input.mousePosition; touchInfo[0].phase = TouchPhase.Moved; } else { // エリア外だったら離され情報を保持 touchInfo[0].phase = TouchPhase.Ended; } } if (Input.GetMouseButtonUp(0)) { // 離された情報を保持 TouchCount = 1; touchInfo[0].position = Input.mousePosition; touchInfo[0].phase = TouchPhase.Ended; } } }