protected void Acquire(FingerGestures.Finger finger) { if (!finger.GestureRecognizers.Contains(this)) { finger.GestureRecognizers.Add(this); } }
// Find closest cluster within radius Cluster FindExistingCluster(FingerGestures.Finger finger) { Cluster best = null; float bestSqrDist = float.MaxValue; float sqrClusterRadiusInPixels = FingerGestures.Convert(ClusterRadius * ClusterRadius, DistanceUnit, DistanceUnit.Pixels); for (int i = 0; i < clusters.Count; ++i) { Cluster cluster = clusters[i]; float elapsedTime = finger.StarTime - cluster.StartTime; // temporal grouping criteria if (elapsedTime > TimeTolerance) { continue; } Vector2 centroid = cluster.Fingers.GetAveragePosition(); float sqrDist = Vector2.SqrMagnitude(finger.Position - centroid); if (sqrDist < bestSqrDist && sqrDist < sqrClusterRadiusInPixels) { best = cluster; bestSqrDist = sqrDist; } } return(best); }
void OnDrag(DragGesture gesture) { if (!HomeBuildingManager.GetInstance().Contains(gesture.Selection)) { return; } //相机停止移动 FingerCamera.GetInstance().couldDrag = false; // first finger FingerGestures.Finger finger = gesture.Fingers[0]; if (gesture.Phase == ContinuousGesturePhase.Started) { dragFingerIndex = finger.Index; } else if (finger.Index == dragFingerIndex) // gesture in progress, make sure that this event comes from the finger that is dragging our dragObject { if (gesture.Phase == ContinuousGesturePhase.Updated) { //transform.position = ScreenPointToWorldPlane(gesture.Position); gesture.Selection.transform.position = ScreenPointToWorldPlane(gesture.Position); } else { dragFingerIndex = -1; FingerCamera.GetInstance().couldDrag = true; var gridPos = HomeGridManager.GetInstance().WorldPosToGridPos(gesture.Selection.transform.position); var cellCenter = HomeGridManager.GetInstance().GridPosToCellCenterInWorld(gridPos); //transform.position = cellCenter; gesture.Selection.transform.position = cellCenter; SoundManager.GetInstance().PlaySound("sound/build_pickup_05"); } } }
protected override void OnBegin(FingerGestures.IFingerList touches) { FingerGestures.Finger finger0 = touches[0]; FingerGestures.Finger finger1 = touches[1]; StartPosition[0] = finger0.StartPosition; StartPosition[1] = finger1.StartPosition; Position[0] = finger0.Position; Position[1] = finger1.Position; float angle = SignedAngularGap(finger0, finger1, finger0.StartPosition, finger1.StartPosition); totalRotation = Mathf.Sign(angle) * MinRotation; rotationDelta = 0; if (OnRotationBegin != null) { OnRotationBegin(this); } rotationDelta = angle - totalRotation; totalRotation = angle; if (OnRotationMove != null) { OnRotationMove(this); } }
protected override bool CanBegin(PinchGesture gesture, FingerGestures.IFingerList touches) { if (!base.CanBegin(gesture, touches)) { return(false); } FingerGestures.Finger finger0 = touches[0]; FingerGestures.Finger finger1 = touches[1]; // if( !FingerGestures.AllFingersMoving( finger0, finger1 ) ) //return false; //if( !FingersMovedInOppositeDirections( finger0, finger1 ) ) //return false; float startGapSqr = Vector2.SqrMagnitude(finger0.StartPosition - finger1.StartPosition); float curGapSqr = Vector2.SqrMagnitude(finger0.Position - finger1.Position); if (Mathf.Abs(startGapSqr - curGapSqr) < ToSqrPixels(MinDistance)) { return(false); } return(true); }
void Update() { if (!FingerGestures.Instance) { return; } if (FingerGestures.Touches.Count >= 2) { distance = Vector2.Distance(FingerGestures.Touches[0].Position, FingerGestures.Touches[1].Position); } else { distance = -1; } int i = 0; for ( ; i < FingerGestures.Touches.Count; ++i) { FingerGestures.Finger finger = FingerGestures.Touches[i]; Rect inset = icons[i].pixelInset; inset.x = finger.Position.x - inset.width / 2; inset.y = finger.Position.y - inset.height / 2; icons[i].pixelInset = inset; icons[i].enabled = true; } for ( ; i < icons.Length; ++i) { icons[i].enabled = false; } }
void UpdatePerFinger() { for (int i = 0; i < FingerGestures.Instance.MaxFingers && i < MaxSimultaneousGestures; ++i) { FingerGestures.Finger finger = FingerGestures.GetFinger(i); T gesture = Gestures[i]; FingerGestures.FingerList touches = tempTouchList; touches.Clear(); if (finger.IsDown) { touches.Add(finger); } if (gesture.State == GestureRecognitionState.Ready) { if (CanBegin(gesture, touches)) { Begin(gesture, 0, touches); } } UpdateGesture(gesture, touches); } }
private void OnDrag(DragGesture gesture) { if (gesture.Selection == null) { return; } FingerGestures.Finger finger = gesture.Fingers[0]; if (gesture.Phase == ContinuousGesturePhase.Started) { _dragScroll = gesture.Selection.GetComponent <Scroll>(); if (_dragScroll == null) { return; } _dragFingerIndex = finger.Index; } else if (finger.Index == _dragFingerIndex && _dragScroll != null) // gesture in progress, make sure that this event comes from the finger that is dragging our dragObject { if (gesture.Phase == ContinuousGesturePhase.Updated) { _dragScroll.DragScroll(gesture.StartPosition, gesture.Position); } else { _dragScroll.StopScrolling(); _dragFingerIndex = -1; } } }
protected override bool CanBegin(FingerGestures.IFingerList touches) { if (!base.CanBegin(touches)) { return(false); } FingerGestures.Finger finger0 = touches[0]; FingerGestures.Finger finger1 = touches[1]; if (!FingerGestures.AllFingersMoving(finger0, finger1)) { return(false); } if (!FingersMovedInOppositeDirections(finger0, finger1)) { return(false); } // check if we went past the minimum rotation amount treshold float rotation = SignedAngularGap(finger0, finger1, finger0.StartPosition, finger1.StartPosition); if (Mathf.Abs(rotation) < MinRotation) { return(false); } return(true); }
void OnDrag(DragGesture gesture) { // first finger FingerGestures.Finger finger = gesture.Fingers[0]; if (gesture.Phase == ContinuousGesturePhase.Started) { // dismiss this event if we're not interacting with our drag object if (gesture.Selection != dragObject) { return; } Debug.Log("Started dragging with finger " + finger); // remember which finger is dragging dragObject dragFingerIndex = finger.Index; } else if (finger.Index == dragFingerIndex) // gesture in progress, make sure that this event comes from the finger that is dragging our dragObject { if (gesture.Phase == ContinuousGesturePhase.Updated) { // update the position by converting the current screen position of the finger to a world position on the Z = 0 plane dragObject.transform.position = GetWorldPos(gesture.Position); } else { Debug.Log("Stopped dragging with finger " + finger); // reset our drag finger index dragFingerIndex = -1; } } }
//只对第一只手指的拖动动作有效,这里不暴露finger给用户是因为不想封装比较复杂的finger类, //以后要用两三只finger的操作 就再另外封装方法。 void FirstFingerDragEventHandler(DragGesture gesture) { //没有用触屏机器测试,但估计Fingers[0]并不是代表第一只点击屏幕的的手指, //finger.Index才是,记录第几只开始触发的手指。两三只手指同时触发时 //fingers[0].index是不同的。 FingerGestures.Finger finger = gesture.Fingers[0]; if (gesture.Phase == ContinuousGesturePhase.Started) { dragFingerIndex = finger.Index; } if (dragFingerIndex != finger.Index) { return; } //下面的内容保证是第一只手指触发的。 if (firstFingerDragMethods != null) { firstFingerDragMethods(gesture.Position, gesture.Selection, gesture.DeltaMove, ContinuousGesturePhaseConvertor(gesture.Phase)); } //第一只手指收起,重置第一只手指index。 if (gesture.Phase == ContinuousGesturePhase.Ended || gesture.Phase == ContinuousGesturePhase.None) { dragFingerIndex = -1; } }
float ComputeGapDelta(FingerGestures.Finger finger0, FingerGestures.Finger finger1, Vector2 refPos1, Vector2 refPos2) { Vector2 curDelta = finger0.Position - finger1.Position; Vector2 refDelta = refPos1 - refPos2; return(curDelta.magnitude - refDelta.magnitude); }
void Begin(T gesture, int clusterId, FingerGestures.IFingerList touches) { //Debug.Log( "Beginning " + this.GetType().Name ); gesture.ClusterId = clusterId; gesture.StartTime = Time.time; // sanity check #if UNITY_EDITOR if (gesture.Fingers.Count > 0) { Debug.LogWarning(this.name + " begin gesture with fingers list not properly released"); } #endif for (int i = 0; i < touches.Count; ++i) { FingerGestures.Finger finger = touches[i]; gesture.Fingers.Add(finger); Acquire(finger); } OnBegin(gesture, touches); gesture.PickStartSelection(Raycaster); gesture.State = GestureRecognitionState.Started; }
protected override bool CanBegin(PinchGesture gesture, FingerGestures.IFingerList touches) { if (!base.CanBegin(gesture, touches)) { return(false); } FingerGestures.Finger finger0 = touches[0]; FingerGestures.Finger finger1 = touches[1]; if (!FingerGestures.AllFingersMoving(finger0, finger1)) { return(false); } if (!FingersMovedInOppositeDirections(finger0, finger1)) { return(false); } float startGap = Vector2.SqrMagnitude(finger0.StartPosition - finger1.StartPosition); float curGap = Vector2.SqrMagnitude(finger0.Position - finger1.Position); if (FingerGestures.GetAdjustedPixelDistance(Mathf.Abs(startGap - curGap)) < (MinDistance * MinDistance)) { return(false); } return(true); }
// Find closest cluster within radius Cluster FindExistingCluster(FingerGestures.Finger finger) { Cluster best = null; float bestSqrDist = float.MaxValue; // account for higher pixel density touch screens float adjustedClusterRadius = FingerGestures.GetAdjustedPixelDistance(ClusterRadius); foreach (Cluster cluster in clusters) { float elapsedTime = finger.StarTime - cluster.StartTime; // temporal grouping criteria if (elapsedTime > TimeTolerance) { continue; } Vector2 centroid = cluster.Fingers.GetAveragePosition(); float sqrDist = Vector2.SqrMagnitude(finger.Position - centroid); if (sqrDist < bestSqrDist && sqrDist < (adjustedClusterRadius * adjustedClusterRadius)) { best = cluster; bestSqrDist = sqrDist; } } return(best); }
protected override bool CanBegin(FingerGestures.IFingerList touches) { if (!base.CanBegin(touches)) { return(false); } FingerGestures.Finger finger0 = touches[0]; FingerGestures.Finger finger1 = touches[1]; if (!FingerGestures.AllFingersMoving(finger0, finger1)) { return(false); } if (!FingersMovedInOppositeDirections(finger0, finger1)) { return(false); } float gapDelta = ComputeGapDelta(finger0, finger1, finger0.StartPosition, finger1.StartPosition); if (Mathf.Abs(gapDelta) < MinDistance) { return(false); } return(true); }
void CreatInk(Vector3 posFinger, FingerGestures.Finger finger) { GameObject ink = Instantiate(inkPrefab) as GameObject; ink.transform.parent = LogicManager.LevelManager.GetLevelObject().transform; Vector3 pos = Camera.main.ScreenToWorldPoint(posFinger); pos.z = 0; ink.transform.position = pos; Ink inkCom = ink.GetComponent <Ink>(); if (inkDict.ContainsKey(finger.Index)) { if (inkDict[finger.Index] != null) { inkDict[finger.Index].Fade(); } inkDict[finger.Index] = inkCom; } else { inkDict.Add(finger.Index, inkCom); } }
protected override void ProcessFinger(FingerGestures.Finger finger) { FingerHoverEvent e = GetEvent(finger); GameObject prevSelection = e.PreviousSelection; GameObject newSelection = finger.IsDown ? PickObject(finger.Position) : null; if (newSelection != prevSelection) { if (prevSelection) { FireEvent(e, FingerHoverPhase.Exit); } if (newSelection) { e.Selection = newSelection; e.Hit = LastHit; FireEvent(e, FingerHoverPhase.Enter); } } e.PreviousSelection = newSelection; }
public void OnDrag(DragGesture gesture) { //GuiTextDebug.Debug("OnDrag"); m_bIsPinch = false; m_bIsDrag = true; FingerGestures.Finger finger = gesture.Fingers[0]; if (gesture.Phase == ContinuousGesturePhase.Started) { m_iDragFingerIndex = finger.Index; ClearData(); FingerStart(gesture); } else if (finger.Index == m_iDragFingerIndex) { if (gesture.Phase == ContinuousGesturePhase.Updated) { FingerMove(gesture); } else { m_iDragFingerIndex = -1; //if (m_v3TouchPostions.Count >= 2) { FingerUp(gesture); } } } }
void OnFingerDown(FingerDownEvent e) { if (currentFinger == null) { currentFinger = e.Finger; GoToTouchTarget(e.Position, 1f); } }
// return signed angle in degrees between current finger position and ref positions static float SignedAngularGap(FingerGestures.Finger finger0, FingerGestures.Finger finger1, Vector2 refPos0, Vector2 refPos1) { Vector2 curDir = (finger0.Position - finger1.Position).normalized; Vector2 refDir = (refPos0 - refPos1).normalized; // check if we went past the minimum rotation amount treshold return(Mathf.Rad2Deg * FingerGestures.SignedAngle(refDir, curDir)); }
void OnFingerUp(FingerUpEvent e) { if (currentFinger == e.Finger) { currentFinger = null; GoToTouchTarget(e.Position, 1f); } }
void FingerGestures_OnFingerUp(int fingerIndex, Vector2 fingerPos, float timeHeldDown) { CheckSpawnParticles(fingerPos, fingerUpObject); // this shows how to access a finger object using its index // The finger object contains useful information not available through the event arguments that you might want to use FingerGestures.Finger finger = FingerGestures.GetFinger(fingerIndex); Debug.Log("Finger was lifted up at " + finger.Position + " and moved " + finger.DistanceFromStart.ToString("N0") + " pixels from its initial position at " + finger.StartPosition); }
protected override GestureRecognitionState OnRecognize(TwistGesture gesture, FingerGestures.IFingerList touches) { if (touches.Count != RequiredFingerCount) { gesture.DeltaRotation = 0; // fingers were lifted? if (touches.Count < RequiredFingerCount) { return(GestureRecognitionState.Ended); } // more fingers added, gesture failed return(GestureRecognitionState.Failed); } FingerGestures.Finger finger0 = touches[0]; FingerGestures.Finger finger1 = touches[1]; // dont do anything if both fingers arent moving if (Method == TwistMethod.Pivot) { if (gesture.Pivot == null) { Debug.LogWarning("Twist - pivot finger is null!", this); return(GestureRecognitionState.Failed); } if (gesture.Pivot != finger0 && gesture.Pivot != finger1) { Debug.LogWarning("Twist - lost track of pivot finger!", this); return(GestureRecognitionState.Failed); } gesture.Position = gesture.Pivot.Position; } else // standard twist { // mid point between finger0 and finger1 gesture.Position = 0.5f * (finger0.Position + finger1.Position); } gesture.DeltaRotation = SignedAngularGap(finger0, finger1, finger0.PreviousPosition, finger1.PreviousPosition); // only raise event when the twist angle has changed if (Mathf.Abs(gesture.DeltaRotation) > Mathf.Epsilon) { gesture.TotalRotation += gesture.DeltaRotation; RaiseEvent(gesture); } return(GestureRecognitionState.InProgress); }
protected override void OnBegin(TwistGesture gesture, FingerGestures.IFingerList touches) { FingerGestures.Finger finger0 = touches[0]; FingerGestures.Finger finger1 = touches[1]; gesture.StartPosition = 0.5f * (finger0.Position + finger1.Position); //( finger0.StartPosition + finger1.StartPosition ); gesture.Position = gesture.StartPosition; //0.5f * ( finger0.Position + finger1.Position ); //float angle = SignedAngularGap( finger0, finger1, finger0.StartPosition, finger1.StartPosition ); gesture.TotalRotation = 0; //angle; //Mathf.Sign( angle ) * MinRotation; gesture.DeltaRotation = 0; //angle; }
/// <summary> /// Check if all the touches in the list started recently /// </summary> /// <param name="touches">The touches to evaluate</param> /// <returns>True if the age of each touch in the list is under a set threshold</returns> protected bool Young(FingerGestures.IFingerList touches) { FingerGestures.Finger oldestTouch = touches.GetOldest(); if (oldestTouch == null) { return(false); } float elapsedTimeSinceFirstTouch = Time.time - oldestTouch.StarTime; return(elapsedTimeSinceFirstTouch < 0.25f); }
void OnFingerUp(FingerUpEvent e) { if (e.Selection == fingerUpObject) { SpawnParticles(fingerUpObject); } // The finger object contains useful information not available through the event arguments that you might want to use FingerGestures.Finger finger = e.Finger; Debug.Log("Finger was lifted up on " + (e.Selection ? e.Selection.name : "<nothing>") + " at " + finger.Position + " and moved " + finger.DistanceFromStart.ToString("N0") + " pixels from its initial position at " + finger.StartPosition + ". It was held down for " + e.TimeHeldDown + " seconds"); }
void OnDrag(DragGesture gesture) { FingerGestures.Finger finger = gesture.Fingers[0]; if (gesture.Phase == ContinuousGesturePhase.Started) { // dismiss this event if we're not interacting with our drag object if (gesture.Selection != this.gameObject) { return; } dragFingerIndex = finger.Index; // spawn some particles because it's cool. //SpawnParticles (dragObject); } else if (finger.Index == dragFingerIndex) { if (gesture.Phase == ContinuousGesturePhase.Updated) { // update the position by converting the current screen position of the finger to a world position on the Z = 0 plane ////////this.transform.rotation = GetWorldPos( gesture.Position ); //rotationRate = 3.0f; //leftInnerRotation = new Vector3 (0, 0, gesture.DeltaMove.y); //Debug.Log ("leftInnterRotation Type == " + leftInnerRotation.GetType ().ToString ()); this.transform.Rotate(gesture.DeltaMove.x, gesture.DeltaMove.y, 0, Space.Self); myQuaternionRotation = this.transform.rotation; myYRotation = this.transform.rotation.y; myXRotation = this.transform.rotation.x; myZRotation = this.transform.rotation.z; //dragObject.transform.rotation = GetWorldPos( gesture.Position ); print("dragObject.transform.rotation =" + this.transform.rotation); gestureYPosition = (gesture.Position.y - 400); } else { // reset our drag finger index dragFingerIndex = -1; // spawn some particles because it's cool. //SpawnParticles( dragObject ); } } }
protected override void OnBegin(PinchGesture gesture, FingerGestures.IFingerList touches) { FingerGestures.Finger finger0 = touches[0]; FingerGestures.Finger finger1 = touches[1]; gesture.StartPosition = 0.5f * (finger0.StartPosition + finger1.StartPosition); gesture.Position = 0.5f * (finger0.Position + finger1.Position); float prevGap = Vector2.Distance(finger0.PreviousPosition, finger1.PreviousPosition); float curGap = Vector2.Distance(finger0.Position, finger1.Position); gesture.Delta = curGap - prevGap; gesture.Gap = curGap; }
protected override void OnBegin(PinchGesture gesture, FingerGestures.IFingerList touches) { FingerGestures.Finger finger0 = touches[0]; FingerGestures.Finger finger1 = touches[1]; gesture.StartPosition = 0.5f * (finger0.StartPosition + finger1.StartPosition); gesture.Position = 0.5f * (finger0.Position + finger1.Position); gesture.Gap = Vector2.Distance(finger0.StartPosition, finger1.StartPosition); float curGap = Vector2.Distance(finger0.Position, finger1.Position); gesture.Delta = FingerGestures.GetAdjustedPixelDistance(DeltaScale * (curGap - gesture.Gap)); gesture.Gap = curGap; }
void HandleDrag( DragGesture gesture ) { if( !enabled ) return; if( gesture.Phase == ContinuousGesturePhase.Started ) { Dragging = true; draggingFinger = gesture.Fingers[0]; } else if( Dragging ) { // make sure this is the finger we started dragging with if( gesture.Fingers[0] != draggingFinger ) return; if( gesture.Phase == ContinuousGesturePhase.Updated ) { Transform tf = transform; Vector3 move = Vector3.zero; if( DragFromObjectCenter ) { Vector3 fingerPos3d; if( ProjectScreenPointOnDragPlane( tf.position, draggingFinger.Position, out fingerPos3d ) ) { move = fingerPos3d - tf.position; } } else { // figure out our previous screen space finger position Vector3 fingerPos3d, prevFingerPos3d; // convert these to world-space coordinates, and compute the amount of motion we need to apply to the object if( ProjectScreenPointOnDragPlane( tf.position, draggingFinger.PreviousPosition, out prevFingerPos3d ) && ProjectScreenPointOnDragPlane( tf.position, draggingFinger.Position, out fingerPos3d ) ) { move = fingerPos3d - prevFingerPos3d; } } if( rigidbody ) physxDragMove += move; // this will be used in FixedUpdate() to properly move the rigidbody else tf.position += move; } else { Dragging = false; } } }