예제 #1
0
    public void CloseUi(UiId uiId)
    {
        UiCtrl ui = GetUi(uiCtrlList, uiId);

        if (ui != null)
        {
            ui.Close();
        }
    }
예제 #2
0
    void Start()
    {
        Me           = this;
        _hpBar       = transform.GetChild(0).gameObject.AddComponent <HpBar>();
        _floatButton = transform.GetChild(1).gameObject.AddComponent <FloatButton>();
        _win         = transform.GetChild(3).gameObject;
        _lose        = transform.GetChild(2).gameObject;

        _win.gameObject.SetActive(false);
        _lose.gameObject.SetActive(false);
    }
예제 #3
0
    protected override void Awake()
    {
        base.Awake();

        uiCtrlList.Clear();
        uiPopupList.Clear();

        _currUi = null;

        EAMainFrame.instance.OnMainFrameFacilityCreated(MainFrameAddFlags.UiManager);
    }
예제 #4
0
    // Start is called before the first frame update
    void Start()
    {
        _rb       = GetComponent <Rigidbody2D>();
        _anim     = GetComponent <Animator>();
        _collider = GetComponent <CapsuleCollider2D>();
        _uiCtrl   = GameObject.FindWithTag("UI").GetComponent <UiCtrl>();
        health    = maxHealth;

        _uiCtrl.MinHealth = 0;
        _uiCtrl.MaxHealth = maxHealth;
        _uiCtrl.Health    = maxHealth;
    }
예제 #5
0
    // get ui
    public UiCtrl GetUi(List <UiCtrl> list, UiId uiId)
    {
        UiCtrl result = null;

        for (int i = 0; i < list.Count; i++)
        {
            if (list[i].uiId == uiId)
            {
                result = list[i];
                break;
            }
        }

        return(result);
    }
예제 #6
0
 private void Awake()
 {
     enabled    = false;
     mainCamera = Camera.main;
     ui         = GetComponent <UiCtrl>();
 }
예제 #7
0
 private void Start()
 {
     ui = GetComponent <UiCtrl>();
 }
예제 #8
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);
            }
        });
    }
예제 #9
0
    public void CloseUi(UiCtrlBase uiCtrlBase, UiResult result = null)
    {
        UiCtrl uiCtrl = (UiCtrl)uiCtrlBase as UiCtrl;

        if (uiCtrl == null)
        {
            return;
        }

        if (uiCtrl._uiState == UiState.WillDestroy)
        {
            return;
        }

        if (_currUi == uiCtrl)
        {
            _currUi = null;
        }

        UiCtrl popup_ui = GetUi(uiPopupList, uiCtrl.uiId);

        if (popup_ui != null)
        {
            uiPopupList.Remove(popup_ui);
        }

        uiCtrl._Deactivate();
        uiCtrl._OnWillDestroy();

        Delegate resultCbD = uiCtrl._resultCbD;

        if (uiCtrl._resultCbD != null)
        {
            if (result == null)
            {
                result      = uiCtrl.uiResult;
                result.btId = ButtonId.Cancel;
            }
            else
            {
                if (result.GetType() != uiCtrl.GetResultType())
                {
                    Debug.Assert(false, @"ResultType must be '" + uiCtrl.GetResultType() + @"' not '" + result.GetType() + @"'.");
                }
            }
            result.uiCtrl = uiCtrl;
        }

        if (uiCtrl._resultCbD != null)
        {
            if (result == null)
            {
                result      = uiCtrl.uiResult;
                result.btId = ButtonId.Cancel;
            }
            else
            {
                if (result.GetType() != uiCtrl.GetResultType())
                {
                    Debug.Assert(false, @"ResultType must be '" + uiCtrl.GetResultType() + @"' not '" + result.GetType() + @"'.");
                }
            }
            result.uiCtrl = uiCtrl;
        }

        if (resultCbD != null)
        {
            resultCbD.DynamicInvoke(new object[] { result });
        }
    }
예제 #10
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);
    }
예제 #11
0
 public virtual void Clear()
 {
     n      = 10;
     btId   = "";
     uiCtrl = null;
 }