public virtual void Hold(TouchCollider tc) { if (onDrag != null) { onDrag.Invoke(); } }
public virtual void PressDown(TouchCollider tc) { ShowPressed(); if (onDragBegin != null) { onDragBegin.Invoke(); } }
public void FollowDragInternal(TouchCollider tc) { if (!Dragged || surpressDragFollow || tc == null) { return; } rectTransform.position = tc.touch.position + delta; }
public virtual void Release(TouchCollider tc) { HidePressed(); if (onDragRelease != null) { onDragRelease.Invoke(); } }
/// <param name="tc"></param> /// <returns>false if the TouchCollider is not actually holding</returns> public virtual bool Hold(TouchCollider tc) { if (onDrag != null) { onDrag.Invoke(); } return(true); }
/// <param name="tc"></param> /// <returns>false if the TouchCollider did not actually press</returns> public virtual bool PressDown(TouchCollider tc) { ShowPressed(); if (onDragBegin != null) { onDragBegin.Invoke(); } return(true); }
public override void Release(TouchCollider tc) { FollowDragInternal(tc); if (tc == null || tc.touch.phase == TouchPhase.Ended || tc.touch.phase == TouchPhase.Canceled) { Dragged = false; base.Release(tc); } }
/// <param name="tc"></param> /// <returns>false if the TouchCollider did not actually release</returns> public virtual bool Release(TouchCollider tc) { HidePressed(); if (onDragRelease != null) { onDragRelease.Invoke(); } return(true); }
public bool Release(Vector2 position, TouchCollider tc) { FollowDragInternal(position); if (tc == null || tc.touch.phase == TouchPhase.Ended || tc.touch.phase == TouchPhase.Canceled) { Dragged = false; return(base.Release(tc)); } return(false); }
public void FollowDrag() { if (surpressDragFollow) { return; } TouchCollider tc = TouchGuiSystem.Instance().GetTouch(fingerId); FollowDragInternal(tc); }
public override void PressDown(TouchCollider tc) { if (Dragged) { Debug.Log("ignored touch before drag finished"); return; } fingerId = triggeringCollider.touch.fingerId; base.PressDown(tc); Dragged = true; delta = (Vector2)rectTransform.position - triggeringCollider.touch.position; }
public TouchCollider GetTouch(int fingerId) { for (int i = 0; i < touchColliders.Count; ++i) { TouchCollider tc = touchColliders[i]; if (tc.touch.phase < TouchPhase.Ended && tc.touch.fingerId == fingerId) { return(tc); } } return(null); }
private TouchCollider Notify(Collider2D c) { triggeringCollider = c.GetComponent <TouchCollider>(); if (triggeringCollider == null) { Debug.LogError(c.gameObject + " is touching " + this); } else { triggeringCollider.touched = this; } return(triggeringCollider); }
public void FollowDrag() { if (surpressDragFollow) { return; } TouchCollider tc = TouchGuiSystem.Instance().GetTouch(fingerId); if (tc == null) { return; } FollowDragInternal(tc.touch.position); }
public void UpdateTouch(int index, Touch t) { if (touchColliders.Count <= index) { TouchCollider tc = CreateTouchCollider(); tc.name = "touch " + index; tc.transform.SetParent(touchCanvas); touchColliders.Add(tc); } TouchCollider touch = touchColliders[index]; touch.touch = t; touch.MarkValid(true); touch.transform.position = t.position; }
public TouchCollider CreateTouchCollider() { if (prefab_touchCollider == null) { GameObject touchObj = new GameObject("touch"); touchObj.layer = LayerMask.NameToLayer("UI"); touchObj.AddComponent <CircleCollider2D>(); Rigidbody2D r2d = touchObj.AddComponent <Rigidbody2D>(); r2d.bodyType = RigidbodyType2D.Kinematic; prefab_touchCollider = touchObj.AddComponent <TouchCollider>(); prefab_touchCollider.MarkValid(false); } GameObject go = Instantiate(prefab_touchCollider.gameObject); return(go.GetComponent <TouchCollider>()); }
public void SortTouchCollidersToMatchTouchArray(Touch[] touches) { // figure out which touch collider is closest to which touch List <TouchColliderDist>[] sortPerTouch = new List <TouchColliderDist> [touches.Length]; for (int i = 0; i < touches.Length; ++i) { Vector2 p = touches[i].position; List <TouchColliderDist> order = new List <TouchColliderDist>(touchColliders.Count); for (int c = 0; c < touchColliders.Count; ++c) { order.Add(new TouchColliderDist { tc = touchColliders[c], dist = ManhattanDistance(p, touchColliders[c].transform.position) }); } order.Sort((a, b) => a.dist.CompareTo(b.dist)); sortPerTouch[i] = order; } // find the best matches for each touch, and match those up with the touch, removing them as options for other touches int count = Mathf.Min(touches.Length, touchColliders.Count); for (int i = 0; i < count; ++i) { int bestIndex = FindIndexOfSmallest(sortPerTouch, sortList => sortList[0].dist); TouchCollider claimedTc = sortPerTouch[bestIndex][0].tc; System.Array.ForEach(sortPerTouch, sortList => sortList.RemoveAt(sortList.FindIndex(e => e.tc == claimedTc))); touchColliders[i] = claimedTc; } // if not all the touch colliders were assigned to a touch, take the remainder and put them back in the touch collider list in any order really (they're about to be deactivated) if (sortPerTouch[0].Count > 0) { List <TouchColliderDist> remainder = sortPerTouch[0]; for (int i = touches.Length; i < touchColliders.Count; ++i) { int lastOne = remainder.Count - 1; touchColliders[i] = remainder[lastOne].tc; remainder.RemoveAt(lastOne); } } }
public override bool Hold(TouchCollider tc) { return(Hold(tc.touch.position)); }
public override bool PressDown(TouchCollider tc) { return(PressDown(tc.touch.position)); }
public override void Hold(TouchCollider tc) { base.Hold(tc); FollowDragInternal(tc); }
public override bool Release(TouchCollider tc) { return(Release(tc.touch.position, tc)); }