/// <summary> /// 加载指定名称UI窗体 /// 功能: /// 1.根据“UI窗体枚举”,加载预设克隆体 /// 2.根据不同预设克隆体中带的脚本中不同的“位置信息”,加载到根窗体下不同的节点 /// 3.隐藏刚创建的UI克隆体 /// 4.把克隆体加入到所有UI窗体的缓存集合中 /// </summary> /// <param name="winType">UI窗体枚举</param> /// <returns></returns> private BaseUIForms LoadUIForm(EM_WinType winType) { string strUIFormPath = null; //UI窗体的查询路径 GameObject goCloneUIPrefab = null; //创建的UI克隆体 BaseUIForms baseUiForms = null; //窗体基类 //根据UI窗体名称,得到对应的加载路径 _DictionaryPaths.TryGetValue(winType, out strUIFormPath); //根据UI窗体名称,加载预设克隆体 if (!string.IsNullOrEmpty(strUIFormPath)) { goCloneUIPrefab = ResourcesMgr.GetInstance().LoadAsset(strUIFormPath, false); } else { LogMgr.GetInstance().Log(LogEnum.Error, "加载UI窗体出错,没有找到" + winType.ToString() + "窗口的路径"); return(null); } //设置UI克隆体的父节点 根据克隆体中带的脚本中不同的“位置信息” if (_TraCanvasTranform != null && goCloneUIPrefab != null) { baseUiForms = goCloneUIPrefab.GetComponent <BaseUIForms>(); //得到这个克隆体里面的BaseUIForms脚本 if (baseUiForms == null) { LogMgr.GetInstance().Log(LogEnum.Error, "baseUIForms为空,请先确认窗体预设对象是否已经加载了子类脚本,UIFormName=" + winType.ToString()); return(null); } if (baseUiForms.GetUIType() == UIFormType.Full) { goCloneUIPrefab.transform.SetParent(_TraNormal, false); } else if (baseUiForms.GetUIType() == UIFormType.PopUp) { goCloneUIPrefab.transform.SetParent(_TraPopUp, false); } //设置隐藏 初始时应该是隐藏的,因为不知道需不需要一开始就显示 goCloneUIPrefab.SetActive(false); //把克隆体加入到所有UI窗体缓存集合中 if (!_DicAllUiFormses.ContainsKey(winType)) { _DicAllUiFormses.Add(winType, baseUiForms); } return(baseUiForms); } return(null); }
/// <summary> /// 得到窗口 因为资源都是同步加载的,直接取就行 /// </summary> /// <param name="winType"></param> /// <returns></returns> public BaseUIForms GetWinForm(EM_WinType winType) { if (_DicAllUiFormses.ContainsKey(winType)) { return(_DicAllUiFormses[winType]); } else { LogMgr.GetInstance().Log(LogEnum.Error, "当前没有打开" + winType.ToString() + "窗口"); return(null); } }