DistanceToRectangle() static public method

Determine the distance from the mouse position to the screen space rectangle specified by the 4 points.
static public DistanceToRectangle ( Vector2 screenPoints, Vector2 mousePos ) : float
screenPoints Vector2
mousePos Vector2
return float
Example #1
0
    /// <summary>
    /// Raycast into the screen and return a list of widgets in order from closest to farthest away.
    /// This is a slow operation and will consider ALL widgets underneath the specified game object.
    /// </summary>

    static public BetterList <UIWidget> Raycast(GameObject root, Vector2 mousePos)
    {
        BetterList <UIWidget> list = new BetterList <UIWidget>();
        UICamera uiCam             = UICamera.FindCameraForLayer(root.layer);

        if (uiCam != null)
        {
            Camera     cam     = uiCam.cachedCamera;
            UIWidget[] widgets = root.GetComponentsInChildren <UIWidget>();

            for (int i = 0; i < widgets.Length; ++i)
            {
                UIWidget w = widgets[i];

                Vector3[] corners = w.worldCorners;
                if (NGUIMath.DistanceToRectangle(corners, mousePos, cam) == 0f)
                {
                    list.Add(w);
                }
            }

            list.Sort(delegate(UIWidget w1, UIWidget w2) { return(w2.mDepth.CompareTo(w1.mDepth)); });
        }
        return(list);
    }
Example #2
0
    public static BetterList <UIWidget> Raycast(GameObject root, Vector2 mousePos)
    {
        var list   = new BetterList <UIWidget>();
        var camera = UICamera.FindCameraForLayer(root.layer);

        if (camera != null)
        {
            var cachedCamera = camera.cachedCamera;
            foreach (var widget in root.GetComponentsInChildren <UIWidget>())
            {
                if (NGUIMath.DistanceToRectangle(NGUIMath.CalculateWidgetCorners(widget), mousePos, cachedCamera) == 0f)
                {
                    list.Add(widget);
                }
            }

            if (f__amcache14 == null)
            {
                f__amcache14 = (w1, w2) => w2.mDepth.CompareTo(w1.mDepth);
            }

            list.Sort(f__amcache14);
        }

        return(list);
    }
Example #3
0
 static public int DistanceToRectangle_s(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 2)
         {
             UnityEngine.Vector2[] a1;
             checkType(l, 1, out a1);
             UnityEngine.Vector2 a2;
             checkType(l, 2, out a2);
             var ret = NGUIMath.DistanceToRectangle(a1, a2);
             pushValue(l, ret);
             return(1);
         }
         else if (argc == 3)
         {
             UnityEngine.Vector3[] a1;
             checkType(l, 1, out a1);
             UnityEngine.Vector2 a2;
             checkType(l, 2, out a2);
             UnityEngine.Camera a3;
             checkType(l, 3, out a3);
             var ret = NGUIMath.DistanceToRectangle(a1, a2, a3);
             pushValue(l, ret);
             return(1);
         }
         LuaDLL.luaL_error(l, "No matched override function to call");
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
Example #4
0
 public static float DistanceToRectangle(Vector3[] worldPoints, Vector2 mousePos, Camera cam)
 {
     Vector2[] array = new Vector2[4];
     for (int i = 0; i < 4; i++)
     {
         array[i] = cam.WorldToScreenPoint(worldPoints[i]);
     }
     return(NGUIMath.DistanceToRectangle(array, mousePos));
 }
Example #5
0
    /// <summary>
    /// Determine the distance from the mouse position to the world rectangle specified by the 4 points.
    /// </summary>

    static public float SceneViewDistanceToRectangle(Vector3[] worldPoints, Vector2 mousePos)
    {
        Vector2[] screenPoints = new Vector2[4];
        for (int i = 0; i < 4; ++i)
        {
            screenPoints[i] = HandleUtility.WorldToGUIPoint(worldPoints[i]);
        }
        return(NGUIMath.DistanceToRectangle(screenPoints, mousePos));
    }
Example #6
0
 static public int DistanceToRectangle_s(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 2)
         {
             UnityEngine.Vector2[] a1;
             checkArray(l, 1, out a1);
             UnityEngine.Vector2 a2;
             checkType(l, 2, out a2);
             var ret = NGUIMath.DistanceToRectangle(a1, a2);
             pushValue(l, true);
             pushValue(l, ret);
             return(2);
         }
         else if (argc == 3)
         {
             UnityEngine.Vector3[] a1;
             checkArray(l, 1, out a1);
             UnityEngine.Vector2 a2;
             checkType(l, 2, out a2);
             UnityEngine.Camera a3;
             checkType(l, 3, out a3);
             var ret = NGUIMath.DistanceToRectangle(a1, a2, a3);
             pushValue(l, true);
             pushValue(l, ret);
             return(2);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function DistanceToRectangle to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
    // Token: 0x06000257 RID: 599 RVA: 0x00020794 File Offset: 0x0001E994
    public static BetterList <UIWidget> Raycast(GameObject root, Vector2 mousePos)
    {
        BetterList <UIWidget> betterList = new BetterList <UIWidget>();
        UICamera uicamera = UICamera.FindCameraForLayer(root.layer);

        if (uicamera != null)
        {
            Camera cachedCamera = uicamera.cachedCamera;
            foreach (UIWidget uiwidget in root.GetComponentsInChildren <UIWidget>())
            {
                Vector3[] worldPoints = NGUIMath.CalculateWidgetCorners(uiwidget);
                if (NGUIMath.DistanceToRectangle(worldPoints, mousePos, cachedCamera) == 0f)
                {
                    betterList.Add(uiwidget);
                }
            }
            betterList.Sort((UIWidget w1, UIWidget w2) => w2.depth.CompareTo(w1.depth));
        }
        return(betterList);
    }
Example #8
0
 public unsafe static long $Invoke19(long instance, long *args)
 {
     return(GCHandledObjects.ObjectToGCHandle(NGUIMath.DistanceToRectangle((Vector3[])GCHandledObjects.GCHandleToPinnedArrayObject(*args), *(*(IntPtr *)(args + 1)), (Camera)GCHandledObjects.GCHandleToObject(args[2]))));
 }