/// <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); }
public override void InitUI() { base.InitUI(); Properties = new UIProperties( UIManager.SceneUIs.HelperWindowUI, UIManager.DisplayUIMode.HideOthers, UIManager.UITypes.AboveBlurEffect, false, true, true); #region Help info category dropdown menu if (m_HelpInfoCategory) { foreach (var item in Enum.GetValues(typeof(HelperInfoManager.HelpInfoCategory))) { m_HelpInfoCategory.options.Add(new Dropdown.OptionData() { text = HelperInfoManager.GetCategroyText((HelperInfoManager.HelpInfoCategory)item) }); } // We need this step to refresh the options list. m_HelpInfoCategory.value = 1; m_HelpInfoCategory.value = 0; // Set default values. m_CurrentSelectedCategoryIndex = 0; // Add event listener to the drop down menu. m_HelpInfoCategory.onValueChanged.AddListener((value) => OnSeletedHelperCategory(value)); } #endregion #region Help info list // Populate the help info buttons. if (HelpInfoButtonPrefab) { m_ButtonList.Clear(); for (int index = 0; index < m_HelpInfoButtonCount; index++) { HelpInfoButtonUI button = Instantiate(HelpInfoButtonPrefab).GetComponent <HelpInfoButtonUI>(); GameUtility.AddChildToParent(m_HelpInfoListRoot, button.transform); m_ButtonList.Add(button); button.Init(index); } OnUpdateHelperInfoButtonList(m_CurrentSelectedCategoryIndex); } else { #if UNITY_EDITOR Debug.LogError("HelpInfoButtonPrefab is NULL"); #endif } #endregion #region Helper info contents #if UNITY_EDITOR if (!m_HelperInfoHeader) { Debug.LogError("Helper info header is null"); } if (!m_HelperInfoImage) { Debug.LogError("Helper info image is null"); } if (!m_HelperInfoContext) { Debug.LogError("Helper info context is null"); } #endif #endregion #region Window active animation m_Animator = GetComponent <Animator>(); #if UNITY_EDITOR if (!m_Animator) { Debug.LogError("Animator component in " + this.gameObject.name + " is null."); } #endif #endregion if (!m_HelperWindowHeaderText) { Debug.LogError("Header text component in " + this.gameObject.name + " is null."); } if (!m_ReturnButton) { Debug.LogError("Return button component in " + this.gameObject.name + " is null."); } m_ReturnButton.onClick.AddListener(delegate { OnClickReturnButton(); }); SetLanguage(GameLanguageManager.CurrentLanguage); }