Example #1
0
        public GameObject AddToPopCanvas()
        {
            var obj = UGUITools.AddChild(UIManager.PopCanvasRoot, (GameObject)uiPrefab);

            obj.name = uiPrefab.name;
            return(obj);
        }
Example #2
0
    private void InitUICanvas()
    {
        if (UIRoot == null)
        {
            return;
        }
        if (m_MiddleUIRoot != null)//表示已经创建过[重登陆]
        {
            return;
        }

        m_MiddleUIRoot = UGUITools.AddChild(UIRoot.gameObject, NormalUIRoot.gameObject, false, UINodeName.MiddleUIRootName).transform;
        m_TopUIRoot    = UGUITools.AddChild(UIRoot.gameObject, NormalUIRoot.gameObject, false, UINodeName.TopUIRootName).transform;
        m_T2Root       = UGUITools.AddChild(UIRoot.gameObject, NormalUIRoot.gameObject, false, UINodeName.T2RootName).transform;
        m_T3Root       = UGUITools.AddChild(UIRoot.gameObject, NormalUIRoot.gameObject, false, UINodeName.T3RootName).transform;

        //Canvas2D
        SetUICanvas2Ds();

        //Canvas3D
        //SetUICanvas3D(CamerasMgr.CameraMain);
        //Show3DUI(true);

        //UICamera
        SetUICamera();
    }
Example #3
0
 public static void CreateCameraOfBattleSpine()
 {
     if (CamerasMgr.CameraOfBattleSpine != null && CamerasMgr.CameraOfBattleSpine.get_transform() != null)
     {
         CamerasMgr.CameraOfBattleSpine.get_gameObject().SetActive(true);
     }
     else
     {
         GameObject gameObject = new GameObject();
         gameObject.set_name("Camera2BattleSpineScreen");
         gameObject.get_transform().set_parent(null);
         CamerasMgr.CameraOfBattleSpine = gameObject.AddComponent <Camera>();
         CamerasMgr.CameraOfBattleSpine.set_clearFlags(1);
         CamerasMgr.CameraOfBattleSpine.set_cullingMask(LayerSystem.GetMask(CamerasMgr.battle_spine_layerss));
         CamerasMgr.CameraOfBattleSpine.set_depth(CamerasMgr.CameraMain.get_depth() - 1f);
         GameObject gameObject2 = AssetManager.AssetOfNoPool.LoadAssetNowNoAB("UGUI/Prefabs/GlobalUI/UICanvasNoEvents", typeof(Object)) as GameObject;
         if (gameObject2 == null)
         {
             return;
         }
         CamerasMgr._canvasOfBattleSpine = UGUITools.AddChild(CamerasMgr.CameraOfBattleSpine.get_gameObject(), gameObject2, false, "_canvasOfBattleSpine").get_transform();
         Canvas component = CamerasMgr._canvasOfBattleSpine.GetComponent <Canvas>();
         if (component != null)
         {
             component.set_worldCamera(CamerasMgr.CameraOfBattleSpine);
             component.get_gameObject().SetActive(true);
             component.set_planeDistance(100f);
             component.set_sortingOrder(1000);
         }
     }
 }
Example #4
0
    private GameObject DoInstantiate(int index)
    {
        GameObject gameObject;

        if (this.temp != null)
        {
            gameObject = UGUITools.AddChild(base.get_gameObject(), this.temp, false);
            gameObject.set_name(this.temp.get_name() + index.ToString());
        }
        else
        {
            gameObject = ResourceManager.GetInstantiate2Prefab(this.temp_prefabname);
            UGUITools.SetParent(base.get_gameObject(), gameObject, false);
            gameObject.set_name(this.temp_prefabname + index.ToString());
        }
        if (this.isAnimation)
        {
            gameObject.GetComponent <RectTransform>().set_anchoredPosition((index < this.maxShow * this.lineContainNum) ? (this.GetPos(index) + this.moveing) : this.GetPos(index));
        }
        else if (!this.IsContainLayoutWidget)
        {
            gameObject.GetComponent <RectTransform>().set_anchoredPosition(this.GetPos(index));
        }
        return(gameObject);
    }
Example #5
0
    // Create STexture
    public static STexture AddTexture(GameObject gameObject)
    {
        STexture texture = UGUITools.AddChild <STexture>(gameObject);

        (texture as RawImage).raycastTarget = false;
        UGUITools.ResetGameObject(texture.gameObject);

        return(texture);
    }
Example #6
0
    public static GameObject AddChild(GameObject parent, GameObject asset, bool forceShow, string name)
    {
        GameObject gameObject = UGUITools.AddChild(parent, asset, forceShow);

        if (gameObject != null && !string.IsNullOrEmpty(name))
        {
            gameObject.set_name(name);
        }
        return(gameObject);
    }
Example #7
0
    // Create SImage
    public static SImage AddImage(GameObject gameObject)
    {
        SImage image = UGUITools.AddChild <SImage>(gameObject);

        image.Atlas         = atlas;
        image.SpriteName    = selectedSprite;
        image.raycastTarget = false;
        UGUITools.ResetGameObject(image.gameObject);

        return(image);
    }
Example #8
0
        /// <summary>
        /// 生成一个新的警告窗口
        /// </summary>
        /// <returns>警告对象</returns>
        private static Alert GetNewAlert()
        {
            if (false == isInitAlert)
            {
                return(null);
            }

            GameObject obj = UGUITools.AddChild(mParent, mPrefab);

            obj.SetActive(true);
            return(obj.GetComponent <Alert>());
        }
Example #9
0
    public GameObject PopupDialog <T>(GameObject prefab, T param, bool instant = true) where T : DialogParam
    {
        GameObject go = UGUITools.AddChild(gameObject, prefab);

        if (go.GetComponent <DialogBase>() != null)
        {
            go.GetComponent <DialogBase>().style = DialogStyle.NormalDialog;
        }
        PushDialog(go, param, instant);

        return(go);
    }
Example #10
0
    public static void ShowImageText(Transform parent, long num, string imagePrefix, string notDestroyChildName)
    {
        Transform   transform  = null;
        IEnumerator enumerator = parent.GetEnumerator();

        try
        {
            while (enumerator.MoveNext())
            {
                Transform transform2 = (Transform)enumerator.get_Current();
                if (transform2.get_name() == notDestroyChildName && notDestroyChildName != string.Empty)
                {
                    transform = transform2;
                }
                else
                {
                    Object.Destroy(transform2.get_gameObject());
                }
            }
        }
        finally
        {
            IDisposable disposable = enumerator as IDisposable;
            if (disposable != null)
            {
                disposable.Dispose();
            }
        }
        int        length     = num.ToString().get_Length();
        long       num2       = num;
        GameObject gameObject = new GameObject();

        gameObject.AddComponent <Image>();
        for (int i = 1; i < length; i++)
        {
            int num3 = (int)((double)num2 / Math.Pow(10.0, (double)(length - i)));
            num2 = (long)((int)((double)num2 % Math.Pow(10.0, (double)(length - i))));
            GameObject gameObject2 = UGUITools.AddChild(parent.get_gameObject(), gameObject, false);
            gameObject2.set_name(num3.ToString());
            Image component = gameObject2.GetComponent <Image>();
            ResourceManager.SetSprite(component, ResourceManager.GetIconSprite(imagePrefix + num3));
            component.SetNativeSize();
        }
        GameObject gameObject3 = UGUITools.AddChild(parent.get_gameObject(), gameObject, false);

        ResourceManager.SetSprite(gameObject3.GetComponent <Image>(), ResourceManager.GetIconSprite(imagePrefix + num2));
        gameObject3.set_name(num2.ToString());
        Object.Destroy(gameObject);
        if (transform != null)
        {
            transform.SetAsLastSibling();
        }
    }
Example #11
0
    // Create SText
    public static SText AddText(GameObject gameObject)
    {
        SText txt = UGUITools.AddChild <SText>(gameObject);

        txt.textStyle               = textStyle;
        txt.text                    = "New Text";
        txt.color                   = Color.black;
        txt.raycastTarget           = false;
        txt.rectTransform.sizeDelta = new Vector2(120, 200);
        UGUITools.ResetGameObject(txt.gameObject);
        return(txt);
    }
Example #12
0
    // Create SMask
    public static SMask AddMask(GameObject gameObject)
    {
        SMask mask = UGUITools.AddChild <SMask>(gameObject);

        mask.name                    = "SMask";
        mask.raycastTarget           = true;
        mask.rectTransform.anchorMin = Vector2.zero;
        mask.rectTransform.anchorMax = Vector2.one;
        mask.rectTransform.sizeDelta = Vector2.zero;
        UGUITools.ResetGameObject(mask.gameObject);

        return(mask);
    }
Example #13
0
    void Start()
    {
        string      path   = $"{Application.streamingAssetsPath}/ui/uiatlas/common.u3d";
        AssetBundle bundle = AssetBundle.LoadFromFile(path);

        if (bundle == null)
        {
            Debug.LogError("null");
            return;
        }
        var prefab = bundle.LoadAsset <SpriteAtlas>("UI_MessageBox");

        UGUITools.AddChild(UIManager.CanvasRoot, prefab);
    }
Example #14
0
    private GameObject CreatLineType(int id, LineType lineType)
    {
        GameObject    gameObject = UGUITools.AddChild(base.get_gameObject(), this.golight, false);
        LightLineLoad component  = gameObject.GetComponent <LightLineLoad>();

        component.SetLine(lineType);
        component.Id = id;
        this.Items.set_Item(id, new LineData
        {
            id   = id,
            type = lineType,
            go   = gameObject
        });
        return(gameObject);
    }
Example #15
0
        /// <summary>
        /// 初始化飘窗,游戏运行后必须调用一次
        /// </summary>
        /// <param name="parent">飘窗元素的父对象</param>
        /// <param name="showtipPrefab">飘窗预置</param>
        public void InitShowTips(GameObject parent, GameObject showtipPrefab)
        {
            int count = ShowTipsList.Count;

            if (count < MAXCOUNT)
            {
                for (int i = count; i < MAXCOUNT; i++)
                {
                    GameObject showtips = UGUITools.AddChild(parent, showtipPrefab);
                    showtips.transform.localPosition = InitialPostion;
                    showtips.SetActive(false);
                    ShowTipsList.Add(showtips);
                }
            }
        }
Example #16
0
    private void OnRenameClick(GameObject go)
    {
        string[] chatPrefabs = new string[] { "Prefab/UI/EquipsOutside/ItemRenamedcr" };

        ResourceManager.Instance.LoadMutileAssets(chatPrefabs, o =>
        {
            if (ItemRenamedcr.Exists == false)
            {
                GameObject view = UGUITools.AddChild(gameObject, ResourceManager.Instance.LoadExistsAsset <GameObject>("Prefab/UI/EquipsOutside/ItemRenamedcr"));
                view.AddComponent <ItemRenamedcr>();
                UGUITools.SetStretch(view);

                ItemRenamedcr.Instance.SetName(_currInfo.plan_name, _currInfo.plan_id);
            }
        }, false, 3);
    }
Example #17
0
    ItemeEquipOutSide3cr CreateSynthesisItem(ConfigEquip equip, float x, float y, bool isRoot = false)
    {
        GameObject renderPrefab = ResourceManager.Instance.LoadExistsAsset <GameObject>("Prefab/UI/EquipsOutside/ItemeEquipOutSide3cr");
        GameObject item         = UGUITools.AddChild(go_EquipSynthesiscr, renderPrefab);

        synthesisItemList.Add(item);
        ItemeEquipOutSide3cr itemScript = item.AddMissingComponent <ItemeEquipOutSide3cr>();

        itemScript.type = 1;
        itemScript.SetData(equip);
        if (isRoot)
        {
            itemScript.Select();
        }
        item.GetComponent <RectTransform>().anchoredPosition = new Vector2(x, y);
        return(itemScript);
    }
Example #18
0
    public void RefreshUI()
    {
        for (int i = 0; i < this.ListItems.get_transform().get_childCount(); i++)
        {
            if (this.ItemPrefab != this.ListItems.get_transform().GetChild(i).get_gameObject())
            {
                Object.Destroy(this.ListItems.get_transform().GetChild(i).get_gameObject());
            }
        }
        int num = SurvivalManager.Instance.StageMax - SurvivalManager.Instance.StageMaxHis;

        num = ((num < 0) ? 0 : num);
        for (int j = SurvivalManager.Instance.StageMax; j > num; j--)
        {
            GameObject gameObject = UGUITools.AddChild(this.ListItems.get_gameObject(), this.ItemPrefab, false);
            gameObject.SetActive(true);
            gameObject.GetComponent <DifficultyItem>().updateItem(j);
            gameObject.GetComponent <ButtonCustom>().onClickCustom = new ButtonCustom.VoidDelegateObj(this.OnClickItem);
        }
        this.Times.set_text(SurvivalManager.Instance.ScInfo.challengeTime.ToString());
        this.ButtonBuyTimes.get_gameObject().SetActive(SurvivalManager.Instance.ScInfo.challengeTime <= 0);
    }
Example #19
0
    private static GameObject Show(string message, string title, GameObject parentGO, GameObject receiverGO, bool isSingle, string okStr, OnOK okFun, string cancelStr, OnCancel cancelFun, string checkStr = "", int bgClickType = 0, DirectionPostion align = DirectionPostion.Center)
    {
        GameObject prefab = ResourceManager.Instance.LoadExistsAsset <GameObject>("Prefab/UI/TipAlter/AlertBox");

        if (parentGO == null)
        {
            parentGO = UIManager.TipLayer.gameObject;
        }

        GameObject obj3 = UGUITools.AddChild(parentGO, prefab);

        Util.SetLayer(obj3, parentGO.layer);
        AlertBox component = obj3.AddMissingComponent <AlertBox>();

        if (string.IsNullOrEmpty(title))
        {
            title = "提示";
        }
        if (string.IsNullOrEmpty(okStr))
        {
            okStr = "确定";
        }
        if (string.IsNullOrEmpty(cancelStr))
        {
            cancelStr = "取消";
        }
        // 默认都是enable
        component.InitSetCommon(title, message, bgClickType, okStr, cancelStr, isSingle);
        component.mOnOK     = okFun;
        component.mOnCancel = cancelFun;

        if (!string.IsNullOrEmpty(checkStr))
        {
            component.AddSetCheckBoxInfo(checkStr);
        }

        return(obj3);
    }
Example #20
0
    /// <summary>
    /// 显示消息发送中
    /// </summary>
    public void ShowSendingUI()
    {
        if (type == 2 || type == 3)
        {
            return;
        }

        if (false == CanShowAlert())
        {
            return;
        }

        if (_connectingUI != null)
        {
            _connectingUI.GetComponent <ConnectingUI>().SetConnectingType(2);
            return;
        }
        type = 1;
        GameObject prefab = ResourceManager.Instance.LoadExistsAsset <GameObject>("Prefab/UI/Common/ConnectingUI");

        prefab.AddMissingComponent <ConnectingUI>();
        _connectingUI = UGUITools.AddChild(UIManager.TipLayer.gameObject, prefab);
        _connectingUI.GetComponent <ConnectingUI>().SetConnectingType(2);
    }
Example #21
0
    public static void InitUICanvas()
    {
        if (UINodesManager.UIRoot == null)
        {
            return;
        }
        if (UINodesManager.m_NoEventsUIRoot != null)
        {
            return;
        }
        GameObject gameObject = AssetLoader.LoadAssetNow("Reserved/UICanvasNoEvents", typeof(Object)) as GameObject;

        if (gameObject == null)
        {
            Debug.LogError("prefabNoEvents初始化失败");
            return;
        }
        UINodesManager.m_NoEventsUIRoot = UGUITools.AddChild(UINodesManager.UIRoot.get_gameObject(), gameObject, false, "UICanvasNoEvents").get_transform();
        UINodesManager.m_NoEventsUIRoot.SetSiblingIndex(UINodesManager.NormalUIRoot.GetSiblingIndex());
        GameObject gameObject2 = AssetLoader.LoadAssetNow("Reserved/UICanvasEvents", typeof(Object)) as GameObject;

        if (gameObject2 == null)
        {
            Debug.LogError("prefabEvents初始化失败");
            return;
        }
        UINodesManager.m_MiddleUIRoot = UGUITools.AddChild(UINodesManager.UIRoot.get_gameObject(), gameObject2, false, "UICanvasMiddle").get_transform();
        UINodesManager.m_TopUIRoot    = UGUITools.AddChild(UINodesManager.UIRoot.get_gameObject(), gameObject2, false, "UICanvasTop").get_transform();
        UINodesManager.m_T2Root       = UGUITools.AddChild(UINodesManager.UIRoot.get_gameObject(), gameObject2, false, "UICanvasT2OfSpeical").get_transform();
        UINodesManager.m_T3Root       = UGUITools.AddChild(UINodesManager.UIRoot.get_gameObject(), gameObject2, false, "UICanvasT3OfSpecial").get_transform();
        UINodesManager.m_T4Root       = UGUITools.AddChild(UINodesManager.UIRoot.get_gameObject(), gameObject2, false, "UICanvasT4OfSpecial").get_transform();
        UINodesManager.SetUICanvas2Ds();
        UINodesManager.SetUICanvas3D(CamerasMgr.CameraMain);
        UINodesManager.Show3DUI(true);
        UINodesManager.SetUICamera();
    }
Example #22
0
 public void CreateRow(int num, int grid = 0)
 {
     base.GetComponent <RectTransform>().set_sizeDelta(new Vector2(base.GetComponent <RectTransform>().get_sizeDelta().x, (float)(-(float)(num * this.height + 2 * this.offset))));
     if (this.Items.get_Count() > num)
     {
         int i;
         for (i = 0; i < num; i++)
         {
             this.Items.get_Item(i).SetActive(true);
         }
         while (i < this.Items.get_Count())
         {
             this.Items.get_Item(i).SetActive(false);
             i++;
         }
     }
     else if (this.Items.get_Count() < num)
     {
         int j;
         for (j = 0; j < this.Items.get_Count(); j++)
         {
             if (!this.Items.get_Item(j).get_activeSelf())
             {
                 this.Items.get_Item(j).SetActive(true);
             }
         }
         if (this.movingCount != 0)
         {
             this.isAddAtMoving = true;
         }
         while (j < num)
         {
             GameObject gameObject;
             if (string.IsNullOrEmpty(this.RowFrefabName))
             {
                 gameObject = UGUITools.AddChild(base.get_gameObject(), this.RowFrefab, false);
             }
             else
             {
                 gameObject = ResourceManager.GetInstantiate2Prefab(this.RowFrefabName);
                 UGUITools.SetParent(base.get_gameObject(), gameObject, false);
             }
             if (gameObject != null)
             {
                 if (string.IsNullOrEmpty(this.RowFrefabName))
                 {
                     gameObject.set_name(this.RowFrefab.get_name() + j);
                 }
                 else
                 {
                     gameObject.set_name(this.RowFrefabName + j);
                 }
                 Transform transform = gameObject.get_transform();
                 if (j == 0)
                 {
                     transform.set_localPosition(new Vector3(0f, (float)(j * this.height + this.offset)));
                 }
                 else
                 {
                     transform.set_localPosition(new Vector3(0f, this.Items.get_Item(j - 1).get_transform().get_localPosition().y + (float)this.height));
                 }
                 transform.set_localRotation(Quaternion.get_identity());
                 transform.set_localScale(Vector3.get_one());
                 gameObject.SetActive(true);
                 this.Items.Add(gameObject);
             }
             j++;
         }
     }
     else
     {
         for (int k = 0; k < num; k++)
         {
             if (!this.Items.get_Item(k).get_activeSelf())
             {
                 this.Items.get_Item(k).SetActive(true);
             }
         }
     }
     for (int l = 0; l < num; l++)
     {
         this.Items.get_Item(l).set_name(l + string.Empty);
     }
 }
Example #23
0
    private void UpdateUi()
    {
        if (RenderPrefab == null)
        {
            RenderPrefab = ResourceManager.Instance.LoadExistsAsset <GameObject>(_prefabPath);
        }

        if (RenderPrefab == null)
        {
            return;
        }

        _gridGroup.enabled = true;

        int lastMaxFirstInitNum = _maxFirstInitNum;
        int lastListMin         = _listMin;
        int lastListMax         = _listMax;

        RectTransform viewRect = null;

        if (_scrollRect != null)
        {
            switch (_direction)
            {
            case Direction.Horizontal:
                _scrollRect.horizontal = true;
                _scrollRect.vertical   = false;
                break;

            case Direction.Vertical:
                _scrollRect.horizontal = false;
                _scrollRect.vertical   = true;
                break;

            case Direction.none:
                _scrollRect.horizontal = false;
                _scrollRect.vertical   = false;
                break;
            }
            if ((UnityEngine.Object)_scrollRect.viewport == (UnityEngine.Object)null)
            {
                viewRect = _scrollRect.gameObject.GetRectTransform();
            }
            else
            {
                viewRect = _scrollRect.viewport;
            }

            _scrollRect.onValueChanged.RemoveAllListeners();
            //设置需要创建的最大item数量
            if (_isNeedSetMaxItemNum)
            {
                if (_fullNum > 0)
                {
                    _maxFirstInitNum = _fullNum + 4;
                }

                if (_maxFirstInitNum > _dataProvider.Length)
                {
                    _maxFirstInitNum = 0;
                }
                else if (_bar != null)
                {
                    _scrollRect.horizontalScrollbar = null;
                    _scrollRect.verticalScrollbar   = null;
                    _bar.gameObject.SetActive(false);
                }

                if (_maxFirstInitNum > 0)
                {
                    if (IsNeedRestPos == 0 || IsNeedRestPos == 3)
                    {
                        _listMin = 0;
                    }
                    else if (IsNeedRestPos == 1)
                    {
                        _listMin = lastListMin;
                        if (lastListMax > _dataProvider.Length - 1)
                        {
                            _listMin -= lastListMax - _dataProvider.Length + 1;
                        }
                        if (_listMin < 0)
                        {
                            _listMin = 0;
                        }
                    }
                    else if (IsNeedRestPos == 2)
                    {
                        _listMin = _dataProvider.Length - _maxFirstInitNum;
                    }
                    _listMax = _listMin + _maxFirstInitNum - 1;
                }
                else
                {
                    _listMin = 0;
                    _listMax = 0;
                }

                var oldPivot = _contTransform.pivot;
                int axis     = _scrollRect.vertical ? 1 : 0;
                oldPivot[axis]       = axis;
                _contTransform.pivot = oldPivot;

                _scrollRect.onValueChanged.AddListener(OnScroll);
            }
        }

        for (int i = 0; i < lastMaxFirstInitNum; i++)
        {
            _renders[lastListMin + i].gameObject.SetActive(false);
            _renders.Remove(lastListMin + i);
            if (_uiCenterOnChild != null)
            {
                Destroy(items[lastListMin + i].gameObject);
                items.RemoveAt(lastListMin + i);
            }
        }

        int initNum = _dataProvider.Length;

        if (_maxFirstInitNum != 0)
        {
            initNum = _maxFirstInitNum;
        }

        for (int i = 0; i < initNum; i++)
        {
            GameObject item;
            if (i >= _renders.Count)
            {
                if (i >= items.Count)
                {
                    item = UGUITools.AddChild(gameObject, RenderPrefab);
                    var itemRender = item.AddComponent(_itemScript) as BaseItemRender;
                    item.name = "item" + (i + _listMin);
                    _renders.Add(i + _listMin, itemRender);
                    items.Add(itemRender);
                }
                else
                {
                    items[i].gameObject.SetActive(true);
                    items[i].name = "item" + (i + _listMin);
                    _renders.Add(i + _listMin, items[i]);
                }
            }
            else    //如果_isNeedSetMaxItemNum为false,是不进入这里的,因为前面把_renders清掉了
            {
                item = _renders[i].gameObject;
                item.SetActive(true); //避免Render 里把自己给隐藏了
            }

            _renders[i + _listMin].SetItemIndex(i + _listMin, _dataProvider.Length);
            _renders[i + _listMin].SetDataGridType(DataGridType);
            _renders[i + _listMin].SetData(_dataProvider[i + _listMin]);
        }

        //如果_isNeedSetMaxItemNum为false,是不进入这里的,因为前面把_renders清掉了
        for (int i = _renders.Count - 1; i >= initNum; i--)
        {
            _renders[i].gameObject.SetActive(false);
            _renders.Remove(i);
            if (_uiCenterOnChild != null)
            {
                Destroy(items[i].gameObject);
                items.RemoveAt(i);
            }
        }

        if (_gridGroup is AutoSizeGridLayoutGroup)
        {
            (_gridGroup as AutoSizeGridLayoutGroup).ItemNum = _renders.Count;
        }

        if (_scrollRect != null)
        {
            //默认处理数量不足设置为不可拖动
            if (_renders.Count <= _fullNum && _uiCenterOnChild == null)
            {
                _scrollRect.horizontal = false;
                _scrollRect.vertical   = false;
                if (_bar != null)
                {
                    _scrollRect.horizontalScrollbar = null;
                    _scrollRect.verticalScrollbar   = null;
                    _bar.gameObject.SetActive(false);
                }
            }
            else
            {
                if (_direction == Direction.Horizontal)
                {
                    _scrollRect.horizontalScrollbar = _bar;
                }
                else if (_direction == Direction.Vertical)
                {
                    _scrollRect.verticalScrollbar = _bar;
                }
            }

            if (_direction == Direction.Horizontal)
            {
                int num;   //列数
                if (_gridGroup.constraint == GridLayoutGroup.Constraint.FixedRowCount)
                {
                    num = (_renders.Count + _gridGroup.constraintCount - 1) / _gridGroup.constraintCount;  //整数除法,向上取整
                }
                else if (_gridGroup.constraint == GridLayoutGroup.Constraint.FixedColumnCount)
                {
                    num = _gridGroup.constraintCount;
                }
                else
                {
                    num = Mathf.FloorToInt((_contTransform.rect.height - _gridGroup.padding.vertical + _gridGroup.spacing.y + 1.0f / 1000.0f) / (_gridGroup.cellSize.y + _gridGroup.spacing.y));
                    num = Mathf.Max(1, num);
                    num = (_renders.Count + num - 1) / num;
                }
                _contTransform.sizeDelta = new Vector2(_gridGroup.padding.horizontal + num * (_gridGroup.cellSize.x + _gridGroup.spacing.x) - _gridGroup.spacing.x, _contTransform.sizeDelta.y);

                _gridGroup.CalculateLayoutInputHorizontal();
                _gridGroup.SetLayoutHorizontal();
                _gridGroup.CalculateLayoutInputVertical();
                _gridGroup.SetLayoutVertical();

                if (_listMax > 0)    //暂时不支持多行
                {
                    for (int i = 0; i < _renders.Count; i++)
                    {
                        var rectTran = _renders[i + _listMin].gameObject.GetRectTransform();
                        ResetPosition(rectTran, 1, _listMin * (_gridGroup.cellSize.x + _gridGroup.spacing.x));
                    }
                    _contTransform.sizeDelta = new Vector2(_gridGroup.padding.horizontal + (_listMax + 1) * (_gridGroup.cellSize.x + _gridGroup.spacing.x) - _gridGroup.spacing.x, _contTransform.sizeDelta.y);
                    _gridGroup.enabled       = false;
                }

                float moveDistance           = 0;
                float anchorGridToScrollview = (_contTransform.anchorMin.x + _contTransform.anchorMax.x) * 0.5f;
                _pivotPosition = (anchorGridToScrollview - 0.5f) * viewRect.rect.width;
                _threshold     = (_gridGroup.cellSize.x + _gridGroup.spacing.x);
                if (IsNeedRestPos == 0)
                {
                    float dGridAnchToScrLeft   = anchorGridToScrollview * viewRect.rect.width;
                    float dGridPivotToScrLeft  = dGridAnchToScrLeft + _contTransform.anchoredPosition.x;
                    float dGridPivotToGridLeft = _contTransform.rect.width * _contTransform.pivot.x;
                    float dScrLeftToGridLeft   = dGridPivotToGridLeft - dGridPivotToScrLeft;
                    moveDistance = dScrLeftToGridLeft;
                }
                else if (IsNeedRestPos == 1)
                {
                    if (_listMax > 0)
                    {
                        moveDistance = 0;
                    }
                    else if (_lastContentSize == Vector2.zero)
                    {
                        moveDistance = 0;
                    }
                    else
                    {
                        float delta = _contTransform.rect.width - _lastContentSize.x;
                        moveDistance = _contTransform.pivot.x * delta;
                    }
                }
                else if (IsNeedRestPos == 2)
                {
                    float dGridAnchToScrRight   = (1 - anchorGridToScrollview) * viewRect.rect.width;
                    float dGridPivotToScrRight  = dGridAnchToScrRight - _contTransform.anchoredPosition.x;
                    float dGridPivotToGridRight = _contTransform.rect.width * (1 - _contTransform.pivot.x);
                    float dScrRightToGridRight  = dGridPivotToGridRight - dGridPivotToScrRight;
                    moveDistance = -dScrRightToGridRight;
                }
                else if (IsNeedRestPos == 3)
                {
                    float dGridPivotToScrCenter  = _contTransform.anchoredPosition.x + (anchorGridToScrollview - 0.5f) * viewRect.rect.width;
                    float dGridPivotToGridCenter = _contTransform.rect.width * (_contTransform.pivot.x - 0.5f);
                    moveDistance = -dGridPivotToScrCenter + dGridPivotToGridCenter;
                }
                ResetPosition(_contTransform, 0, moveDistance);

                _startPosMin = (1 - anchorGridToScrollview) * viewRect.rect.width - _contTransform.rect.width * (1 - _contTransform.pivot.x);
                _startPosMax = _contTransform.rect.width * _contTransform.pivot.x - anchorGridToScrollview * viewRect.rect.width;
            }
            else if (_direction == Direction.Vertical)
            {
                float GroupLen = 0;
                if (_gridGroup is AutoSizeGridLayoutGroup)
                {
                    bool b = IsInScroll();
                    _gridGroup.CalculateLayoutInputHorizontal();
                    _gridGroup.SetLayoutHorizontal();
                    _gridGroup.CalculateLayoutInputVertical();
                    _gridGroup.SetLayoutVertical();

                    GroupLen = (_gridGroup as AutoSizeGridLayoutGroup).LayoutGroupHeight;
                    _contTransform.sizeDelta = new Vector2(_contTransform.sizeDelta.x, _gridGroup.padding.vertical + GroupLen);

                    if (ResetPos == false && b)
                    {
                        IsNeedRestPos = 1;
                    }
                    else
                    {
                        if (GroupLen + _gridGroup.padding.vertical >= viewRect.rect.height)
                        {
                            IsNeedRestPos = 2;
                        }
                        else
                        {
                            IsNeedRestPos = 0;
                        }
                    }
                }
                else
                {
                    int num;   //行数
                    if (_gridGroup.constraint == GridLayoutGroup.Constraint.FixedRowCount)
                    {
                        num = _gridGroup.constraintCount;
                    }
                    else if (_gridGroup.constraint == GridLayoutGroup.Constraint.FixedColumnCount)
                    {
                        num = (_renders.Count + _gridGroup.constraintCount - 1) / _gridGroup.constraintCount;  //整数除法,向上取整
                    }
                    else
                    {
                        num = Mathf.FloorToInt((_contTransform.rect.width - _gridGroup.padding.horizontal + _gridGroup.spacing.x + 1.0f / 1000.0f) / (_gridGroup.cellSize.x + _gridGroup.spacing.x));
                        num = Mathf.Max(1, num);
                        num = (_renders.Count + num - 1) / num;
                    }
                    GroupLen = num * (_gridGroup.cellSize.y + _gridGroup.spacing.y) - _gridGroup.spacing.y;
                    _contTransform.sizeDelta = new Vector2(_contTransform.sizeDelta.x, _gridGroup.padding.vertical + GroupLen);

                    _gridGroup.CalculateLayoutInputHorizontal();
                    _gridGroup.SetLayoutHorizontal();
                    _gridGroup.CalculateLayoutInputVertical();
                    _gridGroup.SetLayoutVertical();
                }

                if (_listMax > 0)    //暂时不支持多列
                {
                    for (int i = 0; i < _renders.Count; i++)
                    {
                        var rectTran = _renders[i + _listMin].gameObject.GetRectTransform();
                        ResetPosition(rectTran, 1, -_listMin * (_gridGroup.cellSize.y + _gridGroup.spacing.y));
                    }
                    _contTransform.sizeDelta = new Vector2(_contTransform.sizeDelta.x, _gridGroup.padding.vertical + (_listMax + 1) * (_gridGroup.cellSize.y + _gridGroup.spacing.y) - _gridGroup.spacing.y);
                    _gridGroup.enabled       = false;
                }

                float moveDistance           = 0;
                float anchorGridToScrollview = (_contTransform.anchorMin.y + _contTransform.anchorMax.y) * 0.5f;
                _pivotPosition = (anchorGridToScrollview - 0.5f) * viewRect.rect.height;
                _threshold     = (_gridGroup.cellSize.y + _gridGroup.spacing.y);
                if (IsNeedRestPos == 0)
                {
                    float dGridAnchToScrTop   = (1 - anchorGridToScrollview) * viewRect.rect.height;
                    float dGridPivotToScrTop  = dGridAnchToScrTop - _contTransform.anchoredPosition.y;
                    float dGridPivotToGridTop = _contTransform.rect.height * (1 - _contTransform.pivot.y);
                    float dScrTopToGridTop    = dGridPivotToGridTop - dGridPivotToScrTop;
                    moveDistance = -dScrTopToGridTop;
                }
                else if (IsNeedRestPos == 1)
                {
                    if (_listMax > 0)
                    {
//                        float dGridTopToScrCenter = _pivotPosition + _contTransform.anchoredPosition.y;
//                        float dPointToGridTop = (((_listMax - _listMin + 1) >> 1) + _listMin) * _threshold;
//                        moveDistance = dPointToGridTop - dGridTopToScrCenter;
                    }
                    else if (_lastContentSize == Vector2.zero)
                    {
                        moveDistance = 0;
                    }
                    else
                    {
                        float delta = _contTransform.rect.height - _lastContentSize.y;
                        moveDistance = (_contTransform.pivot.y - 1) * delta;
                    }
                }
                else if (IsNeedRestPos == 2)
                {
                    float dGridAnchToScrBottom   = anchorGridToScrollview * viewRect.rect.height;
                    float dGridPivotToScrBottom  = dGridAnchToScrBottom + _contTransform.anchoredPosition.y;
                    float dGridPivotToGridBottom = _contTransform.rect.height * _contTransform.pivot.y;
                    float dScrBottomToGridBottom = dGridPivotToGridBottom - dGridPivotToScrBottom;
                    moveDistance = dScrBottomToGridBottom;
                }
                else if (IsNeedRestPos == 3)
                {
                    float dGridPivotToScrCenter  = _contTransform.anchoredPosition.y + (anchorGridToScrollview - 0.5f) * viewRect.rect.height;
                    float dGridPivotToGridCenter = _contTransform.rect.height * (_contTransform.pivot.y - 0.5f);
                    moveDistance = -dGridPivotToScrCenter + dGridPivotToGridCenter;
                }

                ResetPosition(_contTransform, 1, moveDistance);

                _startPosMin = (1 - anchorGridToScrollview) * viewRect.rect.height - _contTransform.rect.height * (1 - _contTransform.pivot.y);
                _startPosMax = _contTransform.rect.height * _contTransform.pivot.y - anchorGridToScrollview * viewRect.rect.height;
            }
            _lastContentSize = _contTransform.sizeDelta;
        }
    }