Set() public method

Convenience function that sets the anchor's values.
public Set ( Transform target, float relative, float absolute ) : void
target Transform
relative float
absolute float
return void
Beispiel #1
0
 void SetAnchor(HorizontalPivot varPivot, UIRect.AnchorPoint varAnchorPoint, float varAbsolute)
 {
     if (varPivot == HorizontalPivot.Left)
     {
         varAnchorPoint.Set(0f, varAbsolute);
     }
     else if (varPivot == HorizontalPivot.Center)
     {
         varAnchorPoint.Set(0.5f, varAbsolute);
     }
     else
     {
         varAnchorPoint.Set(1f, varAbsolute);
     }
 }
Beispiel #2
0
 void SetAnchor(VerticalPivot varPivot, UIRect.AnchorPoint varAnchorPoint, float varAbsolute)
 {
     if (varPivot == VerticalPivot.Bottom)
     {
         varAnchorPoint.Set(0f, varAbsolute);
     }
     else if (varPivot == VerticalPivot.Center)
     {
         varAnchorPoint.Set(0.5f, varAbsolute);
     }
     else
     {
         varAnchorPoint.Set(1f, varAbsolute);
     }
 }
    static int Set(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 3);
        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);

        obj.Set(arg0, arg1);
        return(0);
    }
 static public int Set(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 3)
         {
             UIRect.AnchorPoint self = (UIRect.AnchorPoint)checkSelf(l);
             System.Single      a1;
             checkType(l, 2, out a1);
             System.Single a2;
             checkType(l, 3, out a2);
             self.Set(a1, a2);
             pushValue(l, true);
             return(1);
         }
         else if (argc == 4)
         {
             UIRect.AnchorPoint    self = (UIRect.AnchorPoint)checkSelf(l);
             UnityEngine.Transform a1;
             checkType(l, 2, out a1);
             System.Single a2;
             checkType(l, 3, out a2);
             System.Single a3;
             checkType(l, 4, out a3);
             self.Set(a1, a2, a3);
             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));
     }
 }
Beispiel #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;
        }
    }
    /// <summary>
    /// Convenience function that switches the anchor mode and ensures that dimensions are kept intact.
    /// </summary>

    static void UpdateVerticalAnchor(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.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;

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

                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[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;

                if (chooseClosest)
                {
                    anchor.SetToNearest(val0, val1, val2);
                }
                else if (inverted)
                {
                    anchor.Set(1f, val2);
                }
                else
                {
                    anchor.Set(0f, val0);
                }
            }
        }
    }
Beispiel #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;
        }
    }