/// <summary> /// Resource异步加载; /// </summary> /// <typeparam name="T">ctrl</typeparam> /// <param name="type">资源类型</param> /// <param name="assetName">资源名字</param> /// <param name="action">资源回调</param> /// <param name="progress">进度回调</param> /// <returns></returns> public IEnumerator <float> LoadResAsync <T>(AssetType type, string assetName, Action <T> action, Action <float> progress) where T : Object { string path = FilePathUtility.GetResourcePath(type, assetName); IAssetLoader <T> loader = CreateLoader <T>(type); T ctrl = null; bool isInstance = false; if (path != null) { ResourceRequest request = Resources.LoadAsync <T>(path); while (request.progress < 0.99) { if (progress != null) { progress(request.progress); } yield return(Timing.WaitForOneFrame); } while (!request.isDone) { yield return(Timing.WaitForOneFrame); } ctrl = loader.GetAsset(request.asset as T, out isInstance); } if (action != null) { action(ctrl); } else { LogUtil.LogUtility.PrintError(string.Format("[ResourceMgr]LoadResAsync Load Asset {0} failure!", assetName + "." + type.ToString())); } }
/// <summary> /// Resource同步加载; /// </summary> /// <typeparam name="T">ctrl</typeparam> /// <param name="type">资源类型</param> /// <param name="assetName">资源名字</param> /// <returns>ctrl</returns> public T LoadResSync <T>(AssetType type, string assetName) where T : Object { string path = FilePathUtility.GetResourcePath(type, assetName); IAssetLoader <T> loader = CreateLoader <T>(type); bool isInstance = false; if (path != null) { T ctrl = Resources.Load <T>(path); if (ctrl != null) { return(loader.GetAsset(ctrl, out isInstance)); } } LogUtil.LogUtility.PrintError(string.Format("[ResourceMgr]LoadResSync Load Asset {0} failure!", assetName + "." + type.ToString())); return(null); }