public static void LoadResource(string assetPath, ResourcePathType pathType, OnResourceLoaded onResourceLoaded) { if (pathType == ResourcePathType.Resource) { UnityEngine.Object obj = Resources.Load(assetPath); if (onResourceLoaded != null) { onResourceLoaded(obj); } } else if (pathType == ResourcePathType.Persistant) { WaitLoadStruct tStruct = new WaitLoadStruct(); tStruct.assetPath = assetPath; tStruct.onResourceLoaded = onResourceLoaded; waitToLoadList.Add(tStruct); } }
/// <summary> /// 通过相对路径获得资源的真实路径 /// </summary> public void GetResoureActualPath(string relativePath, out string actualPath, out ResourcePathType type) { //如果使用本地bundle,则无视热更新目录 if (UseLocalBundle) { actualPath = string.Format(@"{0}/{1}", Application.streamingAssetsPath, relativePath); if (File.Exists(actualPath)) { type = ResourcePathType.InLocal; } else { type = ResourcePathType.Invalid; } return; } //首先判断热更新目录是否存在 string hotPath = string.Format(@"{0}/{1}", Application.persistentDataPath, relativePath); if (File.Exists(hotPath)) { actualPath = hotPath; type = ResourcePathType.InHot; return; } //热更新目录不存在,判断本地资源是否存在 string localPath = string.Format(@"{0}/{1}", Application.streamingAssetsPath, relativePath); if (File.Exists(localPath)) { actualPath = localPath; type = ResourcePathType.InLocal; return; } //都不存在,返回Invalid和hotPath,因为可能之后会从服务端下载资源,存放在热更新目录 actualPath = hotPath; type = ResourcePathType.Invalid; }