Example #1
0
 public UIStackChunk(string ui, BasePlane bp, UIConfigChunk cc, params object[] args)
 {
     UIPath = ui; UIBasePlane = bp; ConfigChunk = cc; Args = args;
 }
Example #2
0
        /// <summary>
        /// 打开ui
        /// </summary>
        public void OpenUI(string ui, UIConfigChunk chunk, params object[] args)
        {
            if (chunk.UIResType == ResType.ResourceLoad && chunk.UICacheType == CacheType.Cache)
            {
                TimeLogger.LogError("ui conflict restype and cache type:" + ui);
                return;
            }
            if (_stack.Count != 0)
            {
                var peek = _stack.Peek();
                if (peek.UIPath == ui)
                {
                    return;
                }
                if (peek.ConfigChunk.UIWinType == WindowType.PopUp)
                {
                    _stack.Pop();
                    Recycle(peek);
                }
                else if (peek.ConfigChunk.UIWinType == WindowType.FullScreen)
                {
                    if (peek.ConfigChunk.UIOpenType == OpenType.Back)
                    {
                        Recycle(peek);
                    }
                }
            }
            UIStackChunk cacheStackChunk = null;

            foreach (var stackChunk in _stack)
            {
                if (stackChunk.UIPath == ui && null != stackChunk.UIBasePlane)
                {
                    cacheStackChunk = stackChunk;
                    break;
                }
            }
            BasePlane bp = null;

            if (null == cacheStackChunk)
            {
                GameObject bpGo;
                if (chunk.UIResType == ResType.ResourceLoad)
                {
                    var res = Resources.Load <GameObject>(ui);
                    bpGo = GameObject.Instantiate(res);
                }
                else
                {
                    if (chunk.UICacheType == CacheType.Cache)
                    {
                        bpGo = _pool.Get(ui, chunk);
                    }
                    else
                    {
                        bpGo = AssetBundleMgr.instance.GetAssetBundle(ui).LoadAsset <GameObject>(Path.GetFileNameWithoutExtension(ui));
                    }
                }
                bpGo.transform.parent = Origin;

                bp = bpGo.GetComponent <BasePlane>();

                var rt = bp.GetComponent <RectTransform>();
                rt.offsetMax  = Vector2.zero;
                rt.offsetMin  = Vector2.zero;
                rt.localScale = Vector3.one;

                bp.UIPath = ui;
                bp.OnOpen(args);
            }
            else
            {
                bp = cacheStackChunk.UIBasePlane;
                cacheStackChunk.UIBasePlane = null;
            }
            var uiStackChunk = new UIStackChunk(ui, bp, chunk, args);

            _stack.Push(uiStackChunk);
        }