SetToNearest() public method

Set the anchor's value to the nearest of the 3 possible choices of (left, center, right) or (bottom, center, top).
public SetToNearest ( float abs0, float abs1, float abs2 ) : void
abs0 float
abs1 float
abs2 float
return void
    static int SetToNearest(IntPtr L)
    {
        int count = LuaDLL.lua_gettop(L);

        if (count == 4)
        {
            UIRect.AnchorPoint obj = (UIRect.AnchorPoint)LuaScriptMgr.GetNetObjectSelf(L, 1, "UIRect.AnchorPoint");
            float arg0             = (float)LuaScriptMgr.GetNumber(L, 2);
            float arg1             = (float)LuaScriptMgr.GetNumber(L, 3);
            float arg2             = (float)LuaScriptMgr.GetNumber(L, 4);
            obj.SetToNearest(arg0, arg1, arg2);
            return(0);
        }
        else if (count == 7)
        {
            UIRect.AnchorPoint obj = (UIRect.AnchorPoint)LuaScriptMgr.GetNetObjectSelf(L, 1, "UIRect.AnchorPoint");
            float arg0             = (float)LuaScriptMgr.GetNumber(L, 2);
            float arg1             = (float)LuaScriptMgr.GetNumber(L, 3);
            float arg2             = (float)LuaScriptMgr.GetNumber(L, 4);
            float arg3             = (float)LuaScriptMgr.GetNumber(L, 5);
            float arg4             = (float)LuaScriptMgr.GetNumber(L, 6);
            float arg5             = (float)LuaScriptMgr.GetNumber(L, 7);
            obj.SetToNearest(arg0, arg1, arg2, arg3, arg4, arg5);
            return(0);
        }
        else
        {
            LuaDLL.luaL_error(L, "invalid arguments to method: UIRect.AnchorPoint.SetToNearest");
        }

        return(0);
    }
Exemplo n.º 2
0
    /// <summary>
    /// Convenience function that switches the anchor mode and ensures that dimensions are kept intact.
    /// </summary>

    static void UpdateVerticalAnchor(UIRect r, UIRect.AnchorPoint anchor)
    {
        // Update the target
        if (anchor.target == null)
        {
            return;
        }

        // Update the rect
        anchor.rect = anchor.target.GetComponent <UIRect>();

        // Continue only if we have a parent to work with
        Transform parent = r.cachedTransform.parent;

        if (parent == null)
        {
            return;
        }

        bool inverted = (anchor == r.topAnchor);
        int  i0       = inverted ? 1 : 0;
        int  i1       = inverted ? 2 : 3;

        // Calculate the bottom side
        Vector3[] myCorners = r.worldCorners;
        Vector3   localPos  = parent.InverseTransformPoint(Vector3.Lerp(myCorners[i0], myCorners[i1], 0.5f));

        if (anchor.rect == null)
        {
            // Anchored to a simple transform
            Vector3 remotePos = parent.InverseTransformPoint(anchor.target.position);
            anchor.absolute = Mathf.FloorToInt(localPos.y - remotePos.y + 0.5f);
            anchor.relative = inverted ? 1f : 0f;
        }
        else
        {
            // Anchored to a rectangle -- must anchor to the same side
            Vector3[] targetCorners = anchor.rect.worldCorners;

            // We want to choose the side with the shortest offset
            Vector3 side0 = parent.InverseTransformPoint(Vector3.Lerp(targetCorners[0], targetCorners[3], 0.5f));
            Vector3 side1 = parent.InverseTransformPoint(Vector3.Lerp(targetCorners[1], targetCorners[2], 0.5f));

            float val0 = localPos.y - side0.y;
            float val2 = localPos.y - side1.y;
            float val1 = localPos.y - Vector3.Lerp(side0, side1, 0.5f).y;

            anchor.SetToNearest(val0, val1, val2);
        }
    }
Exemplo n.º 3
0
 static public int SetToNearest(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 4)
         {
             UIRect.AnchorPoint self = (UIRect.AnchorPoint)checkSelf(l);
             System.Single      a1;
             checkType(l, 2, out a1);
             System.Single a2;
             checkType(l, 3, out a2);
             System.Single a3;
             checkType(l, 4, out a3);
             self.SetToNearest(a1, a2, a3);
             pushValue(l, true);
             return(1);
         }
         else if (argc == 7)
         {
             UIRect.AnchorPoint self = (UIRect.AnchorPoint)checkSelf(l);
             System.Single      a1;
             checkType(l, 2, out a1);
             System.Single a2;
             checkType(l, 3, out a2);
             System.Single a3;
             checkType(l, 4, out a3);
             System.Single a4;
             checkType(l, 5, out a4);
             System.Single a5;
             checkType(l, 6, out a5);
             System.Single a6;
             checkType(l, 7, out a6);
             self.SetToNearest(a1, a2, a3, a4, a5, a6);
             pushValue(l, true);
             return(1);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 4
0
    /// <summary>
    /// Convenience function that switches the anchor mode and ensures that dimensions are kept intact.
    /// </summary>

    static void UpdateHorizontalAnchor(UIRect r, UIRect.AnchorPoint anchor)
    {
        // Update the target
        if (anchor.target == null)
        {
            return;
        }

        // Update the rect
        anchor.rect = anchor.target.GetComponent <UIRect>();

        // Continue only if we have a parent to work with
        Transform parent = r.cachedTransform.parent;

        if (parent == null)
        {
            return;
        }

        bool inverted = (anchor == r.rightAnchor);
        int  i0       = inverted ? 2 : 0;
        int  i1       = inverted ? 3 : 1;

        // Calculate the left side
        Vector3[] myCorners = r.worldCorners;
        Vector3   localPos  = parent.InverseTransformPoint(Vector3.Lerp(myCorners[i0], myCorners[i1], 0.5f));

        if (anchor.rect != null)
        {
            // Anchored to a rectangle -- must anchor to the same side
            Vector3[] targetCorners = anchor.rect.worldCorners;

            // We want to choose the side with the shortest offset
            Vector3 side0 = parent.InverseTransformPoint(Vector3.Lerp(targetCorners[0], targetCorners[1], 0.5f));
            Vector3 side1 = parent.InverseTransformPoint(Vector3.Lerp(targetCorners[2], targetCorners[3], 0.5f));

            float val0 = localPos.x - side0.x;
            float val2 = localPos.x - side1.x;
            float val1 = localPos.x - Vector3.Lerp(side0, side1, 0.5f).x;

            anchor.SetToNearest(val0, val1, val2);
        }
        else if (anchor.target.camera != null)
        {
            Vector3[] sides = anchor.target.camera.GetSides(parent);
            Vector3   side0 = sides[0];
            Vector3   side1 = sides[2];

            float val0 = localPos.x - side0.x;
            float val2 = localPos.x - side1.x;
            float val1 = localPos.x - Vector3.Lerp(side0, side1, 0.5f).x;

            anchor.SetToNearest(val0, val1, val2);
        }
        else
        {
            // Anchored to a simple transform
            Vector3 remotePos = anchor.target.position;
            if (anchor.targetCam != null)
            {
                remotePos = anchor.targetCam.WorldToViewportPoint(remotePos);
            }
            if (r.anchorCamera != null)
            {
                remotePos = r.anchorCamera.ViewportToWorldPoint(remotePos);
            }
            remotePos       = parent.InverseTransformPoint(remotePos);
            anchor.absolute = Mathf.FloorToInt(localPos.x - remotePos.x + 0.5f);
            anchor.relative = inverted ? 1f : 0f;
        }
    }
Exemplo n.º 5
0
    /// <summary>
    /// Convenience function that switches the anchor mode and ensures that dimensions are kept intact.
    /// </summary>

    static public void UpdateVerticalAnchor(UIRect r, UIRect.AnchorPoint anchor, bool resetRelative)
    {
        // Update the target
        if (anchor.target == null)
        {
            return;
        }

        // Update the rect
        anchor.rect = anchor.target.GetComponent <UIRect>();

        // Continue only if we have a parent to work with
        Transform parent = r.cachedTransform.parent;

        if (parent == null)
        {
            return;
        }

        bool inverted = (anchor == r.topAnchor);
        int  i0       = inverted ? 1 : 0;
        int  i1       = inverted ? 2 : 3;

        // Calculate the bottom side
        Vector3[] myCorners = r.worldCorners;
        Vector3   localPos  = parent.InverseTransformPoint(Vector3.Lerp(myCorners[i0], myCorners[i1], 0.5f));

        if (anchor.rect != null)
        {
            // Anchored to a rectangle -- must anchor to the same side
            Vector3[] targetCorners = anchor.rect.worldCorners;

            // We want to choose the side with the shortest offset
            Vector3 side0 = parent.InverseTransformPoint(Vector3.Lerp(targetCorners[0], targetCorners[3], 0.5f));
            Vector3 side1 = parent.InverseTransformPoint(Vector3.Lerp(targetCorners[1], targetCorners[2], 0.5f));

            float val0 = localPos.y - side0.y;
            float val2 = localPos.y - side1.y;

            if (resetRelative)
            {
                float val1 = localPos.y - Vector3.Lerp(side0, side1, 0.5f).y;
                anchor.SetToNearest(val0, val1, val2);
            }
            else
            {
                float val = localPos.y - Vector3.Lerp(side0, side1, anchor.relative).y;
                anchor.Set(anchor.relative, val);
            }
        }
#if UNITY_4_3 || UNITY_4_5 || UNITY_4_6
        else if (anchor.target.camera != null)
        {
            Vector3[] sides = anchor.target.camera.GetSides(parent);
#else
        else if (anchor.target.GetComponent <Camera>() != null)
        {
            Vector3[] sides = anchor.target.GetComponent <Camera>().GetSides(parent);
#endif
            Vector3 side0 = sides[3];
            Vector3 side1 = sides[1];

            float val0 = localPos.y - side0.y;
            float val2 = localPos.y - side1.y;

            if (resetRelative)
            {
                float val1 = localPos.y - Vector3.Lerp(side0, side1, 0.5f).y;
                anchor.SetToNearest(val0, val1, val2);
            }
            else
            {
                float val = localPos.y - Vector3.Lerp(side0, side1, anchor.relative).y;
                anchor.Set(anchor.relative, val);
            }
        }
        else
        {
            // Anchored to a simple transform
            Vector3 remotePos = anchor.target.position;
            if (anchor.targetCam != null)
            {
                remotePos = anchor.targetCam.WorldToViewportPoint(remotePos);
            }
            if (r.anchorCamera != null)
            {
                remotePos = r.anchorCamera.ViewportToWorldPoint(remotePos);
            }
            remotePos       = parent.InverseTransformPoint(remotePos);
            anchor.absolute = Mathf.FloorToInt(localPos.y - remotePos.y + 0.5f);
            anchor.relative = inverted ? 1f : 0f;
        }
    }
Exemplo n.º 6
0
    /// <summary>
    /// Convenience function that switches the anchor mode and ensures that dimensions are kept intact.
    /// </summary>

    static void UpdateHorizontalAnchor(UIRect r, UIRect.AnchorPoint anchor, bool relative, bool chooseClosest)
    {
        // Update the target
        if (anchor.target == null)
        {
            return;
        }

        // Update the rect
        anchor.rect = anchor.target.GetComponent <UIRect>();

        // Continue only if we have a parent to work with
        Transform parent = r.cachedTransform.parent;

        if (parent == null)
        {
            return;
        }

        bool inverted = (anchor == r.rightAnchor);
        int  i0       = inverted ? 2 : 0;
        int  i1       = inverted ? 3 : 1;

        // Calculate the left side
        Vector3[] myCorners = r.worldCorners;
        Vector3   localPos  = parent.InverseTransformPoint(Vector3.Lerp(myCorners[i0], myCorners[i1], 0.5f));

        if (anchor.rect == null)
        {
            // Anchored to a simple transform
            Vector3 remotePos = parent.InverseTransformPoint(anchor.target.position);
            anchor.absolute = Mathf.FloorToInt(localPos.x - remotePos.x + 0.5f);
            anchor.relative = inverted ? 1f : 0f;
        }
        else
        {
            // Anchored to a rectangle -- must anchor to the same side
            Vector3[] targetCorners = anchor.rect.worldCorners;

            if (relative)
            {
                Vector3 remotePos = parent.InverseTransformPoint(Vector3.Lerp(targetCorners[i0], targetCorners[i1], 0.5f));
                float   offset    = localPos.x - remotePos.x;
                targetCorners = anchor.rect.localCorners;
                float remoteSize = targetCorners[3].x - targetCorners[0].x;

                anchor.absolute = 0;
                anchor.relative = offset / remoteSize;
                if (inverted)
                {
                    anchor.relative += 1f;
                }
            }
            else
            {
                // We want to choose the side with the shortest offset
                Vector3 side0 = parent.InverseTransformPoint(Vector3.Lerp(targetCorners[0], targetCorners[1], 0.5f));
                Vector3 side1 = parent.InverseTransformPoint(Vector3.Lerp(targetCorners[2], targetCorners[3], 0.5f));

                float val0 = localPos.x - side0.x;
                float val2 = localPos.x - side1.x;
                float val1 = localPos.x - Vector3.Lerp(side0, side1, 0.5f).x;

                if (chooseClosest)
                {
                    anchor.SetToNearest(val0, val1, val2);
                }
                else if (inverted)
                {
                    anchor.Set(1f, val2);
                }
                else
                {
                    anchor.Set(0f, val0);
                }
            }
        }
    }
Exemplo n.º 7
0
    /// <summary>
    /// Convenience function that switches the anchor mode and ensures that dimensions are kept intact.
    /// </summary>

    static public void UpdateHorizontalAnchor(UIRect r, UIRect.AnchorPoint anchor, bool resetRelative)
    {
        // Update the target
        if (anchor.target == null)
        {
            return;
        }

        // Update the rect
        anchor.rect = anchor.target.GetComponent <UIRect>();

        // Continue only if we have a parent to work with
        var parent = r.cachedTransform.parent;

        if (parent == null)
        {
            return;
        }

        var inverted = (anchor == r.rightAnchor);
        var i0       = inverted ? 2 : 0;
        var i1       = inverted ? 3 : 1;

        // Calculate the left side
        var myCorners = r.worldCorners;
        var localPos  = parent.InverseTransformPoint(Vector3.Lerp(myCorners[i0], myCorners[i1], 0.5f));

        if (anchor.rect != null)
        {
            // Anchored to a rectangle -- must anchor to the same side
            var targetCorners = anchor.rect.worldCorners;

            // We want to choose the side with the shortest offset
            var side0 = parent.InverseTransformPoint(Vector3.Lerp(targetCorners[0], targetCorners[1], 0.5f));
            var side1 = parent.InverseTransformPoint(Vector3.Lerp(targetCorners[2], targetCorners[3], 0.5f));

            var val0 = localPos.x - side0.x;
            var val2 = localPos.x - side1.x;

            if (resetRelative)
            {
                var val1 = localPos.x - Vector3.Lerp(side0, side1, 0.5f).x;
                anchor.SetToNearest(val0, val1, val2);
            }
            else
            {
                var val = localPos.x - Vector3.Lerp(side0, side1, anchor.relative).x;
                anchor.Set(anchor.relative, val);
            }
        }
#if UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7
        else if (anchor.target.camera != null)
        {
            Vector3[] sides = anchor.target.camera.GetSides(parent);
#else
        else if (anchor.target.GetComponent <Camera>() != null)
        {
            var sides = anchor.target.GetComponent <Camera>().GetSides(parent);
#endif
            var side0 = sides[0];
            var side1 = sides[2];

            var val0 = localPos.x - side0.x;
            var val2 = localPos.x - side1.x;

            if (resetRelative)
            {
                var val1 = localPos.x - Vector3.Lerp(side0, side1, 0.5f).x;
                anchor.SetToNearest(val0, val1, val2);
            }
            else
            {
                var val = localPos.x - Vector3.Lerp(side0, side1, anchor.relative).x;
                anchor.Set(anchor.relative, val);
            }
        }
        else
        {
            // Anchored to a simple transform
            var remotePos = anchor.target.position;
            if (anchor.targetCam != null)
            {
                remotePos = anchor.targetCam.WorldToViewportPoint(remotePos);
            }
            if (r.anchorCamera != null)
            {
                remotePos = r.anchorCamera.ViewportToWorldPoint(remotePos);
            }
            remotePos       = parent.InverseTransformPoint(remotePos);
            anchor.absolute = Mathf.FloorToInt(localPos.x - remotePos.x + 0.5f);
            anchor.relative = inverted ? 1f : 0f;
        }
    }