UnityEngine.RectTransform.SetRect(UnityEngine.Vector2, UnityEngine.Vector2, UnityEngine.Vector2, UnityEngine.Vector2)

Here are the examples of the csharp api UnityEngine.RectTransform.SetRect(UnityEngine.Vector2, UnityEngine.Vector2, UnityEngine.Vector2, UnityEngine.Vector2) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

2 Examples 7

19 Source : UIUtility.cs
with GNU General Public License v3.0
from jalil49

public static Action<Action<bool>, string> SpawnUI()
            {
                Component confirmationDialogComponent = null;
                GameObject dialog = null;
                foreach (var c in Resources.FindObjectsOfTypeAll<Canvas>())
                {
                    if (c.gameObject.name.Equals("ConfirmationDialog"))
                    {
                        dialog = c.gameObject;
                        break;
                    }
                }
                if (dialog == null)
                {
                    var c = UIUtility.CreateNewUISystem("ConfirmationDialog");
                    c.sortingOrder = 40;
                    c.transform.localPosition = Vector3.zero;
                    c.transform.localScale = Vector3.one;
                    c.transform.SetRect();
                    c.transform.SetAsLastSibling();

                    var bg = UIUtility.CreateImage("Background", c.transform);
                    bg.rectTransform.SetRect();
                    bg.sprite = null;
                    bg.color = new Color(0f, 0f, 0f, 0.5f);
                    bg.raycastTarget = true;

                    var panel = UIUtility.CreatePanel("Panel", bg.transform);
                    panel.rectTransform.SetRect(new Vector2(0.4f, 0.4f), new Vector2(0.6f, 0.6f));
                    panel.color = Color.gray;

                    var text = UIUtility.CreateText("Text", panel.transform, "");
                    text.rectTransform.SetRect(new Vector2(0f, 0.333333f), Vector2.one, new Vector2(10f, 10f), new Vector2(-10f, -10f));
                    text.color = Color.white;
                    text.resizeTextForBestFit = true;
                    text.resizeTextMaxSize = 100;
                    text.alignByGeometry = true;
                    text.alignment = TextAnchor.MiddleCenter;

                    var yes = UIUtility.CreateButton("YesButton", panel.transform, "Yes");
                    (yes.transform as RectTransform).SetRect(Vector2.zero, new Vector2(0.5f, 0.333333f), new Vector2(10f, 10f), new Vector2(-5f, -10f));
                    text = yes.GetComponentInChildren<Text>();
                    text.resizeTextForBestFit = true;
                    text.resizeTextMaxSize = 100;
                    text.alignByGeometry = true;
                    text.alignment = TextAnchor.MiddleCenter;

                    var no = UIUtility.CreateButton("NoButton", panel.transform, "No");
                    (no.transform as RectTransform).SetRect(new Vector2(0.5f, 0f), new Vector2(1f, 0.333333f), new Vector2(5f, 10f), new Vector2(-10f, -10f));
                    text = no.GetComponentInChildren<Text>();
                    text.resizeTextForBestFit = true;
                    text.resizeTextMaxSize = 100;
                    text.alignByGeometry = true;
                    text.alignment = TextAnchor.MiddleCenter;

                    confirmationDialogComponent = c.gameObject.AddComponent<ConfirmationDialog>();
                    c.gameObject.SetActive(false);
                }
                else
                {
                    var components = dialog.GetComponents<Component>();
                    foreach (var c in components)
                    {
                        if (c.GetType().Name == nameof(ConfirmationDialog))
                        {
                            confirmationDialogComponent = c;
                            break;
                        }
                    }
                }
                return (Action<Action<bool>, string>)Delegate.CreateDelegate(typeof(Action<Action<bool>, string>), confirmationDialogComponent, confirmationDialogComponent.GetType().GetMethod(nameof(DisplayDialog), BindingFlags.Instance | BindingFlags.Public));
            }

19 Source : UIUtility.cs
with GNU General Public License v3.0
from jalil49

private static RectTransform ConstuctContextMenuElement()
        {
            var root = CreateNewUIObject("ContextMenuElement");
            root.gameObject.AddComponent<LayoutElement>().preferredHeight = 25;
            var b = CreateButton("Button", root);
            b.transform.SetRect();
            UnityEngine.Object.Destroy(b.GetComponent<Image>());
            UnityEngine.Object.Destroy(b.GetComponent<CanvasRenderer>());
            b.targetGraphic = CreateImage("Background", b.transform, standardSprite);
            b.targetGraphic.rectTransform.SetRect();
            ((Image)b.targetGraphic).type = Image.Type.Sliced;
            var icon = CreateImage("Icon", b.transform);
            icon.rectTransform.pivot = new Vector2(0f, 0.5f);
            icon.rectTransform.SetRect(new Vector2(0f, 0f), new Vector2(0f, 1f), new Vector2(2f, 2f), new Vector2(23f, -2f));
            var t = b.GetComponentInChildren<Text>();
            t.rectTransform.SetRect(new Vector2(0f, 0f), new Vector2(1f, 1f), new Vector2(25f, 0f), new Vector2(-25f, 0f));
            t.rectTransform.SetAsLastSibling();
            t.alignment = TextAnchor.MiddleLeft;
            t.alignByGeometry = true;
            var childIcon = CreateRawImage("ChildIcon", b.transform, dropdownArrow.texture);
            childIcon.rectTransform.localRotation = Quaternion.AngleAxis(90, Vector3.forward);
            childIcon.rectTransform.SetRect(new Vector2(1f, 0f), new Vector2(1f, 1f), new Vector2(-26.5f, -2f), new Vector2(2.5f, 2f));
            return root;
        }