void TouchManagerUpdate() { _touchManager.update(); _touchManager.GetTouch(); }
private void Update() { _touchManager.update(); // タッチ取得 TouchManager touch_state = this._touchManager.GetTouch(); //タッチされているとき if (touch_state.TouchFlag) { _touchPositionX = (int)Math.Round(touch_state.TouchPosition.x, MidpointRounding.AwayFromZero); _touchPositionZ = (int)Math.Round(touch_state.TouchPosition.z - 0.2f, MidpointRounding.AwayFromZero); // タッチした瞬間の処理 if (touch_state.TouchPhase == TouchPhase.Began) { //自分のターンの時 if (_myTurn) { CreateGeister(touch_state); _boardManager.SetPixelCanChoice(_originalGeister.transform); } //ガイスターセットの時 if (_setGeister) { if (_boardManager.ToIdx(_touchPositionX, _touchPositionZ) > 0 && _boardManager.ToIdx(_touchPositionX, _touchPositionZ) < 5 || _boardManager.ToIdx(_touchPositionX, _touchPositionZ) > 6 && _boardManager.ToIdx(_touchPositionX, _touchPositionZ) < 11) { } else { return; } if (_setCount < 4) { if (_boardManager.GetPixel(_touchPositionX, _touchPositionZ).GetComponent <Pixel>().SetGeisterBlue("Player")) { _setCount++; } if (_setCount == 4) { _setText.text = "赤のガイスターを配置してください"; _setText.color = new Color(255, 0, 0); } } else if (_setCount < 8) { if (_boardManager.GetPixel(_touchPositionX, _touchPositionZ).GetComponent <Pixel>().SetGeisterRed("Player")) { _setCount++; } if (_setCount == 8) { _setText.text = ""; _setGeister = false; _myTurn = true; //_boardManager.SetPixelChoice(); } } } } if (_chachedGeister != null) { _chachedGeister.transform.position = new Vector3(touch_state.TouchPosition.x, _chachedGeister.transform.position.y, touch_state.TouchPosition.z); int deltaPosX = (int)Mathf.Round(_chachedGeister.transform.position.x - _originalGeister.transform.position.x); int deltaPosZ = (int)Mathf.Round(_chachedGeister.transform.position.z - _originalGeister.transform.position.z); //離したら if (touch_state.TouchPhase == TouchPhase.Ended) { EndedTouch(deltaPosX, deltaPosZ); } } } }
void Update() { //タッチ情報更新 _touchManager.update(); _touchManager.GetTouch(); if (_touchManager._touch_flag) { if (Application.isEditor) { // 座標系変換 Vector3 pos = default; if (old_phase._touch_phase == TouchPhase.Began) { // マウスのワールド座標までパーティクルを移動し、パーティクルエフェクトを1つ生成する pos = _camera.ScreenToWorldPoint(Input.mousePosition + _camera.transform.forward * 10); } else if (_touchManager._touch_phase == TouchPhase.Moved) { float distance = 100; // 飛ばす&表示するRayの長さ float duration = 3; // 表示期間(秒) Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); Debug.DrawRay(ray.origin, ray.direction * distance, Color.red, duration, false); RaycastHit hit = new RaycastHit(); //ヒットボックスの存在するオブジェクトにRayが衝突したときの処理 if (Physics.Raycast(ray, out hit, distance)) { isMove = true; bombBase = hit.collider.gameObject.GetComponent <BombBase>(); } //クリックし続けてるなら if (isMove) { //pos :unity.transform.positionの座標 //Input.mousePosition:1920x1080のクリックした座標 pos = _camera.ScreenToWorldPoint(Input.mousePosition + _camera.transform.forward * 10); if (_touchManager._touch_position.x < gameBottomLeft || _touchManager._touch_position.x > gameTopRight) { Debug.Log("範囲外 : " + "," + _touchManager._touch_position + "," + pos); pos = new Vector3(oldPos.x, pos.y, pos.z); //return; } if (_touchManager._touch_position.y > gameTop || _touchManager._touch_position.y < gameButtom) { Debug.Log("範囲外 : " + "," + _touchManager._touch_position + "," + pos); pos = new Vector3(pos.x, oldPos.y, pos.z); // return; } bombBase.transform.position = pos; } } else if (_touchManager._touch_phase == TouchPhase.Ended) { isMove = false; } oldPos = pos; } else { // 座標系変換 Vector3 vPoint = _touchManager._touch_position; Vector3 pos = default; //クリックした瞬間 if (_touchManager._touch_phase == TouchPhase.Began) { // タップのワールド座標までパーティクルを移動し、パーティクルエフェクトを1つ生成する pos = _camera.ScreenToWorldPoint(vPoint + _camera.transform.forward * 10); } //クリック長押し中(クリックした瞬間の次フレームから離すまでの間) else if (_touchManager._touch_phase == TouchPhase.Moved) { float distance = 100; // 飛ばす&表示するRayの長さ Ray ray = Camera.main.ScreenPointToRay(vPoint); RaycastHit hit = new RaycastHit(); //ヒットボックス(HitBox3Dのみ、2Dには対応してないので別の書き方をする)の存在するオブジェクトにRayが衝突したときの処理^0^ if (Physics.Raycast(ray, out hit, distance)) { isMove = true; bombBase = hit.collider.gameObject.GetComponent <BombBase>(); } //クリックし続けてるなら if (isMove) { pos = _camera.ScreenToWorldPoint(vPoint + _camera.transform.forward * 10); if (vPoint.x < gameBottomLeft || vPoint.x > gameTopRight) { pos = new Vector3(oldPos.x, pos.y, pos.z); } if (vPoint.y > gameTop || vPoint.y < gameButtom) { pos = new Vector3(pos.x, oldPos.y, pos.z); } bombBase.transform.position = pos; } } else if (_touchManager._touch_phase == TouchPhase.Ended) { isMove = false; } oldPos = pos; } //oldの更新 old_phase._touch_phase = _touchManager._touch_phase; if (bombBase != default) { bombBase.Catch(isMove); } } }