Exemplo n.º 1
0
        public static RectTransform VerticalGroup(RectTransform parent)
        {
            GameObject obj = new GameObject("ToyBox.VerticalGroup");

            RectTransform transform = obj.AddComponent <RectTransform>();

            transform.SetParent(parent, false);
            transform.anchorMin = new Vector2(0.0f, 0.0f);
            transform.anchorMax = new Vector2(1.0f, 1.0f);
            transform.pivot     = new Vector2(0.5f, 0.5f);
            transform.offsetMin = new Vector2(0.0f, 0.0f);
            transform.offsetMax = new Vector2(0.0f, 0.0f);

            VerticalLayoutGroupWorkaround group = obj.AddComponent <VerticalLayoutGroupWorkaround>();

            group.SetLayoutVertical();
            group.childControlWidth      = true;
            group.childControlHeight     = true;
            group.childForceExpandWidth  = false;
            group.childForceExpandHeight = false;
            group.childScaleWidth        = false;
            group.childScaleHeight       = false;
            group.childAlignment         = TextAnchor.UpperLeft;
            group.spacing = DefaultSpacing;
            group.padding = DefaultPadding;

            return(transform);
        }
Exemplo n.º 2
0
        public static RectTransform TopLevelWindow(Transform parent)
        {
            GameObject obj = new GameObject("ToyBox.TopLevelWindow");

            ToyBox.Main.Objects.Add(obj);
            crUI.obj = obj;

            RectTransform transform = obj.AddComponent <RectTransform>();

            transform.SetParent(parent, false);
            transform.anchorMin = new Vector2(0.0f, 0.0f);
            transform.anchorMax = new Vector2(1.0f, 1.0f);
            transform.pivot     = new Vector2(0.5f, 0.5f);
            transform.offsetMin = new Vector2(0.0f, 0.0f);
            transform.offsetMax = new Vector2(0.0f, 0.0f);

            VerticalLayoutGroupWorkaround group = obj.AddComponent <VerticalLayoutGroupWorkaround>();

            group.SetLayoutVertical();
            group.childControlWidth      = true;
            group.childControlHeight     = true;
            group.childForceExpandWidth  = false;
            group.childForceExpandHeight = false;
            group.childScaleWidth        = false;
            group.childScaleHeight       = false;
            group.childAlignment         = TextAnchor.UpperLeft;
            group.spacing = DefaultSpacing;
            group.padding = DefaultPadding;

            LayoutElement layout = obj.AddComponent <LayoutElement>();

            layout.minWidth        = -1.0f;
            layout.minHeight       = -1.0f;
            layout.preferredWidth  = -1.0f;
            layout.preferredHeight = -1.0f;
            layout.flexibleWidth   = 1.0f;
            layout.flexibleHeight  = 1.0f;

            CanvasGroup canvas = obj.AddComponent <CanvasGroup>();

            ContentSizeFitterExtended fitter = obj.AddComponent <ContentSizeFitterExtended>();

            AccessTools
            .DeclaredField(typeof(ContentSizeFitterExtended), "m_HorizontalFit")
            .SetValue(fitter, ContentSizeFitterExtended.FitMode.PreferredSize);
            AccessTools
            .DeclaredField(typeof(ContentSizeFitterExtended), "m_VerticalFit")
            .SetValue(fitter, ContentSizeFitterExtended.FitMode.PreferredSize);
            fitter.SetLayoutVertical();

            return(transform);
        }