Пример #1
0
        public void Update()
        {
            _input.Update();

            var newTouches = new List<Touch3D>();
            foreach (var touch2D in _input.Touches)
            {
                var ray = Camera.main.ScreenPointToRay(new Vector3(touch2D.Position.x, touch2D.Position.y));

                RaycastHit hitSurface;
                int surfaceLayerMask = 1 << LayerMask.NameToLayer("Surface");
                if (!Physics.Raycast(ray, out hitSurface, 100, surfaceLayerMask))
                    continue;
                var touch3D = new Touch3D
                {
                    Touch2D = touch2D,
                    Hit = hitSurface,
                    Ray = ray
                };
                var prevTouch = _touches.FirstOrDefault(t => t.Touch2D.Id == touch2D.Id);
                if (prevTouch != null)
                {
                    touch3D.PrevHit = prevTouch.Hit;
                    touch3D.PrevRay = prevTouch.Ray;
                }
                else
                {
                    touch3D.TouchFirstFrame = true;
                }
                newTouches.Add(touch3D);
            }
            _touches = newTouches;
        }
Пример #2
0
        public void Update()
        {
            _input.Update();

            var newTouches = new List <Touch3D>();

            foreach (var touch2D in _input.Touches)
            {
                var ray = Camera.main.ScreenPointToRay(new Vector3(touch2D.Position.x, touch2D.Position.y));

                RaycastHit hitSurface;
                int        surfaceLayerMask = 1 << LayerMask.NameToLayer("Surface");
                if (!Physics.Raycast(ray, out hitSurface, 100, surfaceLayerMask))
                {
                    continue;
                }
                var touch3D = new Touch3D
                {
                    Touch2D = touch2D,
                    Hit     = hitSurface,
                    Ray     = ray
                };
                var prevTouch = _touches.FirstOrDefault(t => t.Touch2D.Id == touch2D.Id);
                if (prevTouch != null)
                {
                    touch3D.PrevHit = prevTouch.Hit;
                    touch3D.PrevRay = prevTouch.Ray;
                }
                else
                {
                    touch3D.TouchFirstFrame = true;
                }
                newTouches.Add(touch3D);
            }
            _touches = newTouches;
        }