IEnumerator LoadOutResource() { while (true) { if (waitToLoadList.Count > 0) { WaitLoadStruct tStruct = waitToLoadList[0]; string realPath = StringTool.Append(ResourcePath.GetAppOutResourcePath(), "/", tStruct.assetPath); WWW tWww = new WWW(realPath); yield return(tWww); if (tWww.error != null) { DebugHelper.Log(StringTool.Append("加载资源错误----> ", tWww.error, "--->", realPath)); } else { if (tStruct.onResourceLoaded != null) { UnityEngine.Object asset = tWww.assetBundle.mainAsset; tStruct.onResourceLoaded(asset); tWww.assetBundle.Unload(false); } waitToLoadList.RemoveAt(0); } } yield return(new WaitForEndOfFrame()); } }
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); } }