private int AddNewFrame(UIController uc)
        {
            Object[] selection = (Object[])Selection.objects;
            if (selection.Length == 0)
            {
                return(-1);
            }
            Dictionary <string, UIFrameItem> _liEditUse = ArrayConverseToList(uc._frameItems);
            string strFrameId = "";

            foreach (Object obj in selection)
            {
                UIFrameItem ufi = new UIFrameItem();
                GameObject  go  = (GameObject)obj;
                strFrameId = "ID_" + go.name;
                if (_liEditUse.ContainsKey(strFrameId))
                {
                    continue;
                }

                UIFrame uf = go.GetComponent <UIFrame>();
                if (uf == null)
                {
                    Debug.LogError("<color=red>[Error]</color>---" + obj + "上没有UIFrame组件!!", obj);
                    continue;
                }
                ufi._prefabFrame  = uf;
                uf.FrameId        = strFrameId;
                ufi._strFrameID   = uf.FrameId;
                ufi._nPannelIndex = 1;
                _liEditUse.Add(strFrameId, ufi);
            }
            uc._frameItems = ListConverseToArray(_liEditUse);
            return(_liEditUse.Count - 1);
        }
예제 #2
0
        /// <summary>
        /// 显示UI,没有实例化过就先实例化
        /// </summary>
        /// <param name="strFrameId"></param>
        /// <param name="actionAfterShow"></param>
        void _ShowUI(string strFrameId, System.Action <UIFrame> actionAfterShow = null)
        {
            // 如果已经加载过了,直接显示吧
            if (dictLoadedFrame.ContainsKey(strFrameId))
            {
                dictLoadedFrame[strFrameId].OnFrameShow();
                if (actionAfterShow != null)
                {
                    actionAfterShow(dictLoadedFrame[strFrameId]);
                }
                return;
            }

            // 判断配置是否存在
            if (!dictItems.ContainsKey(strFrameId))
            {
                Debug.LogError("<color=red>[Error]</color>---" + "找不到窗口:" + strFrameId);
                return;
            }

            // 实例化窗口
            UIFrame frame = GameObject.Instantiate(dictItems[strFrameId]._prefabFrame) as UIFrame;

            if (frame != null)
            {
                frame.FrameId = strFrameId;
                frame.OnFrameLoad();
                frame.transform.SetParent(uiRoot.GetPannel(dictItems[strFrameId]._nPannelIndex).transform);
                frame.transform.localScale    = Vector3.one;
                frame.transform.localPosition = Vector3.zero;
                dictLoadedFrame.Add(strFrameId, frame);
                frame.OnFrameShow();

                if (actionAfterShow != null)
                {
                    actionAfterShow(dictLoadedFrame[strFrameId]);
                }
            }
        }