private Hashtable ht = null; //容器键值对集合 /// <summary> /// 得到实例(单例) /// </summary> /// <returns></returns> public static ResourcesMgr GetInstance() { if (_Instance == null) { _Instance = new GameObject("_ResourceMgr").AddComponent <ResourcesMgr>(); } return(_Instance); }
/// <summary> /// 从Resources中读取窗体预制体 /// </summary> /// <param name="uiFormName"></param> private BaseUIForm LoadUIForm(string strUIName) { //定义三个局部变量,需加载的UI预制体的路径,预制体本身,预制体上挂载的baseUiForm string strUIFormPaths = null; GameObject goCloneUIPrefabs = null; BaseUIForm baseUiForm = null; //根据UI窗体名称,得到对应的加载路径 _DicFormPaths.TryGetValue(strUIName, out strUIFormPaths); //如果未从缓存字典中得到集合 if (!string.IsNullOrEmpty(strUIFormPaths)) { //用自定义的资源读取脚本从路径中得到并生成预制体 goCloneUIPrefabs = ResourcesMgr.GetInstance().LoadAsset(strUIFormPaths, false); } else { Debug.Log("未将该uiFormName的路径加入缓存中,参数uiFormName=" + strUIName); } //从该预制体上得到BaseUiForm(窗体控制脚本,实际得到的是BaseUiForm的子类) if (_TraCanvasTransform != null && goCloneUIPrefabs != null) { baseUiForm = goCloneUIPrefabs.GetComponent <BaseUIForm>(); if (baseUiForm == null) { Debug.Log("baseUiForm==null! ,请先确认窗体预设对象上是否加载了baseUIForm的子类脚本! 参数 uiFormName=" + strUIName); return(null); } //根据BaseUiForm中持有的CurrentUIType类中的属性判断加载到哪个节点 switch (baseUiForm.CurrentUIType.UIForms_Type) { case UIFormType.Normal: goCloneUIPrefabs.transform.SetParent(_TraNormal, false); break; case UIFormType.PopUp: goCloneUIPrefabs.transform.SetParent(_TraPopUp, false); break; case UIFormType.Fixed: goCloneUIPrefabs.transform.SetParent(_TraFixed, false); break; default: break; } //设置隐藏 goCloneUIPrefabs.SetActive(false); } return(baseUiForm); }
BaseUI LoadUI(string UIName) { Debug.Log("从资源处加载UI"); string uiPath; GameObject UIPrefab = null; BaseUI baseUI = null; UIPath.TryGetValue(UIName, out uiPath); Debug.Log($"路径:{uiPath}"); if (!string.IsNullOrEmpty(uiPath)) { UIPrefab = ResourcesMgr.GetInstance().LoadAsset(uiPath, false); } if (nodeRoot != null && UIPrefab != null) { baseUI = UIPrefab.GetComponent <BaseUI>(); if (baseUI == null) { Debug.Log($"baseUI==null,请确认窗口是否有BaseUI脚本,参数:{UIName}"); return(null); } switch (baseUI.currentUIType.type) { case UIFormType.Normal: UIPrefab.transform.SetParent(nodeNormal, false); break; case UIFormType.Fixed: UIPrefab.transform.SetParent(nodeFixed, false); break; case UIFormType.PopUp: UIPrefab.transform.SetParent(nodePopUp, false); break; } UIPrefab.SetActive(false); cacheUIs.Add(UIName, baseUI); return(baseUI); } else { Debug.Log($"traRoot!=null Or UIPrefab!=null Please Check 参数{UIName}"); } Debug.Log($"出现不可预估的错误 参数{UIName}"); return(null); }
/// <summary> /// 初始化读取Canvas /// </summary> private void InitRootCanvasLoading() { ResourcesMgr.GetInstance().LoadAsset(SysDefine.SYS_PATH_CANVAS, false); }
/// <summary> /// 初始化加载(rootUI窗体)Canvas预制体 /// </summary> private void InitRootCanvasLoading() { ResourcesMgr.GetInstance().LoadAsset(SysDefine.canvasPath, false); }