コード例 #1
0
        /// <inheritdoc />
        public ITouchHit GetTouchHit(Transform value)
        {
            var result = new TouchHit();

            result.InitWith(value);
            return(result);
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
ファイル: TouchHit.cs プロジェクト: keangame/TouchScript
 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;
 }
コード例 #5
0
ファイル: TouchHit.cs プロジェクト: vousk/TouchScript
        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);
        }
コード例 #6
0
ファイル: CameraLayer2D.cs プロジェクト: keangame/TouchScript
        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;
        }
コード例 #7
0
ファイル: CameraLayer.cs プロジェクト: ludo6577/NumericWall
        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;
        }
コード例 #8
0
ファイル: TouchHit.cs プロジェクト: keangame/TouchScript
 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;
 }
コード例 #9
0
ファイル: CameraLayer2D.cs プロジェクト: ludo6577/NumericWall
        /// <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;
        }
コード例 #10
0
    // 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);
        };
    }
コード例 #11
0
ファイル: TouchHit.cs プロジェクト: vousk/TouchScript
        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);
        }
コード例 #12
0
ファイル: UILayer.cs プロジェクト: guozanhua/TouchScript
        /// <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;
        }
コード例 #13
0
ファイル: CameraLayer.cs プロジェクト: ludo6577/NumericWall
        /// <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;
        }
コード例 #14
0
ファイル: TouchLayer.cs プロジェクト: guozanhua/TouchScript
 /// <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;
 }
コード例 #15
0
ファイル: TouchLayer.cs プロジェクト: guozanhua/TouchScript
 /// <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;
 }
コード例 #16
0
        /// <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;
        }
コード例 #17
0
 /// <inheritdoc />
 public bool GetHitTarget(Vector2 position, out TouchHit hit)
 {
     TouchLayer layer;
     return GetHitTarget(position, out hit, out layer);
 }
コード例 #18
0
ファイル: UILayer.cs プロジェクト: guozanhua/TouchScript
        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;
        }
コード例 #19
0
ファイル: TouchLayer.cs プロジェクト: keangame/TouchScript
 /// <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;
 }
コード例 #20
0
ファイル: HitTest.cs プロジェクト: RabitBox/FlickBattler
 /// <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;
 }
コード例 #21
0
ファイル: Untouchable.cs プロジェクト: keangame/TouchScript
 /// <inheritdoc />
 public override ObjectHitResult IsHit(TouchHit hit)
 {
     return DiscardTouch ? ObjectHitResult.Discard : ObjectHitResult.Miss;
 }
コード例 #22
0
ファイル: HitTest.cs プロジェクト: vousk/TouchScript
 /// <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);
 }
コード例 #23
0
        /// <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;
        }
コード例 #24
0
ファイル: TapGesture.cs プロジェクト: keangame/TouchScript
        /// <inheritdoc />
        public override bool GetTargetHitResult(out TouchHit hit)
        {
            if (State == GestureState.Ended)
            {
                hit = cachedTargetHitResult;
                return true;
            }

            return base.GetTargetHitResult(out hit);
        }
コード例 #25
0
 /// <inheritdoc />
 public ITouchHit GetTouchHit(Transform value)
 {
     var result = new TouchHit();
     result.InitWith(value);
     return result;
 }
コード例 #26
0
ファイル: Gesture.cs プロジェクト: oafkad/TouchScript
 /// <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);
 }
コード例 #27
0
 /// <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);
コード例 #28
0
ファイル: Gesture.cs プロジェクト: oafkad/TouchScript
        /// <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;
        }
コード例 #29
0
ファイル: Gesture.cs プロジェクト: keangame/TouchScript
        /// <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;
        }
コード例 #30
0
 /// <inheritdoc />
 public override ObjectHitResult IsHit(TouchHit hit)
 {
     return DiscardTouch ? ObjectHitResult.Discard : ObjectHitResult.Miss;
 }
コード例 #31
0
ファイル: TouchManager.cs プロジェクト: keangame/TouchScript
        /// <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;
        }