void Update() { if (!Controllable) { return; } var inputH = InputUtil.GetInputH(); var inputV = InputUtil.GetInputV(); var inputPinch = -InputUtil.GetPinch(); // horizontal input for azimuth var dA = inputH * angularSpeed; // vertical input for elevation var dE = inputV * angularSpeed; // change radius. scroll up to go near var dR = inputPinch * scrollSpeed; Move(dA, dE, dR); }
/// <summary> /// dragging cube /// </summary> private void OnRotate() { _drag2DegreeTotal = 0f; Observable.EveryUpdate() .Where(_ => Input.GetMouseButton(0)) .Subscribe(_ => { var isHorizontal = false; var drag2Degree = 0f; var dragAmount = InputUtil.GetDragAmount(); if (_rotateAxisScreenHorizontal.sqrMagnitude != 0) { drag2Degree = -dragAmount.x * 0.3f; isHorizontal = true; } else { drag2Degree = dragAmount.y * 0.3f; } drag2Degree = Mathf.RoundToInt(drag2Degree); // create rotation matrix var sign = 0; var rotateAngle = Vector3.zero; if (_rotateAxisScreenHorizontal.x != 0 || _rotateAxisScreenVertical.x != 0) { sign = isHorizontal ? _rotateAxisScreenHorizontal.x : _rotateAxisScreenVertical.x; rotateAngle = new Vector3(drag2Degree * sign, 0f, 0f); } else if (_rotateAxisScreenHorizontal.y != 0 || _rotateAxisScreenVertical.y != 0) { sign = isHorizontal ? _rotateAxisScreenHorizontal.y : _rotateAxisScreenVertical.y; rotateAngle = new Vector3(0f, drag2Degree * sign, 0f); } else if (_rotateAxisScreenHorizontal.z != 0 || _rotateAxisScreenVertical.z != 0) { sign = isHorizontal ? _rotateAxisScreenHorizontal.z : _rotateAxisScreenVertical.z; rotateAngle = new Vector3(0f, 0f, drag2Degree * sign); } rotateAngle = new Vector3(Mathf.RoundToInt(rotateAngle.x), Mathf.RoundToInt(rotateAngle.y), Mathf.RoundToInt(rotateAngle.z)); var matrix = cubesUtil.RotateMatrix(rotateAngle); foreach (var cube in _rotateCubes) { cube.RotateAroundAxis(matrix); } _drag2DegreeTotal += drag2Degree * sign; _drag2DegreeTotal %= 360f; }) .AddTo(stateDisposable); Observable.EveryUpdate() .Where(_ => Input.GetMouseButtonUp(0)) .Subscribe(_ => { stateAsObservable.Value = State.Transfer; _messageSubject.OnNext(Message.ReleaseCube); }) .AddTo(stateDisposable); }
/// <summary> /// axis /// 回転の軸と方向を決定 /// </summary> private void OnRotateTargets() { Observable.EveryUpdate() .Subscribe(_ => { var dragAmount = InputUtil.GetDragAmount(); _totalDragAmount.x += dragAmount.x; _totalDragAmount.y += dragAmount.y; var threshold = 50f; if (Mathf.Abs(_totalDragAmount.x) > threshold && Mathf.Abs(_totalDragAmount.x) > Mathf.Abs(_totalDragAmount.y)) { var cameraUp = mainCamera.transform.up; Debug.Log(cameraUp.ToString()); if (Mathf.Abs(cameraUp.x) > Mathf.Abs(cameraUp.y) && Mathf.Abs(cameraUp.x) > Mathf.Abs(cameraUp.z)) { _rotateAxisScreenHorizontal = cameraUp.x > 0 ? new Vector3Int(1, 0, 0) : new Vector3Int(-1, 0, 0); var posIdX = _clickedCube.PositionId.x; _rotateCubes = _cubes.Where(cube => cube.PositionId.x == posIdX).ToList(); } else if (Mathf.Abs(cameraUp.y) > Mathf.Abs(cameraUp.x) && Mathf.Abs(cameraUp.y) > Mathf.Abs(cameraUp.z)) { _rotateAxisScreenHorizontal = cameraUp.y > 0 ? new Vector3Int(0, 1, 0) : new Vector3Int(0, -1, 0); var posIdY = _clickedCube.PositionId.y; _rotateCubes = _cubes.Where(cube => cube.PositionId.y == posIdY).ToList(); } else { _rotateAxisScreenHorizontal = cameraUp.z > 0 ? new Vector3Int(0, 0, 1) : new Vector3Int(0, 0, -1); var posIdZ = _clickedCube.PositionId.z; _rotateCubes = _cubes.Where(cube => cube.PositionId.z == posIdZ).ToList(); } stateAsObservable.Value = State.Rotate; } else if (Mathf.Abs(_totalDragAmount.y) > threshold && Mathf.Abs(_totalDragAmount.y) > Mathf.Abs(_totalDragAmount.x)) { var cameraRight = mainCamera.transform.right; if (Mathf.Abs(cameraRight.x) > Mathf.Abs(cameraRight.y) && Mathf.Abs(cameraRight.x) > Mathf.Abs(cameraRight.z)) { _rotateAxisScreenVertical = cameraRight.x > 0 ? new Vector3Int(1, 0, 0) : new Vector3Int(-1, 0, 0); var posIdX = _clickedCube.PositionId.x; _rotateCubes = _cubes.Where(cube => cube.PositionId.x == posIdX).ToList(); } else if (Mathf.Abs(cameraRight.y) > Mathf.Abs(cameraRight.x) && Mathf.Abs(cameraRight.y) > Mathf.Abs(cameraRight.z)) { _rotateAxisScreenVertical = cameraRight.y > 0 ? new Vector3Int(0, 1, 0) : new Vector3Int(0, -1, 0); var posIdY = _clickedCube.PositionId.y; _rotateCubes = _cubes.Where(cube => cube.PositionId.y == posIdY).ToList(); } else { _rotateAxisScreenVertical = cameraRight.z > 0 ? new Vector3Int(0, 0, 1) : new Vector3Int(0, 0, -1); var posIdZ = _clickedCube.PositionId.z; _rotateCubes = _cubes.Where(cube => cube.PositionId.z == posIdZ).ToList(); } stateAsObservable.Value = State.Rotate; } }) .AddTo(stateDisposable); }