コード例 #1
0
    public void Init()
    {
        uiCtrlList.Clear();
        uiPopupList.Clear();

        GameObject goRoot = GameObject.Find(UI_ROOT_NAME);

        if (goRoot == null)
        {
            goRoot = new GameObject(UI_ROOT_NAME);

            GameObject page  = new GameObject(UI_ROOT_PAGE);
            GameObject above = new GameObject(UI_ROOT_ABOVE);
            GameObject popup = new GameObject(UI_ROOT_POPUP);

            page.transform.SetParent(goRoot.transform);
            above.transform.SetParent(goRoot.transform);
            popup.transform.SetParent(goRoot.transform);
        }

        if (null != goRoot)
        {
            m_tUIRoot    = goRoot.transform;
            m_tRootPage  = m_tUIRoot.Find(UI_ROOT_PAGE);
            m_tRootAbove = m_tUIRoot.Find(UI_ROOT_ABOVE);
            m_tRootPopup = m_tUIRoot.Find(UI_ROOT_POPUP);
        }

        GameObject[] rootObjects = UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects();

        rootObjects.ForEach(s =>
        {
            UiCtrl[] uis = s.GetComponentsInChildren <UiCtrl>(true);

            for (int i = 0; i < uis.Length; ++i)
            {
                UiCtrl v     = uis[i];
                string value = v.GetType().ToString();
                v.uiId.Set(value);
                v.SetActive(false);
                Canvas c = v.GetComponent <Canvas>();

                bool isWorldUi = false;

                if (c != null)
                {
                    if (v.sortingOrder > 0)
                    {
                        c.sortingOrder = v.sortingOrder;
                    }
                }

                if (isWorldUi == false)
                {
                    RectTransform rt = v.GetComponent <RectTransform>();

                    rt.SetParent(m_tRootPage);
                    rt.Reset();
                }

                uiCtrlList.Add(v);
            }
        });
    }
コード例 #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);
    }