UnityEngine.UI.DefaultControls.CreateUIElementRoot C# (CSharp) Method

CreateUIElementRoot() private static method

private static CreateUIElementRoot ( string name, Vector2 size ) : GameObject
name string
size Vector2
return UnityEngine.GameObject
        private static GameObject CreateUIElementRoot(string name, Vector2 size)
        {
            GameObject obj2 = new GameObject(name);
            obj2.AddComponent<RectTransform>().sizeDelta = size;
            return obj2;
        }

Usage Example

        public static GameObject CreateButton(DefaultControls.Resources resources)
        {
            GameObject gameObject  = DefaultControls.CreateUIElementRoot("Button", DefaultControls.s_ThickElementSize);
            GameObject gameObject2 = new GameObject("Text");

            gameObject2.AddComponent <RectTransform>();
            DefaultControls.SetParentAndAlign(gameObject2, gameObject);
            Image image = gameObject.AddComponent <Image>();

            image.sprite = resources.standard;
            image.type   = Image.Type.Sliced;
            image.color  = DefaultControls.s_DefaultSelectableColor;
            Button defaultColorTransitionValues = gameObject.AddComponent <Button>();

            DefaultControls.SetDefaultColorTransitionValues(defaultColorTransitionValues);
            Text text = gameObject2.AddComponent <Text>();

            text.text      = "Button";
            text.alignment = TextAnchor.MiddleCenter;
            DefaultControls.SetDefaultTextValues(text);
            RectTransform component = gameObject2.GetComponent <RectTransform>();

            component.anchorMin = Vector2.zero;
            component.anchorMax = Vector2.one;
            component.sizeDelta = Vector2.zero;
            return(gameObject);
        }
All Usage Examples Of UnityEngine.UI.DefaultControls::CreateUIElementRoot