public void AddRandomAction(int Difficulty = -1) { PinchType newActType = (PinchType)(RandGenerator.Next(0, 4 + 1)); if (Difficulty == -1) { Difficulty = RandGenerator.Next(_DifficultyMin, _DifficultyMax + 1); } switch (newActType) { case PinchType.Tip2: ActionsList.Add(new PinchAction(newActType, dpT2, Difficulty)); break; case PinchType.Pad2: ActionsList.Add(new PinchAction(newActType, dpP2, Difficulty)); break; case PinchType.Tip3: ActionsList.Add(new PinchAction(newActType, dpT3, Difficulty)); break; case PinchType.Pad3: ActionsList.Add(new PinchAction(newActType, dpP3, Difficulty)); break; //case PinchType.Lateral: // ActionsList.Add(new PinchAction(newActType, dpL2, Difficulty)); // break; } }
private void MakeStep(PinchType type) { try { float currentValue; switch (type) {// we have this annoying switch cases because the json Converter cannot convert Dictionary, so we just added 4 properties... case PinchType.Pad2: currentValue = m_mainController.CurrentPatient.MotionRange.Pad2; break; case PinchType.Pad3: currentValue = m_mainController.CurrentPatient.MotionRange.Pad3; break; case PinchType.Tip2: currentValue = m_mainController.CurrentPatient.MotionRange.Tip2; break; case PinchType.Tip3: currentValue = m_mainController.CurrentPatient.MotionRange.Tip3; break; default: return; } strength = m_pinchManager.GetPinchStrength(type); if (strength > currentValue) { switch (type) { case PinchType.Pad2: m_mainController.CurrentPatient.MotionRange.Pad2 = strength; break; case PinchType.Pad3: m_mainController.CurrentPatient.MotionRange.Pad3 = strength; break; case PinchType.Tip2: m_mainController.CurrentPatient.MotionRange.Tip2 = strength; break; case PinchType.Tip3: m_mainController.CurrentPatient.MotionRange.Tip3 = strength; break; default: return; } } if (strength >= 1 || stopwatch.ElapsedMilliseconds > timeToWaitInSec * 1000) { StartCoroutine(NextLevel()); } } catch (Exception e) { MainController.PrintToLog(e.ToString(), MainController.LogType.Error); } }
public void MakeMutation() { int actionIndex = (RandGenerator.Next(0, ActionsList.Count)); int newActionIndex = (RandGenerator.Next(0, 4 + 1)); while (actionIndex == newActionIndex) { newActionIndex = (RandGenerator.Next(0, 4 + 1)); } ActionsList.RemoveAt(actionIndex); PinchType newActType = (PinchType)newActionIndex; int Difficulty = RandGenerator.Next(_DifficultyMin, _DifficultyMax + 1); switch (newActType) { case PinchType.Tip2: ActionsList.Add(new PinchAction(newActType, dpT2, Difficulty)); break; case PinchType.Pad2: ActionsList.Add(new PinchAction(newActType, dpP2, Difficulty)); break; case PinchType.Tip3: ActionsList.Add(new PinchAction(newActType, dpT3, Difficulty)); break; case PinchType.Pad3: ActionsList.Add(new PinchAction(newActType, dpP3, Difficulty)); break; } }
public void AddRandomAction(int Difficulty = -1) { PinchType newActType = (PinchType)(RandGenerator.Next(1, 4)); if (Difficulty == -1) { Difficulty = RandGenerator.Next(_DifficultyMin, _DifficultyMax + 1); } switch (newActType) { case PinchType.Tip2: ActionsList.Add(new PinchAction(newActType, dpT2, Difficulty)); break; case PinchType.Pad2: ActionsList.Add(new PinchAction(newActType, dpP2, Difficulty)); break; case PinchType.Tip3: ActionsList.Add(new PinchAction(newActType, dpT3, Difficulty)); break; case PinchType.Pad3: ActionsList.Add(new PinchAction(newActType, dpP3, Difficulty)); break; default: MainController.PrintToLog("At \"AddRandomAction\" Random number was not good - " + newActType + ". TherapyData.cs.", MainController.LogType.Error); break; } }
/// <summary> /// [コンストラクタ] /// </summary> /// <param name="touchPoint1"> 接触点 1 </param> /// <param name="touchPoint2"> 接触点 2 </param> /// <param name="angle"> 接触点 1 から見た 接触点 2 の角度</param> /// <param name="baseDistance"> 基準となる距離( 1/100 ピクセル ) </param> /// <param name="currentDistance">現在の距離( 1/100 ピクセル ) </param> /// <param name="pinchType"> ピンチ区分 </param> public PinchData(TouchPoint touchPoint1, TouchPoint touchPoint2, int angle, int baseDistance, int currentDistance, PinchType pinchType) { this.touchPoint1 = touchPoint1; this.touchPoint2 = touchPoint2; this.angle = angle; this.baseDistance = baseDistance; this.currentDistance = currentDistance; this.pinchType = pinchType; }
public int DifficultyPerPlayer; // dp public PinchAction(PinchType t, int dp, int diffScore = -1) { Type = t; DifficultyPerPlayer = dp; if (diffScore == -1) { DifficultyLevel = RandGenerator.Next(_DifficultyMin, _DifficultyMax + 1); } else { DifficultyLevel = diffScore; } }
/// <summary> /// [内部メソッド] /// 「ピンチ」イベントを実行する /// </summary> /// <param name="touchPoint1">接触点1</param> /// <param name="touchPoint2">接触点2</param> private void executePinchEvent(TouchPoint touchPoint1, TouchPoint touchPoint2) { // 接触点1と接触点2の距離から「ピンチ」イベントハンドラを実行するか int distance = Calculator.CalcurateDistance(touchPoint1.X, touchPoint1.Y, touchPoint2.X, touchPoint2.Y); if (Math.Abs(this.baseTwoTouchDistanceCentiPixel - distance) < pinchIntervalCentiPixel) { return; } // 接触点1と接触点2の角度を計算する int angle = Calculator.CalculateAngle(touchPoint1.X, touchPoint1.Y, touchPoint2.X, touchPoint2.Y); // 基準となる距離と接触点1,2の距離からピンチ区分を決定する PinchType type = Calculator.DistanceToPinchType(this.baseTwoTouchDistanceCentiPixel, distance); // 「ピンチ」イベントハンドラを実行する var pinchData = new PinchData(touchPoint1, touchPoint2, angle, this.baseTwoTouchDistanceCentiPixel, distance, type); var peArgs = new PinchEventArgs(pinchData); OnPinch(peArgs); this.baseTwoTouchDistanceCentiPixel = distance; }
void Update() { //inertia camera panning if (InertiaUse) { if (InertiaActive && (InertiaSpeed.magnitude > fInertiaCheckMin)) { SetCameraPosition(trCameraRoot.position - InertiaSpeed); InertiaSpeed = Vector3.Lerp(InertiaSpeed, Vector3.zero, InertiaAge); InertiaAge += Time.smoothDeltaTime; } else { InertiaActive = false; } } if (fCamPanLimit > 0.0f) { fCamPanLimit -= Time.deltaTime; } if (Input.touchCount < 2) { if (InPinch) { InPinch = false; bInTouch = false; fCamPanLimit = 0.1f; pinchType = PinchType.None; camPanningUse = true; } } Vector3 vTouch = Input.mousePosition; ray = Camera.main.ScreenPointToRay(vTouch); float enter; //if left MouseButton down if (Input.GetMouseButton(0)) { if (EventSystem.current && EventSystem.current.IsPointerOverGameObject()) { //Debug.Log("left-click over a GUI element!"); return; } #if UNITY_EDITOR if (Input.GetKey(KeyCode.LeftShift)) { //Debug.Log ("left shift key is held down"); if (!vEDInRotation) { vEDInRotation = true; vEDCamRootRotStart = trCameraRoot.localRotation.eulerAngles; vEDMouseStart = vTouch; //Debug.Log ("editor rotation start"); } else { if (Vector3.Distance(vTouch, vEDMouseStart) > fDragCheckMin) { //Debug.Log ("change rotation start vTouch:"+vTouch+" vEDMouseStart:"+vEDMouseStart+" vEDCamRootRotStart:"+vEDCamRootRotStart); vEDMouseMove = vTouch - vEDMouseStart; vEDCamRootRot.x = vEDCamRootRotStart.x - vEDMouseMove.y * 0.1f; vEDCamRootRot.y = vEDCamRootRotStart.y + vEDMouseMove.x * 0.1f; vEDCamRootRot.z = 0; vEDCamRootRot.x = Mathf.Clamp(vEDCamRootRot.x, 10.0f, 90.0f); trCameraRoot.localRotation = Quaternion.Euler(vEDCamRootRot); //Debug.Log ("change rotation : "+vEDCamRootRot); } } } else { vEDInRotation = false; } #endif xzPlane.Raycast(ray, out enter); if (!bInTouch) { bInTouch = true; //gr.enabled = false; ClickAfter = 0.0f; LongTabCheck = true; Dragged = false; mousePosPrev = mousePosStart = vTouch; if (Listner != null) { Listner.OnTouchDown(ray); } // Get Picking Position xzPlane.Raycast(ray, out enter); vPickStart = ray.GetPoint(enter) - trCameraRoot.position; vPickOld = vPickStart; vCamRootPosOld = trCameraRoot.position; if (InertiaUse) { InertiaActive = false; InertiaAge = 0.0f; InertiaSpeed = Vector3.zero; } //Debug.Log ("Update buildingSelected:"+((buildingSelected != null) ? buildingSelected.name : "none")); } else { if (Input.touchCount < 2) { //Mouse Button is in pressed & mouse move certain diatance if (Vector3.Distance(vTouch, mousePosStart) > fDragCheckMin) { // set drag flag on if (!Dragged) { Dragged = true; if (Listner != null) { Listner.OnDragStart(ray); } } #if UNITY_EDITOR if (!Input.GetKey(KeyCode.LeftShift)) { #endif // prevent camera shaking while touch pressed after drag. if (Vector3.Distance(vTouch, mousePosPrev) > fDragCheckMin) { if (Listner != null) { Listner.OnDrag(ray); } if (camPanningUse) { Vector3 vPickNew = ray.GetPoint(enter) - trCameraRoot.position; if (InertiaUse) { InertiaSpeed = 0.3f * InertiaSpeed + 0.7f * (vPickNew - vPickOld); } vCameraPanDir = vPickNew - vPickStart; //Debug.Log ("vCameraPanDir:"+vCameraPanDir); SetCameraPosition(vCamRootPosOld - vCameraPanDir); vPickOld = vPickNew; } } #if UNITY_EDITOR } #endif } // Not Move else { if (Dragged) { if (Listner != null) { Listner.OnDrag(ray); } if (camPanningUse) { Vector3 vPickNew = ray.GetPoint(enter) - trCameraRoot.position; if (InertiaUse) { InertiaSpeed = 0.3f * InertiaSpeed + 0.7f * (vPickNew - vPickOld); } vPickOld = vPickNew; } } else { if (!Dragged) { ClickAfter += Time.deltaTime; if (LongTabCheck && (ClickAfter > LongTabPeriod)) { LongTabCheck = false; if (Listner != null) { Listner.OnLongPress(ray); } } } } } mousePosPrev = vTouch; } } } else { #if UNITY_EDITOR if (vEDInRotation) { vEDInRotation = false; } #endif //Release MouseButton if (bInTouch) { bInTouch = false; //gr.enabled = true; if (Listner != null) { Listner.OnTouchUp(ray); } // if in drag state if (Dragged) { if (InertiaUse && (InertiaSpeed.magnitude > fInertiaCheckMin)) { InertiaActive = true; } if (Listner != null) { Listner.OnDragEnd(ray); } } else { if (Listner != null) { Listner.OnTouch(ray); } } } } //if (EventSystem.current && !EventSystem.current.IsPointerOverGameObject()) { //zoom with mouse wheel float fInputValue = Input.GetAxis("Mouse ScrollWheel"); if (Listner != null) { Listner.OnMouseWheel(fInputValue); } if (fInputValue != 0.0f) { if (!InZoom) { mousePosStart = vTouch; xzPlane.Raycast(ray, out enter); vPickStart = ray.GetPoint(enter) - trCameraRoot.position; vCamRootPosOld = trCameraRoot.position; InZoom = true; } float zoomDelta = fInputValue * zoomSpeed; SetCameraZoom(zoomCurrent - zoomDelta); UpjustPickPos(vTouch, vPickStart); } else { if (InZoom) { InZoom = false; } } //} // pinch zoom for mobile touch input if (Input.touchCount != 2) { return; } Touch touchZero = Input.GetTouch(0); Touch touchOne = Input.GetTouch(1); Vector3 vPinchDir = touchOne.position - touchZero.position; float fPinchDistance = vPinchDir.magnitude; vPinchDir.Normalize(); Vector3 vPinchTouchCenter = (touchOne.position - touchZero.position) * 0.5f + touchZero.position; ray = Camera.main.ScreenPointToRay(vPinchTouchCenter); xzPlane.Raycast(ray, out enter); Vector3 vPinchPickCenter = ray.GetPoint(enter) - trCameraRoot.position; if (!InPinch) { vTouchPosStart[0] = touchZero.position; vTouchPosStart[1] = touchOne.position; ZoomStart = zoomCurrent; vCamRootRotStart = trCameraRoot.localRotation.eulerAngles; vCamRootRot = vCamRootRotStart; vCamRootPosOld = trCameraRoot.position; vPinchDirStart = vPinchDir; fPinchDistanceStart = fPinchDistance; vPinchPickCenterStart = vPinchPickCenter; InPinch = true; camPanningUse = false; } else { Vector2 vTouchZeroDelta = touchZero.position - vTouchPosStart[0]; Vector2 vTouchOneDelta = touchOne.position - vTouchPosStart[1]; if ((vTouchZeroDelta.magnitude > 1.0f) && (vTouchOneDelta.magnitude > 1.0f)) { float angleWithUp = Vector2.Angle(vTouchOneDelta, Vector2.up); float angleBetweenTouches = Vector2.Angle(vTouchZeroDelta, vTouchOneDelta); //Debug.Log ("angleWithUp:"+angleWithUp+"angleBetweenTouches:"+angleBetweenTouches); // check if pinch up if (((angleWithUp < 30.0f) || (150.0f < angleWithUp)) && (angleBetweenTouches < 50.0f)) { pinchType = PinchType.Up; } else if ((angleBetweenTouches < 30.0f) || (150.0f < angleBetweenTouches)) { pinchType = PinchType.Zoom; } else { pinchType = PinchType.Rotate; } } if (pinchType == PinchType.Up) { if (UseXRotation) { //rotate x float fDelta = touchZero.deltaPosition.y * Time.deltaTime * 10.0f; vCamRootRot.x = Mathf.Clamp(vCamRootRot.x - fDelta, 10.0f, 90.0f); trCameraRoot.localRotation = Quaternion.Euler(vCamRootRot); Debug.Log("change rotation 1"); } } else { //zoom float fDelta = fPinchDistance - fPinchDistanceStart; SetCameraZoom(ZoomStart - fDelta * zoomSpeed * 0.05f); if (UseYRotation) { // rotate y Vector3 v1 = vPinchDirStart; Vector3 v2 = vPinchDir; float dot = v1.x * v2.x + v1.y * v2.y; //# dot product float det = v1.x * v2.y - v1.y * v2.x; // # determinant float angle = Mathf.Atan2(det, dot); //# atan2(y, x) or atan2(sin, cos) angle *= Mathf.Rad2Deg; vCamRootRot.y = vCamRootRotStart.y + angle; trCameraRoot.localRotation = Quaternion.Euler(vCamRootRot); Debug.Log("change rotation 2"); } } if ((pinchType == PinchType.Zoom) || (pinchType == PinchType.Rotate)) { UpjustPickPos(vPinchTouchCenter, vPinchPickCenterStart); } } }
// Declares the Update function void Control() { if (MultiplatformTouch) { UniversalTouch(); } #if UNITY_EDITOR Pinch = PinchEditor; // Sets pich to the editor pinch you gave. #endif #if !UNITY_ANDROID && !UNITY_IOS || UNITY_EDITOR if (Input.GetMouseButtonDown(0)) // If the mouse button is down { TouchedObject = null; // Makes LastTouchObject empty so it no longer has an effect Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); // Sends a new ray from mouse position RaycastHit hit; // The hit info of ray if (Physics.Raycast(ray, out hit)) // If the ray was collided with something { TouchingObject = hit.transform.gameObject; // Then player are touching (clicking) that Object! } } else if (Input.GetMouseButtonUp(0)) // if the mouse button is released { TouchingObject = null; // Player is not touching (clicking) anything now Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); // Sends a new ray from mouse Position RaycastHit hit; // The hit info of ray if (Physics.Raycast(ray, out hit)) // If the ray collided with something. { TouchedObject = hit.transform.gameObject; // Then player has just touched(clicked) that object } } if (Input.GetMouseButtonDown(0)) // Checks if the mouse was just pressed. { LastPosition = Input.mousePosition; // Sets last position to mouse position } else if (Input.GetMouseButtonUp(0)) // Now if mouse button is released { UpPosition = Input.mousePosition; // Sets up position to mouse position for easy acess if (UpPosition.x >= UpPosition.x + SwipeSensivity) { Swipe = SwipeType.Right; // Sets swipe to Right } else if (UpPosition.x <= LastPosition.x - SwipeSensivity) { Swipe = SwipeType.Left; // Sets swipe to left } else if (UpPosition.y >= LastPosition.y + SwipeSensivity) { Swipe = SwipeType.Up; // Sets swipe to Up } else if (UpPosition.y <= LastPosition.y - SwipeSensivity) { Swipe = SwipeType.Down; // Sets swip to Down } else { Swipe = SwipeType.SamePosition; // No swipe occoured! } } #endif #if UNITY_ANDROID || UNITY_IOS if (!MultiplatformTouch) { UniversalTouch(); } #endif }
Vector2 UpPosition; // The position where user released touch void DetectSwipe() //Declares the new DetectSwipe function { if (Input.touchCount > 0) { if (Input.GetTouch(0).phase == TouchPhase.Began) { LastPosition = Input.GetTouch(0).position; } else if (Input.GetTouch(0).phase == TouchPhase.Ended) { UpPosition = Input.GetTouch(0).position; if (UpPosition.x >= UpPosition.x + SwipeSensivity) { Swipe = SwipeType.Right; // Sets swipe to Right } else if (UpPosition.x <= LastPosition.x - SwipeSensivity) { Swipe = SwipeType.Left; // Sets swipe to left } else if (UpPosition.y >= LastPosition.y + SwipeSensivity) { Swipe = SwipeType.Up; // Sets swipe to Up } else if (UpPosition.y <= LastPosition.y - SwipeSensivity) { Swipe = SwipeType.Down; // Sets swip to Down } else { Swipe = SwipeType.SamePosition; // No swipe occoured! } } if (Input.touchCount > 1) // If two fingers are touching the screen { if (Input.GetTouch(1).phase == TouchPhase.Began) // if the second finger has just began touching { InitialDistance = Vector3.Distance(Input.GetTouch(0).position, Input.GetTouch(1).position); // Initial Distance is the distance between two fingers now } if (Input.GetTouch(0).phase == TouchPhase.Moved && Input.GetTouch(1).phase == TouchPhase.Moved) // If any of the finger were moved { float Distance = Vector3.Distance(Input.GetTouch(0).position, Input.GetTouch(1).position); // Distance between the two fingers now if (Distance < InitialDistance) // if the distance was lesser than Initial Distance { Pinch = PinchType.Decrease; // Sets Pinch to decrese. } else if (Distance > InitialDistance) // if the distance was more than Initial Distance { Pinch = PinchType.Increase; // Sets pinch to Increse } } else { Pinch = PinchType.None; // Player did not pinched } } else { Pinch = PinchType.None; // Player did not pinched } } }
/// <summary> /// [内部メソッド] /// 排他的イベントを割り当てる /// </summary> private void allocateExclusiveEvent(Win32ApiWrapper.TouchEventData[] eventData) { Win32ApiWrapper.TouchEventFlags eventFlags = eventData[0].dwEventFlags; // 接触点の座標情報を設定する TouchPoint touchPoint1 = new TouchPoint(eventData[0].x, eventData[0].y); TouchPoint touchPoint2 = null; if (eventData.Length > 1) { touchPoint2 = new TouchPoint(eventData[1].x, eventData[1].y); } // 各イベントを割り当てる if (eventData.Length > 1 && (eventData[1].dwEventFlags & Win32ApiWrapper.TouchEventFlags.DOWN) == Win32ApiWrapper.TouchEventFlags.DOWN) { // ピンチ操作の開始を検知する _baseTwoTouchDistance = Calculator.CalcurateDistance(touchPoint1.X, touchPoint1.Y, touchPoint2.X, touchPoint2.Y); } else if (eventData.Length > 1 && (eventData[1].dwEventFlags & Win32ApiWrapper.TouchEventFlags.MOVE) == Win32ApiWrapper.TouchEventFlags.MOVE) { // 「ピンチ」イベントハンドラを実行するか int distance = Calculator.CalcurateDistance(touchPoint1.X, touchPoint1.Y, touchPoint2.X, touchPoint2.Y); if (Math.Abs(_baseTwoTouchDistance - distance) > PinchInterval) { // 「ピンチ」イベントハンドラを実行する int angle = Calculator.CalculateAngle(touchPoint1.X, touchPoint1.Y, touchPoint2.X, touchPoint2.Y); PinchType type = Calculator.DistanceToPinchType(_baseTwoTouchDistance, distance); var pinchData = new PinchData(touchPoint1, touchPoint2, angle, _baseTwoTouchDistance, distance, type); var peArgs = new PinchEventArgs(pinchData); OnPinch(peArgs); _baseTwoTouchDistance = distance; } } else if ((eventFlags & Win32ApiWrapper.TouchEventFlags.UP) == Win32ApiWrapper.TouchEventFlags.UP) { int distance = Calculator.CalcurateDistance(_baseTouchPoint.X, _baseTouchPoint.Y, touchPoint1.X, touchPoint1.Y); TimeSpan touchSpan = DateTime.Now - _touchDownTime; TimeSpan tapSpan = DateTime.Now - _previousTapTime; if (shouldExecSwipeEvent(touchPoint1, distance)) { // 「スワイプ」イベントハンドラを実行する int angle = Calculator.CalculateAngle(_baseTouchPoint.X, _baseTouchPoint.Y, touchPoint1.X, touchPoint1.Y); SwipeDirection direction = Calculator.AngleToDirection(angle); var swipeData = new SwipeData(_baseTouchPoint, touchPoint1, angle, distance, direction); var seArgs = new SwipeEventArgs(swipeData, _orbit); OnSwipe(touchPoint1, seArgs); resetFields(); } else if (touchSpan.TotalMilliseconds < _tapInterval && tapSpan.TotalMilliseconds < _doubleTapInterval) { // 「ダブルタップ」イベントハンドラを実行する var teArgs = new TouchEventArgs(touchPoint1, _orbit); OnDoubleTap(teArgs); } else if (touchSpan.TotalMilliseconds < _tapInterval) { // 「タップ」イベントハンドラを実行する _previousTapTime = DateTime.Now; var teArgs = new TouchEventArgs(touchPoint1, _orbit); OnTap(teArgs); } } }