Esempio n. 1
0
 public static void AutoAlign(this GameObject tr, UIAlign align = UIAlign.CENTER, UIPluginType uitype = defaultType)
 {
     if (uitype == UIPluginType.UGUI)
     {
         tr.UGUIAutoAlign(align);
     }
 }
Esempio n. 2
0
        public static List <GameObject> CreateHorGridScroll(this GameObject gameobject, string masksprite, out GameObject scrollObj, Vector2 viewSize, float delta, GameObject prefab, int cnt, UIAlign align = UIAlign.CENTER, int collimit = -1, int rowlimit = -1, UIPluginType uitype = defaultType)
        {
            if (uitype == UIPluginType.UGUI)
            {
                GameObject scrollgameobject = gameobject.TryGetGameObject("Scroll");
                scrollObj = scrollgameobject;
                float totalx = 0f;
                if (prefab != null)
                {
                    totalx = (prefab.GetComponent <RectTransform>().sizeDelta.x + delta) * cnt;
                }

                ScrollViewExpand rect = scrollgameobject.TryAddComponent <ScrollViewExpand>();
                rect.vertical     = false;
                rect.horizontal   = true;
                rect.movementType = ScrollRect.MovementType.Elastic;
                rect.inertia      = true;
                //rect.horizontalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport;
                //rect.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport;
                rect.GetComponent <RectTransform>().sizeDelta = viewSize;

                GameObject viewPortgameobject = scrollgameobject.TryGetGameObject("Viewport");
                GameObject Gridgameobject     = viewPortgameobject.TryGetGameObject("Grid");

                Mask viewmask = viewPortgameobject.TryAddComponent <Mask>();
                viewmask.showMaskGraphic = false;

                ImageExpand viewimage = viewPortgameobject.TryAddComponent <ImageExpand>();
                viewimage.raycastTarget = true;
                viewimage.type          = Image.Type.Sliced;
                viewimage.fillCenter    = true;

                if (SpriteAtlasMgr.mIns != null)
                {
                    SpriteAtlasMgr.mIns.ChangeSprite(viewimage, masksprite);
                }

                GridLayoutGroup group = Gridgameobject.TryAddComponent <GridLayoutGroup>();
                group.spacing     = new Vector2(delta, 0);
                group.startCorner = GridLayoutGroup.Corner.UpperLeft;
                group.startAxis   = GridLayoutGroup.Axis.Horizontal;

                RectTransform grouprect = group.GetComponent <RectTransform>();
                grouprect.sizeDelta = new Vector2(totalx, 0);
                grouprect.anchorMin = new Vector2(0, 1);
                grouprect.anchorMax = new Vector2(1, 1);
                grouprect.pivot     = new Vector2(0, 1);

                if (collimit != -1 && collimit >= 0)
                {
                    group.constraint      = GridLayoutGroup.Constraint.FixedColumnCount;
                    group.constraintCount = collimit;
                }
                else if (rowlimit != -1 && rowlimit >= 0)
                {
                    group.constraint      = GridLayoutGroup.Constraint.FixedRowCount;
                    group.constraintCount = rowlimit;
                }

                if (align == UIAlign.CENTER)
                {
                    group.childAlignment = TextAnchor.MiddleCenter;
                }
                else if (align == UIAlign.CENTER_DOWN)
                {
                    group.childAlignment = TextAnchor.LowerCenter;
                }
                else if (align == UIAlign.CENTER_TOP)
                {
                    group.childAlignment = TextAnchor.UpperCenter;
                }
                else if (align == UIAlign.LEFT_DOWN)
                {
                    group.childAlignment = TextAnchor.LowerLeft;
                }
                else if (align == UIAlign.LEFT_TOP)
                {
                    group.childAlignment = TextAnchor.UpperLeft;
                }
                else if (align == UIAlign.RIGHT_DOWN)
                {
                    group.childAlignment = TextAnchor.LowerRight;
                }
                else if (align == UIAlign.RIGHT_TOP)
                {
                    group.childAlignment = TextAnchor.UpperRight;
                }

                List <GameObject> gameObjectList = null;
                if (cnt > 0)
                {
                    gameObjectList = ListPool.TrySpawn <List <GameObject> >();
                    for (int i = 0; i < cnt; ++i)
                    {
                        GameObject childgameobject = GameObject.Instantiate(prefab);
                        if (i == 0)
                        {
                            RectTransform childrect = childgameobject.GetComponent <RectTransform>();
                            if (childrect != null)
                            {
                                group.cellSize = childrect.sizeDelta;
                            }
                        }
                        Gridgameobject.AddInstance(childgameobject);
                        gameObjectList.Add(childgameobject);
                    }
                }

                RectTransform viewrecttransform = viewPortgameobject.GetComponent <RectTransform>();
                viewrecttransform.anchorMin = Vector2.zero;
                viewrecttransform.anchorMax = new Vector2(1, 1);
                viewrecttransform.pivot     = new Vector2(0, 1);
                viewrecttransform.sizeDelta = Vector2.zero;

                rect.content  = grouprect;
                rect.viewport = viewrecttransform;
                return(gameObjectList);
            }
            scrollObj = null;
            return(null);
        }
Esempio n. 3
0
 public static void AutoAlign(this Component tr, UIAlign align = UIAlign.CENTER, UIPluginType uitype = defaultType)
 {
     tr.gameObject.AutoAlign(align, uitype);
 }