void Start() { Swipeable swipeable = GetComponent <Swipeable>(); swipeable.onSwipe = OnSwipe; swipeable.onTouched = OnTouched; }
void Resolve(Vector2 touchPos, int fingerID) { TouchInfo touchInfo = touchInfos.Find(t => t.touchID == fingerID); if (touchInfo == null) { return; } Vector3 startPosition = touchInfo.touchPos; Vector3 newPosition = touchPos; float distance = Vector3.Distance(startPosition, newPosition); float deltaTime = Time.time - touchInfo.time; Vector3 direction = newPosition - startPosition; direction.Normalize(); TouchResult touchResult = new TouchResult(distance, deltaTime, direction); Swipeable swipeable = touchInfo.touchedObject.GetComponent <Swipeable>(); if (distance < clickDistanceThreshold) { swipeable.Touched(touchResult); } else { swipeable.Swipe(touchResult); } touchInfos.Remove(touchInfo); }
// ------------------------------------------------------------------------------- public void OnDrag(PointerEventData eventData) { if (Swipeable.CheckForSwipe(eventData, SwipeCheckData)) { Hide(); SlidingPanel.Show(); } }
// ------------------------------------------------------------------------------- public void OnDrag(PointerEventData eventData) { if (Swipeable.CheckForSwipe(eventData, SwipeToCloseData)) { SlideOff(); } else if (Swipeable.CheckForSwipe(eventData, SwipeToOpenData)) { SlideOn(); } }
private static void PerformTap(Ray ray) { if (Physics.Raycast(ray, out RaycastHit hitInfo, float.MaxValue, sm_raycastMask)) { Swipeable component = hitInfo.transform.gameObject.GetComponent <Swipeable>(); if (component != null) { component.SwipeEntered(); } } }
void Awake() { if (!Util.DontDestroyOnLoad <Player>(gameObject)) { return; } Instance = this; _swipeable = GetComponent <Swipeable>(); SetSwipeEvent(); _level = Level.Instance; }
void AddTouch(Touch touch) { Ray ray = Camera.main.ScreenPointToRay(touch.position); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { GameObject hitGameObject = hit.collider.gameObject; Swipeable swipeable = hitGameObject.GetComponent <Swipeable>(); if (swipeable) { touchInfos.Add(new TouchInfo(touch.position, touch.fingerId, hitGameObject, Time.time)); } } }
void AddMouse() { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { GameObject hitGameObject = hit.collider.gameObject; Swipeable swipeable = hitGameObject.GetComponent <Swipeable>(); if (swipeable) { touchInfos.Add(new TouchInfo(Input.mousePosition, -1, hitGameObject, Time.time)); } } }
private void onTap(Transform tapTarget) { if (tapTarget == null) { return; } Debug.Log($"Tap on {tapTarget.name}"); Tappable tappable = tapTarget.GetComponent <Tappable>(); tappable?.onTap(); Swipeable swipeable = tapTarget.GetComponent <Swipeable>(); if (swipeable != null) { currentSwipe = swipeable.onSwipeStart(); } }
private void CheckSwipe(Touch touch) { touchPositions[touch.fingerId].Add(touch.position); Vector3 firstPosition = touchPositions[touch.fingerId][0]; Vector3 lastPosition = touchPositions[touch.fingerId][touchPositions[touch.fingerId].Count - 1]; Vector3 firstPoint = Camera.main.ScreenToWorldPoint(new Vector3(firstPosition.x, firstPosition.y, Camera.main.nearClipPlane)); Vector3 lastPoint = Camera.main.ScreenToWorldPoint(new Vector3(lastPosition.x, lastPosition.y, Camera.main.nearClipPlane)); Vector3 direction = lastPoint - firstPoint; swipeDirections.Add(direction); // Check if the touch hit a swipable Swipeable swipeable = GetSwipeable(raycastHits[touch.fingerId].Value); if (swipeable) { swipeable.OnSwipe(raycastHits[touch.fingerId].Value, direction); touchPositions[touch.fingerId].Clear(); touchPositions[touch.fingerId].Add(touch.position); } }
void Update() { if (IsInit || !unitID.IsReady()) { return; } IsInit = true; GameObject player = GameSharedData.GetLocalPlayer(); // don't do it for other players /* if (player.GetComponent<Unit_ID>().GetPlayerIndex() != GetComponent<Unit_ID>().GetPlayerIndex()) * { * enabled = false; * return; * }*/ Swipeable swipeable = GetComponent <Swipeable>(); swipeable.onSwipe = OnSwipe; swipeable.onTouched = OnTouched; }
public VerticalSwipe(Swipeable target, float completePixelLength) : base(target) { this.completePixelLength = completePixelLength; }
public HorizontalSwipe(Swipeable target, float completePixelLength) : base(target) { this.completePixelLength = completePixelLength; }
protected Swipe(Swipeable target) { this.target = target; }
public DiagonalSwipe(Swipeable target, float length) : base(target) { this.length = length; }