Exemplo n.º 1
0
 /// <summary>Allows you to warp to the target object.</summary>
 public void WarpTo(SgtFloatingTarget target)
 {
     if (target != null)
     {
         WarpTo(target.CachedPoint.Position, target.WarpDistance);
     }
 }
        public void Pick(Vector2 pickScreenPoint)
        {
            var floatingCamera = default(SgtFloatingCamera);

            if (SgtFloatingCamera.TryGetCamera(1, ref floatingCamera) == true)
            {
                var warpTarget   = SgtFloatingTarget.FirstInstance;
                var bestTarget   = default(SgtFloatingTarget);
                var bestDistance = float.PositiveInfinity;

                for (var i = 0; i < SgtFloatingTarget.InstanceCount; i++)
                {
                    var localPosition = floatingCamera.CalculatePosition(ref warpTarget.CachedPoint.Position);
                    var screenPoint   = floatingCamera.CachedCamera.WorldToScreenPoint(localPosition);

                    if (screenPoint.z >= 0.0f)
                    {
                        var distance = ((Vector2)screenPoint - pickScreenPoint).sqrMagnitude;

                        if (distance <= bestDistance)
                        {
                            bestDistance = distance;
                            bestTarget   = warpTarget;
                        }
                    }

                    warpTarget = warpTarget.NextInstance;
                }

                if (bestTarget != null)
                {
                    var pickThreshold = Mathf.Min(Screen.width, Screen.height) * PickDistance;

                    if (bestDistance <= pickThreshold * pickThreshold)
                    {
                        CurrentTarget = bestTarget;
                    }
                }
                else
                {
                    CurrentTarget = null;
                }
            }
        }