예제 #1
0
파일: UIMgr.cs 프로젝트: pilipalaBeng/Oasis
 public void SetAnchorScreenCenter(UIBase ui)
 {
     ui.GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, 0);
     ui.GetComponent <RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0, 0);
     ui.GetComponent <RectTransform>().anchorMin = Vector3.zero;
     ui.GetComponent <RectTransform>().anchorMax = Vector3.one;
 }
예제 #2
0
 // Start is called before the first frame update
 void OnEnable()
 {
     if (instance == null)
     {
         if (TooltipConfig.Singleton?.uiItemDialog != null && uiCharacterItem != null)
         {
             instance = TooltipConfig.Singleton.uiItemDialog;
         }
         if (TooltipConfig.Singleton?.uiSkillDialog != null && uiCharacterSkill != null)
         {
             instance = TooltipConfig.Singleton.uiSkillDialog;
         }
         if (instance != null)
         {
             uiRenderer = instance.GetComponent <Renderer>();
         }
     }
 }
예제 #3
0
    private void _OpenPanel(string uiName, bool closeBottom = false, params object[] args)
    {
        UIBase panel = uiStack.Find((p) => p.UIName.Equals(uiName));

        if (panel == null)
        {
            if (uiCache.ContainsKey(uiName))
            {
                panel = instance.uiCache[uiName];
                instance.uiCache.Remove(uiName);
            }
            else
            {
                GameObject uiPrefab = loader.GetUIByName(uiName);

                GameObject ui = Instantiate(uiPrefab);
                panel        = ui.GetComponent <UIBase>();
                panel.UIName = uiName;
                panel.OnInit();
            }

            CurrentUIPanel = panel;
            panel.Args     = args;
            panel.gameObject.SetActive(true);
            panel.transform.SetParent(instance.panelRoot);
            panel.transform.localPosition = Vector3.zero;
            panel.transform.localScale    = Vector3.one;

            RectTransform rtf = panel.GetComponent <RectTransform>();
            rtf.anchorMax = new Vector2(1, 1);
            rtf.anchorMin = new Vector2(0, 0);
            rtf.offsetMax = new Vector2(0, 0);
            rtf.offsetMin = new Vector2(0, 0);

            panel.OnRefresh();

            if (uiStack.Count > 0 && closeBottom)
            {
                UIBase lastPanel = uiStack[uiStack.Count - 1];
                lastPanel.gameObject.SetActive(false);
            }

            uiStack.Add(panel);
        }
        else
        {
            Debug.LogError(uiName + "已经打开");
        }
    }
예제 #4
0
 public void UIExit(UIBase ui, UIExitStyle style)
 {
     if (ui == null)
     {
         Debug.LogWarning("需要退出的UI不存在!");
         return;
     }
     if (!_uiList.Contains(ui))
     {
         Debug.LogWarning("需要退出的UI不在UI列表中!UI:" + ui.ToString());
         return;
     }
     _uiList.Remove(ui);
     OnUIExitStyle(ui.GetComponent <RectTransform>(), style, () => { Destroy(ui.gameObject); });
 }
예제 #5
0
    public void ElementInit()
    {
        //Debug.Log("ElementInit");

        for (int i = 0; i < 4; i++)
        {
            UIBase uiTmp = CreateItem(c_elementItem, "layout_element");
            m_elementList.Add(uiTmp);

            uiTmp.GetComponent <RectTransform>().anchoredPosition3D = new Vector3(-300 + i * 200, 200, 0);
        }

        InitElementPlanA();

        InitElementPlanB();

        //GlobalEvent.AddEvent(GameDataEvent.ElementList, ReceviceElementChange);

        ReceviceElementChange();
    }
예제 #6
0
    public UIBase CreateUI(UIID uiID)
    {
        UIBase rObj  = null;
        UIBase uiObj = null;

        // 1. Get UI file name via UIID
        string name = fileName[(int)uiID];

        // 2. Use UI file name to load UI from resources
        rObj = Resources.Load("Prefabs/Menus/" + name, typeof(UIBase)) as UIBase;

        // 3. GameObject.Instantiate
        uiObj = GameObject.Instantiate(rObj);

        uiObj.GetComponent <RectTransform> ().SetParent(rectTrans);
        uiObj.transform.localScale    = Vector3.one;
        uiObj.transform.localPosition = Vector3.zero;

        // hint: you may need an array to store ui file names

        return(uiObj);
    }
예제 #7
0
    protected override void Init()
    {
        kernel = GameKernel.GetInstance();

        m_uistacks   = new Stack <int>();
        m_uicache    = new UIBase[(int)UIPageEnum.Max];
        m_tips_cache = new List <int>();
        sb           = new StringBuilder(256);

        //生成uiroot
        GameObject temp = ResMgr.LoadGameObject(string.Format(m_UIPath, m_root_tag));

        //Debug.Log(string.Format(m_UIPath, m_root_tag));
        m_uiRoot = temp.GetComponentInChildren <UIBase>();
        m_canvas = m_uiRoot.GetComponent <Canvas>();

        //Debug.Log("init the muiRoot");
        GameObject.DontDestroyOnLoad(temp);
        //生成背景遮罩
        temp     = ResMgr.LoadGameObject(string.Format(m_UIPath, m_mask_tag), m_uiRoot.transform);
        m_bgMask = temp.GetComponent <UIMask>();
        m_bgMask.Hide();
    }
예제 #8
0
        /// <summary>
        /// Load UI form the resources folder based on the scene UI type.
        /// </summary>
        /// <param name="ui">The type of the scene UI</param>
        /// <returns>Return NULL if load resources process failed.</returns>
        public UIBase LoadUI(SceneUIs ui, Transform parent = null)
        {
            // If the target UI is already in list, ignore the call.
            if (m_NormalUIs.ContainsKey(ui) || m_UIWontDestoryThroughSceneChange.ContainsKey(ui))
            {
                return(null);
            }

            // Load the UI prefab form the resources folder.
            UIBase uiPrefab = Resources.Load <UIBase>(GetUIPrefabPath(ui));

            // If sucessfully loaded the UI prefab form the resource folder.
            if (uiPrefab != null)
            {
                // Instantiate a new object base on this prefab.
                UIBase uiGameObject = Instantiate(uiPrefab);
                // Init the UI.
                uiGameObject.InitUI();

                // Set UI gameObject's parent transform.
                switch (uiGameObject.Properties.GetUIType)
                {
                case UITypes.AboveBlurEffect:
                    if (!parent)
                    {
                        GameUtility.AddChildToParent(m_AboveBlurEffectRoot, uiGameObject.transform);
                    }
                    else
                    {
                        GameUtility.AddChildToParent(parent, uiGameObject.transform);
                    }
                    break;

                case UITypes.UnderBlurEffect:
                    if (!parent)
                    {
                        GameUtility.AddChildToParent(m_UnderBlurEffectRoot, uiGameObject.transform);
                    }
                    else
                    {
                        GameUtility.AddChildToParent(parent, uiGameObject.transform);
                    }
                    break;

                default:
#if UNITY_EDITOR
                    Debug.LogError("Unexpected switch case in UImanager's LoadUI method.");
#endif
                    return(null);
                }

                // Reset the UI rect transform.
                uiGameObject.GetComponent <RectTransform>().ExpandToMaxFormCenter();

                // Only the root UI will be store to the list.
                if (uiGameObject.Properties.IsRootUI)
                {
                    // Add the ui into appropriate list.
                    if (uiGameObject.Properties.WontDestoryWhenSceneChange)
                    {
                        m_UIWontDestoryThroughSceneChange.Add(ui, uiGameObject);
                    }
                    else
                    {
                        m_NormalUIs.Add(ui, uiGameObject);
                    }
                }

                // Reture result.
                return(uiGameObject);
            }
#if UNITY_EDITOR
            Debug.Log("Failed to load the UI prefab, the path to target prefab object: " + GetUIPrefabPath(ui));
#endif
            return(null);
        }