Exemplo n.º 1
0
        public Tuple <Transform, Transform> Show(UiId id)
        {
            GameObject ui = GetPrefabObject(id);

            if (ui == null)
            {
                Debug.LogError("can not find prefab " + id.ToString());
                return(null);
            }

            UIBase uiScript = GetUiScript(ui, id);

            if (uiScript == null)
            {
                return(null);
            }

            // 初始化UI对应的父物体
            InitUi(uiScript);

            Transform hideUI = null;

            if (uiScript.GetUiLayer() == UILayer.BASIC_UI)
            {
                uiScript.uiState = UIState.SHOW;
                hideUI           = Hide();
            }
            else
            {
                uiScript.uiState = UIState.SHOW;
            }

            _uiStack.Push(uiScript);

            return(new Tuple <Transform, Transform>(ui.transform, hideUI));   //Item1:要显示的UI, Item2:要隐藏的UI
        }
Exemplo n.º 2
0
    public UiCtrl ActiveUi(UiId uiId, UiParam param = null,
                           UISpawntype spawnType    = UISpawntype.EUIPage,
                           bool push = true, bool clearstack = false)
    {
        UiCtrl ui = GetUi(uiCtrlList, uiId);

        if (ui == null)
        {
            var prefab = ResourceManager.instance.CreateUI(spawnType, uiId.ToString());

            if (prefab == null)
            {
                Debug.Assert(prefab != null, " ui resource is null spawnTyp : " + spawnType + " uiId :" + uiId.ToString());
                return(null);
            }

            ui = prefab.GetComponent <UiCtrl>();
            string value = ui.GetType().ToString();
            ui.uiId.Set(value);
            ui.SetActive(false);
        }

        if (ui != null && ui.gameObject != null)
        {
            RectTransform rt = ui.GetComponent <RectTransform>();

            Transform parent = (spawnType == UISpawntype.EUIPage) ? m_tRootPage : (spawnType == UISpawntype.EUIAbove) ? m_tRootAbove : m_tRootPopup;

            rt.SetParent(parent);
            rt.Reset();

            if (param == null)
            {
                param = new UiParam();
            }

            if (ui._uiParamBase != null)
            {
                ui._uiParamBase.Clear();
            }

            if (ui.uiResult != null)
            {
                ui.uiResult.Clear();
            }

            ui.SetUiParam(param);

            ui._Activate();

            ui.SetActive(true);

            ui._Init();

            if (clearstack)
            {
                _prevSections.Clear();
            }

            if (push)
            {
                UiCtrl uisection = ui.GetComponent <UiCtrl>() as UiCtrl;

                if (uisection != null)
                {
                    StackSection s = new StackSection();
                    s.uiId.Set(uisection.uiId);
                    s.param     = param;
                    s.spawnType = spawnType;
                    _prevSections.Insert(0, s);
                }
            }

            bool bPopup = (UISpawntype.EUIPopup == spawnType);

            if (!bPopup)
            {
                _currUi = ui;
                uiCtrlList.Add(ui);
            }

            if (bPopup)
            {
                uiPopupList.Add(ui);
            }
        }

        return(ui);
    }
Exemplo n.º 3
0
        /// <summary>
        /// 加载要显示的UI预制体,如果加载过则从缓存中读取
        /// </summary>
        /// <param name="id">要加载的UiId</param>
        /// <returns>UI GameObject</returns>
        private GameObject GetPrefabObject(UiId id)
        {
            if (!_prefabDictionary.ContainsKey(id) || _prefabDictionary[id] == null)
            {
                GameObject prefab = LoadManager.Single.Load <GameObject>(Path.UI_PATH, id.ToString());
                if (prefab != null)
                {
                    _prefabDictionary[id] = Instantiate(prefab);
                }
                else
                {
                    Debug.LogError("can not find prefab name : " + id);
                }
            }

            return(_prefabDictionary[id]);
        }
Exemplo n.º 4
0
 public void Set(UiId rhs)
 {
     Set(rhs.ToString());
 }