public void HideUI(SceneUIs ui) { if (m_NormalUIs.ContainsKey(ui)) { HideUI(m_NormalUIs[ui]); } if (m_UIWontDestoryThroughSceneChange.ContainsKey(ui)) { HideUI(m_UIWontDestoryThroughSceneChange[ui]); } }
public T GetUI <T>(SceneUIs ui) where T : UIBase { if (m_NormalUIs.ContainsKey(ui)) { return((T)m_NormalUIs[ui]); } if (m_UIWontDestoryThroughSceneChange.ContainsKey(ui)) { return((T)m_UIWontDestoryThroughSceneChange[ui]); } return(null); }
public UIBase GetUI(SceneUIs ui) { if (m_NormalUIs == null || m_UIWontDestoryThroughSceneChange == null) { return(null); } if (m_NormalUIs.ContainsKey(ui)) { return(m_NormalUIs[ui]); } if (m_UIWontDestoryThroughSceneChange.ContainsKey(ui)) { return(m_UIWontDestoryThroughSceneChange[ui]); } return(null); }
/// <summary> /// Get the ui prefab object path in the resources folder. /// </summary> /// <param name="ui">The target scene UI.</param> /// <returns>Return path to resources folder.</returns> private string GetUIPrefabPath(SceneUIs ui) { return(m_UIResourcesFolderPath + ui.ToString()); }
/// <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); }