/// <inheritdoc /> public ITouchHit GetTouchHit(Transform value) { var result = new TouchHit(); result.InitWith(value); return(result); }
/// <inheritdoc /> public override LayerHitResult Hit(Vector2 position, out TouchHit hit) { if (base.Hit(position, out hit) == LayerHitResult.Miss) return LayerHitResult.Miss; if (_camera == null) return LayerHitResult.Error; if (_camera.enabled == false || _camera.gameObject.activeInHierarchy == false) return LayerHitResult.Miss; if (!_camera.pixelRect.Contains(position)) return LayerHitResult.Miss; var ray = _camera.ScreenPointToRay(position); return castRay(ray, out hit); }
/// <inheritdoc /> public override LayerHitResult Hit(Vector2 position, out TouchHit hit) { hit = new TouchHit(); if (camera == null) return LayerHitResult.Error; if (camera.enabled == false || camera.gameObject.active == false) return LayerHitResult.Miss; if (!camera.pixelRect.Contains(position)) return LayerHitResult.Miss; var ray = camera.ScreenPointToRay(new Vector3(position.x, position.y, camera.nearClipPlane)); return castRay(ray, out hit); }
public static TouchHit FromRaycastHit2D(RaycastHit2D value) { var result = new TouchHit() { Type = HitType.Hit2D, Collider2d = value.collider, Distance = value.fraction, Normal = -Vector3.forward, Point = value.point, Rigidbody2D = value.rigidbody, Transform = value.collider.transform }; return result; }
public static TouchHit FromRaycastHit2D(RaycastHit2D value) { var result = new TouchHit() { Type = HitType.Hit2D, Collider2d = value.collider, Distance = value.fraction, Normal = -Vector3.forward, Point = value.point, Rigidbody2D = value.rigidbody, Transform = value.collider.transform }; return(result); }
protected override LayerHitResult castRay(Ray ray, out TouchHit hit) { hit = new TouchHit(); var hits = Physics2D.GetRayIntersectionAll(ray, float.PositiveInfinity, LayerMask); if (hits.Length == 0) return LayerHitResult.Miss; if (hits.Length > 1) hits = sortHits(hits); var success = false; foreach (var raycastHit in hits) { hit = TouchHit.FromRaycastHit2D(raycastHit); var hitTests = raycastHit.transform.GetComponents<HitTest>(); if (hitTests.Length == 0) { success = true; break; } var hitResult = HitTest.ObjectHitResult.Error; foreach (var test in hitTests) { hitResult = test.IsHit(hit); if (hitResult == HitTest.ObjectHitResult.Hit || hitResult == HitTest.ObjectHitResult.Discard) { break; } } if (hitResult == HitTest.ObjectHitResult.Hit) { success = true; break; } if (hitResult == HitTest.ObjectHitResult.Discard) { break; } } if (success) { return LayerHitResult.Hit; } return LayerHitResult.Miss; }
private HitTest.ObjectHitResult doHit(RaycastHit raycastHit, out TouchHit hit) { hit = new TouchHit(raycastHit); raycastHit.transform.GetComponents(tmpHitTestList); var count = tmpHitTestList.Count; if (count == 0) return HitTest.ObjectHitResult.Hit; var hitResult = HitTest.ObjectHitResult.Hit; for (var i = 0; i < count; i++) { var test = tmpHitTestList[i]; if (!test.enabled) continue; hitResult = test.IsHit(hit); if (hitResult == HitTest.ObjectHitResult.Miss || hitResult == HitTest.ObjectHitResult.Discard) break; } return hitResult; }
public static TouchHit FromRaycastHit(RaycastHit value) { var result = new TouchHit() { Type = HitType.Hit3D, BarycentricCoordinate = value.barycentricCoordinate, Collider = value.collider, Distance = value.distance, LightmapCoord = value.lightmapCoord, Normal = value.normal, Point = value.point, Rigidbody = value.rigidbody, TextureCoord = value.textureCoord, TextureCoord2 = value.textureCoord2, Transform = value.collider.transform, TriangleIndex = value.triangleIndex }; return result; }
/// <inheritdoc /> protected override LayerHitResult castRay(Ray ray, out TouchHit hit) { hit = default(TouchHit); var raycastHits = Physics2D.GetRayIntersectionAll(ray, float.PositiveInfinity, LayerMask); Debug.DrawRay(ray.origin, ray.direction, Color.green); if (raycastHits.Length == 0) return LayerHitResult.Miss; if (raycastHits.Length > 1) { sortHits(raycastHits); RaycastHit2D raycastHit = default(RaycastHit2D); var i = 0; while (i < sortedHits.Count) { raycastHit = sortedHits[i]; switch (doHit(raycastHit, out hit)) { case HitTest.ObjectHitResult.Hit: return LayerHitResult.Hit; case HitTest.ObjectHitResult.Discard: return LayerHitResult.Miss; } i++; } } else { switch (doHit(raycastHits[0], out hit)) { case HitTest.ObjectHitResult.Hit: return LayerHitResult.Hit; case HitTest.ObjectHitResult.Error: return LayerHitResult.Error; default: return LayerHitResult.Miss; } } return LayerHitResult.Miss; }
// Use this for initialization void Start() { transformListener.Transformed += (object sender, System.EventArgs e) => { Vector3 posDelta = transformListener.LocalDeltaPosition; posDelta.z = 0; this.transform.position += posDelta; this.transform.localScale *= transformListener.DeltaScale; this.transform.eulerAngles += new Vector3(0, -transformListener.DeltaRotation, 0); }; planeTapListener.Tapped += (object sender, System.EventArgs e) => { TouchScript.Hit.TouchHit hitResult = new TouchScript.Hit.TouchHit(); planeTapListener.GetTargetHitResult(planeTapListener.ScreenPosition, out hitResult); howie.MoveTo(hitResult.Point.x, hitResult.Point.z); }; }
public static TouchHit FromRaycastHit(RaycastHit value) { var result = new TouchHit() { Type = HitType.Hit3D, BarycentricCoordinate = value.barycentricCoordinate, Collider = value.collider, Distance = value.distance, LightmapCoord = value.lightmapCoord, Normal = value.normal, Point = value.point, Rigidbody = value.rigidbody, TextureCoord = value.textureCoord, TextureCoord2 = value.textureCoord2, Transform = value.collider.transform, TriangleIndex = value.triangleIndex }; return(result); }
/// <inheritdoc /> public override LayerHitResult Hit(Vector2 position, out TouchHit hit) { if (base.Hit(position, out hit) == LayerHitResult.Miss) return LayerHitResult.Miss; if (eventSystem == null) return LayerHitResult.Error; if (pointerDataCache == null) pointerDataCache = new PointerEventData(eventSystem); pointerDataCache.position = position; eventSystem.RaycastAll(pointerDataCache, raycastResultCache); var count = raycastResultCache.Count; if (count == 0) return LayerHitResult.Miss; if (count > 1) { for (var i = 0; i < count; ++i) { var raycastHit = raycastResultCache[i]; switch (doHit(raycastHit, out hit)) { case HitTest.ObjectHitResult.Hit: return LayerHitResult.Hit; case HitTest.ObjectHitResult.Discard: return LayerHitResult.Miss; } } } else { switch (doHit(raycastResultCache[0], out hit)) { case HitTest.ObjectHitResult.Hit: return LayerHitResult.Hit; case HitTest.ObjectHitResult.Error: return LayerHitResult.Error; default: return LayerHitResult.Miss; } } return LayerHitResult.Miss; }
/// <inheritdoc /> protected override LayerHitResult castRay(Ray ray, out TouchHit hit) { hit = default(TouchHit); var raycastHits = Physics.RaycastAll(ray, float.PositiveInfinity, LayerMask); if (raycastHits.Length == 0) return LayerHitResult.Miss; if (raycastHits.Length > 1) { sortHits(raycastHits); RaycastHit raycastHit = default(RaycastHit); var i = 0; while (i < sortedHits.Count) { raycastHit = sortedHits[i]; switch (doHit(raycastHit, out hit)) { case HitTest.ObjectHitResult.Hit: return LayerHitResult.Hit; case HitTest.ObjectHitResult.Discard: return LayerHitResult.Miss; } i++; } } else { switch (doHit(raycastHits[0], out hit)) { case HitTest.ObjectHitResult.Hit: return LayerHitResult.Hit; case HitTest.ObjectHitResult.Error: return LayerHitResult.Error; default: return LayerHitResult.Miss; } } return LayerHitResult.Miss; }
/// <summary> /// Called when a layer is touched to query the layer if this touch hits something. /// </summary> /// <param name="touch">Touch.</param> /// <param name="hit">Hit result.</param> /// <returns><see cref="LayerHitResult.Hit"/>, if an object is hit, <see cref="LayerHitResult.Miss"/> or <see cref="LayerHitResult.Error"/> otherwise.</returns> /// <remarks>This method may also be used to update some internal state or resend this event somewhere.</remarks> protected virtual LayerHitResult beginTouch(TouchPoint touch, out TouchHit hit) { var result = Hit(touch.Position, out hit); return result; }
/// <summary> /// Checks if a point in screen coordinates hits something in this layer. /// </summary> /// <param name="position">Position in screen coordinates.</param> /// <param name="hit">Hit result.</param> /// <returns><see cref="LayerHitResult.Hit"/>, if an object is hit, <see cref="LayerHitResult.Miss"/> or <see cref="LayerHitResult.Error"/> otherwise.</returns> public virtual LayerHitResult Hit(Vector2 position, out TouchHit hit) { hit = default(TouchHit); if (enabled == false || gameObject.activeInHierarchy == false) return LayerHitResult.Miss; return LayerHitResult.Error; }
/// <inheritdoc /> public bool GetHitTarget(Vector2 position, out TouchHit hit, out TouchLayer layer) { hit = default(TouchHit); layer = null; for (var i = 0; i < layerCount; i++) { var touchLayer = layers[i]; if (touchLayer == null) continue; TouchHit _hit; if (touchLayer.Hit(position, out _hit) == TouchLayer.LayerHitResult.Hit) { hit = _hit; layer = touchLayer; return true; } } return false; }
/// <inheritdoc /> public bool GetHitTarget(Vector2 position, out TouchHit hit) { TouchLayer layer; return GetHitTarget(position, out hit, out layer); }
private HitTest.ObjectHitResult doHit(RaycastResult raycastHit, out TouchHit hit) { hit = new TouchHit(raycastHit); if (!(raycastHit.module is GraphicRaycaster)) return HitTest.ObjectHitResult.Miss; var go = raycastHit.gameObject; if (go == null) return HitTest.ObjectHitResult.Miss; go.GetComponents(tmpHitTestList); var count = tmpHitTestList.Count; if (count == 0) return HitTest.ObjectHitResult.Hit; var hitResult = HitTest.ObjectHitResult.Hit; for (var i = 0; i < count; i++) { var test = tmpHitTestList[i]; if (!test.enabled) continue; hitResult = test.IsHit(hit); if (hitResult == HitTest.ObjectHitResult.Miss || hitResult == HitTest.ObjectHitResult.Discard) break; } return hitResult; }
/// <summary> /// Checks if a point hits something in this layer. /// </summary> /// <param name="position">Position in screen coordinates.</param> /// <param name="hit">Raycast result.</param> /// <returns>Hit, if an object is hit, Miss or Error otherwise.</returns> public virtual LayerHitResult Hit(Vector2 position, out TouchHit hit) { hit = new TouchHit(); return LayerHitResult.Miss; }
/// <summary> /// Determines whether a touch point hit the object. /// </summary> /// <param name="hit"> Data from a raycast. </param> /// <returns> <see cref="ObjectHitResult.Hit"/> if touch point hits the object, <see cref="ObjectHitResult.Miss"/> if it doesn't, <see cref="ObjectHitResult.Discard"/> if it doesn't and this touch must be ignored, Error otherwise. </returns> public virtual ObjectHitResult IsHit(TouchHit hit) { return ObjectHitResult.Hit; }
/// <inheritdoc /> public override ObjectHitResult IsHit(TouchHit hit) { return DiscardTouch ? ObjectHitResult.Discard : ObjectHitResult.Miss; }
/// <summary> /// Determines whether a touch point hit the object. /// </summary> /// <param name="hit">Data from a raycast.</param> /// <returns><see cref="ObjectHitResult.Hit"/> if touch point hits the object, <see cref="ObjectHitResult.Miss"/> if it doesn't, <see cref="ObjectHitResult.Discard"/> if it doesn't and this touch must be ignored, Error otherwise.</returns> public virtual ObjectHitResult IsHit(TouchHit hit) { return(ObjectHitResult.Hit); }
/// <inheritdoc /> public override LayerHitResult Hit(Vector2 position, out TouchHit hit) { if (base.Hit(position, out hit) == LayerHitResult.Miss) return LayerHitResult.Miss; if (_camera != null) { if (!_camera.pixelRect.Contains(position)) return LayerHitResult.Miss; } hit = new TouchHit(transform); transform.GetComponents(tmpHitTestList); var count = tmpHitTestList.Count; if (count == 0) return LayerHitResult.Hit; for (var i = 0; i < count; i++) { var test = tmpHitTestList[i]; if (!test.enabled) continue; var hitResult = test.IsHit(hit); if (hitResult == HitTest.ObjectHitResult.Miss || hitResult == HitTest.ObjectHitResult.Discard) return LayerHitResult.Miss; } return LayerHitResult.Hit; }
/// <inheritdoc /> public override bool GetTargetHitResult(out TouchHit hit) { if (State == GestureState.Ended) { hit = cachedTargetHitResult; return true; } return base.GetTargetHitResult(out hit); }
/// <inheritdoc /> public ITouchHit GetTouchHit(Transform value) { var result = new TouchHit(); result.InitWith(value); return result; }
/// <summary> /// Gets result of casting a ray from gesture touch points centroid screen position. /// </summary> /// <param name="hit"> Raycast result </param> /// <returns> <c>true</c> if ray hits gesture's target; <c>false</c> otherwise. </returns> public virtual bool GetTargetHitResult(out TouchHit hit) { return GetTargetHitResult(ScreenPosition, out hit); }
/// <summary> /// Casts a ray from camera position. /// </summary> /// <param name="ray">The ray.</param> /// <param name="hit">Hit information if the ray has hit something.</param> /// <returns>Hit result.</returns> protected abstract LayerHitResult castRay(Ray ray, out TouchHit hit);
/// <summary> /// Gets result of casting a ray from specific screen position. /// </summary> /// <param name="position"> The position. </param> /// <param name="hit"> Raycast result. </param> /// <returns> <c>true</c> if ray hits gesture's target; <c>false</c> otherwise. </returns> public virtual bool GetTargetHitResult(Vector2 position, out TouchHit hit) { if (layer != null) { if (layer.Hit(position, out hit) != TouchLayer.LayerHitResult.Hit) return false; } else { TouchLayer l = null; if (!touchManager.GetHitTarget(position, out hit, out l)) return false; } if (cachedTransform == hit.Transform || hit.Transform.IsChildOf(cachedTransform)) return true; return false; }
/// <summary> /// Gets result of casting a ray from specific screen position. /// </summary> /// <param name="position">The position.</param> /// <param name="hit">Raycast result.</param> /// <returns>true if ray hits gesture's target; otherwise, false.</returns> public virtual bool GetTargetHitResult(Vector2 position, out TouchHit hit) { TouchLayer layer = null; if (!TouchManager.Instance.GetHitTarget(position, out hit, out layer)) return false; if (transform == hit.Transform || hit.Transform.IsChildOf(transform)) return true; return false; }
/// <summary> /// Checks if the touch has hit something. /// </summary> /// <param name="position">Touch point screen position.</param> /// <param name="hit">Output RaycastHit.</param> /// <param name="layer">Output touch layer which was hit.</param> /// <returns>True if something was hit.</returns> public bool GetHitTarget(Vector2 position, out TouchHit hit, out TouchLayer layer) { hit = new TouchHit(); layer = null; foreach (var touchLayer in layers) { if (touchLayer == null) continue; TouchHit _hit; if (touchLayer.Hit(position, out _hit) == TouchLayer.LayerHitResult.Hit) { hit = _hit; layer = touchLayer; return true; } } return false; }