/// <summary> /// Updates the trail. /// </summary> /// <param name="gesture">Gesture.</param> private void UpdateTrail(DragGesture gesture) { ContinuousGesturePhase ePhase = gesture.Phase; // the screen position the user's finger is at currently Vector2 vPos = gesture.Position; // based on phase of the gesture, call certain functions switch (ePhase) { case ContinuousGesturePhase.Started: trail.DragStarted(vPos); break; case ContinuousGesturePhase.Updated: trail.DragUpdated(vPos); break; case ContinuousGesturePhase.Ended: trail.DragEnded(); break; } // save the last position for use with displaying combo //lastPos = vPos; trailDeltaMove = gesture.DeltaMove; }
void OnDrag(DragGesture gesture) { // current gesture phase (Started/Updated/Ended) ContinuousGesturePhase phase = gesture.Phase; switch (phase) { case ContinuousGesturePhase.Ended: transform.position = startDragPos; if (doneWithShake) { GetComponent <TBDragToMove>().DragPlaneCollider = null; } break; case ContinuousGesturePhase.Updated: elapsed = gesture.ElapsedTime; if (!doneWithShake && elapsed >= 1f) //Shake inhaler for 1 second { if (!isGestureRecognized) { isGestureRecognized = true; scaleAnim.Play("InhalerObjectPulse"); NextStep(); } } break; } }
void OnDrag(DragGesture gesture) { // current gesture phase (Started/Updated/Ended) ContinuousGesturePhase phase = gesture.Phase; // Drag/displacement since last frame Vector3 deltaMove = gesture.DeltaMove / 800; deltaMove.y = 0; this.transform.position += deltaMove; }
void OnDrag(DragGesture gesture) { ContinuousGesturePhase phase = gesture.Phase; Vector3 UIPos = Game.gesturePos2UIPos(gesture.StartPosition); trails[0].transform.position = UIPos; trails[0].particleSystem.enableEmission = true; if (phase.ToString() == "Ended") { trails[0].particleSystem.enableEmission = false; } }
void OnPinch(PinchGesture gesture) { // current gesture phase (Started/Updated/Ended) ContinuousGesturePhase phase = gesture.Phase; // Current gap distance between the two fingers float gap = gesture.Gap; // Gap difference since last frame float delta = gesture.Delta; float pinchScalseFactor = 0.2f; this.transform.localScale += gesture.Delta * pinchScalseFactor * Vector3.one; }
ContinuousGestureEventPhase ContinuousGesturePhaseConvertor(ContinuousGesturePhase phase) { if (phase == ContinuousGesturePhase.None) { return(ContinuousGestureEventPhase.None); } else if (phase == ContinuousGesturePhase.Started) { return(ContinuousGestureEventPhase.Started); } else if (phase == ContinuousGesturePhase.Updated) { return(ContinuousGestureEventPhase.Updated); } else { return(ContinuousGestureEventPhase.Ended); } }
void OnTwist(TwistGesture gesture) { ContinuousGesturePhase phase = gesture.Phase; if (phase == ContinuousGesturePhase.Started) { twisting = true; } if (gesture.Position.y <= (Screen.height * 0.845f)) { CameraDummy.transform.Rotate(0.0f, gesture.DeltaRotation, 0.0f); UpdateTargetOffset(); } if (phase == ContinuousGesturePhase.Ended) { twisting = false; } }
void OnDrag(DragGesture gesture) { // current gesture phase (Started/Updated/Ended) ContinuousGesturePhase phase = gesture.Phase; if (phase == ContinuousGesturePhase.Ended) //Check where spacer has been dropped { Ray ray = Camera.main.ScreenPointToRay(gesture.Position); RaycastHit hit; bool snapBack = true; int maskLayer = 1 << 9; //Snap to position if spacer is at target position or revert to start pos if (Physics.Raycast(ray, out hit, 100, maskLayer)) { foreach (GameObject targetCollider in targetColliders) { if (hit.collider.gameObject == targetCollider) { transform.position = targetDragPos; if (!doneWithDrag && !isGestureRecognized) { isGestureRecognized = true; scaleAnim.Play("InhalerObjectPulse"); NextStep(); snapBack = false; } } } } if (snapBack) { transform.position = startDragPos; } } }
void OnDrag(DragGesture gesture) { if (Game.state != fixState) { return; } ContinuousGesturePhase phase = gesture.Phase; Debug.Log("phase" + phase.ToString()); // // Vector3 creaPos = gesture.Position; // // creaPos.x -= Screen.width / 2; // creaPos.y -= Screen.height / 2 ; // creaPos.x *= Camera.main.fieldOfView / ( Screen.height / 2 ) * touchScaleX ; // creaPos.y *= Camera.main.fieldOfView / ( Screen.height / 2 ) * touchScaleY ; // creaPos.z = 1f; // // creaCursor.transform.position = creaPos; if (ifPress) { Vector3 UIPos = Game.gesturePos2UIPos(gesture.StartPosition); float dis = Vector3.Distance(UIPos, initPos); Debug.Log("ifPressed " + dis.ToString()); Debug.Log("size " + (spriteWidth / 2)); //check if drag if (dis < spriteWidth / 2) { Debug.Log("distanced "); // Debug.Log ( "move " + gesture.DeltaMove.ToString() ); // transform.position += new Vector3 (gesture.DeltaMove.x * dragScale , gesture.DeltaMove.y * dragScale , 0); transform.position = Game.gesturePos2UIPos(gesture.Position); } // if (!newdown) { // //GameObject newo = Instantiate (fireballdown, new Vector3 (x, y, z), Quaternion.identity) as GameObject; // //down = newo; // //newdown = true; // } } if (phase.ToString().Equals("Started")) { Debug.Log("ges" + gesture.Position + gesture.StartPosition); Vector3 UIPos = Game.gesturePos2UIPos(gesture.Position); Debug.Log("began drag " + Vector3.Distance(UIPos, initPos) + " < " + (spriteWidth / 2)); // Ray ray = new Ray( Game.mainCamera.transform.position , UIPos - Game.mainCamera.transform.position ); // RaycastHit raycastHit = new RaycastHit(); // if ( Physics.Raycast( ray , out raycastHit ) && raycastHit.collider.gameObject == gameObject ) // { if (Vector3.Distance(UIPos, initPos) < spriteWidth / 2 && num > 0) { touchEffect.Emit(30); ifPress = true; } } if (phase.ToString().Equals("Ended") && ifPress) { ifPress = false; // DestroyObject(down, 0.1f); // newdown = false; //Debug.Log (gesture.Position); // logic.SendMessage("destoryLife", new Vector2(x + gesture.TotalMove.x / 150f, y + gesture.TotalMove.y / 150f)); HOTween.To(transform , resetTime , "position" , initPos , false , resetEase , 0); logic.SendMessage("destoryLife", Game.gesturePos2CreaPos(gesture.Position)); num--; text.text = num.ToString(); Color col = text.color; col.a = 0; text.color = col; col.a = 1; HOTween.To(text , textTime , new TweenParms() .Prop("color", col, false) .Loops(2, LoopType.YoyoInverse) ); Vector3 gesPos = Game.gesturePos2CreaPos(gesture.Position); GameObject exp = Instantiate(exposionPrefab) as GameObject; exp.transform.position = new Vector3(gesPos.x, gesPos.y, exp.transform.position.z); } creaCursor.transform.position = Game.gesturePos2CreaPos(gesture.Position); UICursor.transform.position = Game.gesturePos2UIPos(gesture.Position); }
// Direct user control of the fish's direction, for when the GO isKinematic void OnDrag(DragGesture gesture) // drag anywhere on the screen, unless on the cam dummy to move the camera position { ContinuousGesturePhase phase = gesture.Phase; animator.SetBool("dragging", true); bool dragIsHorizontal = false; bool dragIsVertical = false; if (Mathf.Abs(gesture.DeltaMove.x) > Mathf.Abs(gesture.DeltaMove.y)) { dragIsHorizontal = true; } else { dragIsVertical = true; } // if (phase == ContinuousGesturePhase.Ended) // { // //Debug.Log("phase: " + phase); // //animator.SetBool("dragging", false); // // adjust root rotation for ani rotation (should more ideally change gradually as turn ani returns to orig position) // GO.GetComponent<Rigidbody>().transform.Rotate(0.0f, 35.0f, 0.0f); // } // drag is happening in top area, where the user can rotate the camera using the dummy camera if (gesture.Position.y > (Screen.height * 0.845f)) { CameraDummy.transform.Rotate(0.0f, 2.0f * dragSpeed * gesture.DeltaMove.x, 0.0f); if (dragIsVertical) { // let user raise or lower the camera relative to the target // TODO: Set limits for the amount up or down the camera is allowed to go // TODO: UI to indicate camera height, and a way to return to default. CameraDummyChild.transform.position = new Vector3(CameraDummyChild.transform.position.x, CameraDummyChild.transform.position.y + verticalDragSpeed * gesture.DeltaMove.y, CameraDummyChild.transform.position.z); } UpdateTargetOffset(); } // drag is happening above the botton area reserved for UX. Therefore, turning can happen else if (gesture.Position.y > (Screen.height * 0.1f) && GO.GetComponent <Rigidbody>().isKinematic) { // FSMFishController fishController = GO.GetComponent<FSMFishController>(); // if the animator is in seesObstacle state, if the user forces the fish to turn (via this function) // turn off auto-turning by moving to seesObstacleNoTurningAllowed state. That way, the fish is allowed // to get close to an obstacle, giving the user more control (i.e. if they want to get close enough to // jump over the obstacle. And need to set canAutoTurn before switching to turn state. if (animator.GetCurrentAnimatorStateInfo(0).IsName("seesObstacle")) { animator.SetBool("canAutoTurn", false); } animator.SetBool("gotoTurnState", true); //fishController.turnIsComplete = true; // if a drag to turn is started, it should cancel any automated turning by returning to the SwimState if (dragIsHorizontal) { _cumulativeDragAmount += dragSpeed * gesture.DeltaMove.x; fishManager.cumulativeDragAmount = _cumulativeDragAmount; GO.GetComponent <Rigidbody>().transform.Rotate(0.0f, -dragSpeed * gesture.DeltaMove.x, 0.0f); if (gesture.DeltaMove.x < 0) { animator.SetBool("turnL", false); animator.SetBool("turnR", true); } else if (gesture.DeltaMove.x > 0) { animator.SetBool("turnR", false); animator.SetBool("turnL", true); } else // If drag movement stops, return to turn idle state //animator.SetBool("turnL", false); //animator.SetBool("turnR", false); { } } else if (dragIsVertical) { animator.SetBool("turnL", false); animator.SetBool("turnR", false); float rotateAmount = dragSpeed * gesture.DeltaMove.y; if (rb.transform.position.y > (_waterlevel - 0.2f)) { rotateAmount = -Mathf.Abs(rotateAmount); // only let the rotation go Down, not Up, if near the surface } GO.GetComponent <Rigidbody>().transform.Rotate(rotateAmount, 0.0f, 0.0f); // rotating the z } } // touch has ended, leave the if (phase == ContinuousGesturePhase.Ended) { animator.SetBool("turnL", false); animator.SetBool("turnR", false); animator.SetBool("dragging", false); _cumulativeDragAmount = 0.0f; fishManager.cumulativeDragAmount = 0.0f; } }
//Vector3 _start public virtual void OnDrag(DragGesture gesture) { if (Time.time < nextDragTime) { return; } _bNewDrag = true; //if (m_IsMouseDown == false && UIManager.Instance.IsPointInUI(gesture.Position) == true) // return; ContinuousGesturePhase phase = gesture.Phase; if (phase == ContinuousGesturePhase.Started) { m_YOnDown = Camera.main.transform.localPosition.y; m_IsMouseDown = true; //_camOriginPos = Camera.main.transform.position; _fingerOrigin = Camera.main.ScreenToViewportPoint(Input.mousePosition); _startPos = Camera.main.transform.position; _startDragTime = Time.realtimeSinceStartup; _hitPos = GetHitPosWithGeometry(gesture.Position, Camera.main.transform.position, _groundPosY); // ShowCanvas3d(false); SendCameraPosChangeMsg(true); //Debug.Log("_hitPos0:" + _hitPos); } else if (phase == ContinuousGesturePhase.Ended) { // _bNewDrag = false; if (m_IsMouseDown) { Vector3 endPos = Camera.main.transform.position; // Camera.main.ScreenToViewportPoint(Input.mousePosition); float dst = (endPos - _startPos).magnitude; //??? float totalDragTime = Time.realtimeSinceStartup - _startDragTime; float speed = Math.Min(dst / totalDragTime, AUTOSCROLLMAXSPEED); float acc = -200; Vector3 dir = (endPos - _startPos); StartCoroutine(MoveToStop(speed, dir.normalized, acc)); } else { SendCameraPosChangeMsg(false); } m_IsMouseDown = false; // } if (phase != ContinuousGesturePhase.Ended && m_IsMouseDown) { float dst = 0; //Vector3 pos = GetCamPosByScreenWorldPos (Camera.main, Input.mousePosition, _hitPos); //Vector3 offsetCam = -pos + _camOriginPos; //Vector3 camPos = _camOriginPos -offsetCam;// Vector3 camPos = GetCamPosByScreenWorldPos(Camera.main, Input.mousePosition, _hitPos, _tempBound); //if (!_bounds.Contains (camPos)) { // dst = _scale * _bounds.SqrDistance (camPos); // //Vector3 offsetDir = camPos-Camera.main.transform.position; // camPos = Vector3.Lerp (_camOriginPos, camPos, 1.0f / Math.Max (dst, _fMin)); // //Debug.Log ("dst1:"+dst); // //return;\ if (!IsInClampPos(ref camPos)) { //_camOriginPos = Camera.main.transform.position; //ResetCamPos(); } else { camPos.y = _startPos.y; ChangeCameraTransform(camPos, Quaternion.identity, true, false); } // if (dst / _scale > 0.3f) { // return; // } // Vector3 mPos = Camera.main.ScreenToViewportPoint(Input.mousePosition); // Vector3 dir = mPos - _fingerOrigin; // Vector3 camPos = Vector3.zero; // dir.z = dir.y; // dir.y = 0; // // float factor = 300 / Mathf.Abs(_hitPos.y - Camera.main.transform.position.y); // Vector3 offsetCam = Camera.main.transform.rotation * dir * factor; // offsetCam.y = 0; // camPos = _camOriginPos - offsetCam;// // float dst=0; // if (!_bounds.Contains (camPos)) { // dst=_scale*_bounds.SqrDistance (camPos); // camPos= camPos - offsetCam/Math.Max(dst,_fMin); // Debug.Log ("dst..1:"+dst/_scale+",camPos:"+camPos); // //return; // } // if (dst / _scale > 0.3f) { // return; // } // Vector3 cPos = Camera.main.transform.position; // Camera.main.transform.position = camPos;// // // // Vector3 curHit = GetHitPosWithGeometry(gesture.Position, camPos, _hitPos.y); // // Vector3 offset = curHit - _hitPos; // offset.y = 0; // Vector3 resultPos = camPos - offset; // if (!_bounds.Contains (resultPos)) { // dst=_scale*_bounds.SqrDistance (resultPos); // resultPos= camPos - offset/Math.Max(dst,_fMin); // //Debug.Log ("dst:"+dst); // //return; // } //SendCameraPosChangeMsg(); // if (dst / _scale > 0.3f) { // Camera.main.transform.position = cPos; // return; // } // Camera.main.transform.position = resultPos; // curHit = GetHitPosWithGeometry(gesture.Position, Camera.main.transform.position, _hitPos.y); // } }