protected bool m_IsLoadSceneAsset = false; //标识是否是加载场景资源 #region 加载资源 public static BridgeLoader LoadAsset(string url, LoadAssetModel loadModel, System.Action <BaseAbstracResourceLoader> onCompleteAct, bool isloadSceneAsset) { switch (loadModel) { case LoadAssetModel.None: Debug.LogError("异常的加载默认 LoadAssetModel.None 是默认的值 ,使用前请正确赋值"); return(null); case LoadAssetModel.Sync: return(LoadAssetSync(url, onCompleteAct, isloadSceneAsset)); case LoadAssetModel.Async: #if UNITY_EDITOR if (Application.isPlaying == false) { Debug.LogError("编辑器下非运行模式不要使用异步模式"); return(null); } #endif return(LoadAssetAsync(url, onCompleteAct, isloadSceneAsset)); default: Debug.LogError("没有定义的加载类型 " + loadModel); return(null); } }
/// <summary> /// 加载声音资源 /// </summary> /// <param name="url"></param> /// <param name="parent"></param> /// <param name="callback"></param> private void LoadAudio(string url, Transform parent, LoadAssetModel loadModel, System.Action <AudioClip> callback) { AudioLoader.LoadAudioClip(parent, url, loadModel, (loader) => { ResourcesLoadTraceMgr.Instance.RecordTraceResourceInfor(loader); #region 加载成功后的处理逻辑 if (loader == null || (loader.IsCompleted && loader.IsError)) { Debug.LogError("LoadMaterial Fail,Not Exit At Path= " + url); if (callback != null) { callback.Invoke(null); } return; } //加载资源出错 AudioClip clip = loader.ResultObj as AudioClip; if (callback != null) { callback.Invoke(clip); } #endregion }); }
/// <summary> /// WWW 方式异步加载资源 /// </summary> /// <param name="topPath">资源相对目录前的绝对目录</param> /// <param name="url">资源相对目录</param> /// <param name="onCompleteAct"></param> /// <returns></returns> public static WWWLoader WWWLoadAsset(string topPath, LoadAssetModel loadModel, string url, System.Action <BaseAbstracResourceLoader> onCompleteAct) { if (loadModel != LoadAssetModel.Async) { Debug.LogError("WWWLoader 只支持异步加载资源"); return(null); } if (string.IsNullOrEmpty(url)) { Debug.LogError(string.Format("Url Can't Be Null , TypeLoader={0}", typeof(WWWLoader))); return(null); } bool isLoaderExit = false; Debug.LogInfor("WWWLoadAsset url=" + url); WWWLoader wwwLoader = ResourcesLoaderMgr.GetOrCreateLoaderInstance <WWWLoader>(url, ref isLoaderExit); wwwLoader.m_OnCompleteAct.Add(onCompleteAct); if (isLoaderExit) { if (wwwLoader.IsCompleted) { wwwLoader.OnCompleteLoad(wwwLoader.IsError, wwwLoader.Description, wwwLoader.ResultObj, true); //如果当前加载器已经完成加载 则手动触发事件 } return(wwwLoader); //如果已经存在 且当前加载器还在加载中,则只需要等待加载完成则回调用回调 } wwwLoader.m_TopPath = topPath; wwwLoader.m_LoadAssetCoroutine = EventCenter.Instance.StartCoroutine(wwwLoader.LoadAssetAsync(topPath, url, wwwLoader)); return(wwwLoader); }
/// <summary> /// 加载材质球 /// </summary> /// <param name="url"></param> /// <param name="target"></param> /// <param name="callback"></param> private void LoadMaterial(string url, Transform target, LoadAssetModel loadModel, System.Action <Material> callback) { MaterialLoader.LoadAsset(target, url, loadModel, (loader) => { ResourcesLoadTraceMgr.Instance.RecordTraceResourceInfor(loader); #region 加载成功后的处理逻辑 if (loader == null || (loader.IsCompleted && loader.IsError)) { Debug.LogError("LoadMaterial Fail,Not Exit At Path= " + url); if (callback != null) { callback.Invoke(null); } return; } //加载资源出错 Material mat = loader.ResultObj as Material; if (callback != null) { callback.Invoke(mat); } #endregion }); }
public static MaterialLoader LoadAsset(Transform requestTarget, string url, LoadAssetModel loadModel, System.Action <BaseAbstracResourceLoader> completeHandler) { switch (loadModel) { case LoadAssetModel.None: Debug.LogError("异常的加载默认 LoadAssetModel.None 是默认的值 ,使用前请正确赋值"); return(null); case LoadAssetModel.Sync: return(LoadAssetSync(requestTarget, url, completeHandler)); case LoadAssetModel.Async: return(LoadAssetAsync(requestTarget, url, completeHandler)); default: Debug.LogError("没有定义的加载类型 " + loadModel); return(null); } }
protected FileStream fileStream = null; //读取文件的流对象 #region 资源加载 /// <summary> /// 资源加载统一接口 /// </summary> /// <param name="url"></param> /// <param name="loadModel">同步异步加载模式</param> /// <param name="onCompleteAct"></param> /// <returns></returns> public static ByteLoader LoadAsset(string url, LoadAssetModel loadModel, System.Action <BaseAbstracResourceLoader> onCompleteAct) { switch (loadModel) { case LoadAssetModel.None: Debug.LogError("异常的加载默认 LoadAssetModel.None 是默认的值 ,使用前请正确赋值"); return(null); case LoadAssetModel.Sync: return(LoadAssetSync(url, onCompleteAct)); case LoadAssetModel.Async: return(LoadAssetAsync(url, onCompleteAct)); default: Debug.LogError("没有定义的加载类型 " + loadModel); return(null); } }
public static SceneLoader LoadScene(string url, LoadAssetModel loadModel, System.Action <BaseAbstracResourceLoader> completeHandler) { switch (loadModel) { case LoadAssetModel.None: Debug.LogError("异常的加载默认 LoadAssetModel.None 是默认的值 ,使用前请正确赋值"); return(null); case LoadAssetModel.Sync: return(LoadSceneSync(url, completeHandler)); case LoadAssetModel.Async: return(LoadSceneAsync(url, completeHandler)); default: Debug.LogError("没有定义的加载类型 " + loadModel); return(null); } }
/// <summary> /// 加载字体资源 /// </summary> /// <param name="url"></param> /// <param name="callback"></param> private void LoadFont(string url, LoadAssetModel loadModel, System.Action <Font> callback) { FontLoader.LoadFontAsset(url, loadModel, (loader) => { ResourcesLoadTraceMgr.Instance.RecordTraceResourceInfor(loader); #region 加载成功后的处理逻辑 if (loader == null || (loader.IsCompleted && loader.IsError)) { Debug.LogError("LoadFont Fail,Not Exit At Path= " + url); if (callback != null) { callback.Invoke(null); } return; } //加载资源出错 if (callback != null) { callback.Invoke(loader.ResultObj as Font); } #endregion }); }
/// <summary> /// 加载已经打成Prefab的预制体的资源的Sprite 精灵 /// </summary> /// <param name="targetImag"></param> /// <param name="url"></param> /// <param name="callback"></param> private void LoadSprite(string url, UnityEngine.UI.Image targetImag, LoadAssetModel loadModel, System.Action <Sprite> callback) { SpriteLoader.LoadAsset(targetImag.transform, url, loadModel, (loader) => { #region 加载成功后的处理逻辑 ResourcesLoadTraceMgr.Instance.RecordTraceResourceInfor(loader); if (loader == null || (loader.IsCompleted && loader.IsError)) { Debug.LogError("LoadSprite Fail,Not Exit At Path= " + url); if (callback != null) { callback.Invoke(null); } return; } //加载资源出错 targetImag.sprite = loader.ResultObj as Sprite; if (callback != null) { callback.Invoke(targetImag.sprite); } #endregion }); }
/// <summary> /// AssetBundle 加载资源 /// </summary> /// <param name="url">标识当前需要加载的AssetBundel 资源路径</param> /// <param name="assetFileName">在这个AssetBundel 中的资源名称</param> /// <param name="loadModel"></param> /// <param name="assetBundleState">标识是单独的AssetBundle 还是文件夹组成的AssetBundle</param> /// <param name="isloadSceneAsset">标识是否是场景资源加载</param> /// <returns></returns> public static NewAssetBundleLoader3 LoadAssetBundleAsset(string url, string assetFileName, LoadAssetModel loadModel, AssetBundleExitState assetBundleState, bool isloadSceneAsset) { if (assetBundleState == AssetBundleExitState.None) { Debug.LogError("LoadAssetBundleAsset Fail,Not AssetBundle Asset url=" + url); return(null); } url = url.ToLower(); assetFileName = assetFileName.ToLower(); switch (loadModel) { case LoadAssetModel.None: Debug.LogError("异常的加载默认 LoadAssetModel.None 是默认的值 ,使用前请正确赋值"); return(null); case LoadAssetModel.Sync: return(LoadAssetBundleAssetSync(url, assetFileName, assetBundleState, isloadSceneAsset)); case LoadAssetModel.Async: return(LoadAssetBundleAssetAsync(url, assetFileName, assetBundleState, isloadSceneAsset)); default: Debug.LogError("没有定义的加载类型 " + loadModel); return(null); } }
/// <summary> /// 根据指定的路径加载一个预制体资源并生成对应的实例 /// </summary> /// <param name="url">资源唯一路径</param> /// <param name="parent">实例生成后挂载在那个父节点下</param> /// <param name="callback">加载资源成功后的回调</param> /// <param name="isActivate">默认为tue 标识生成的实例为激活状态</param> /// <param name="isResetTransProperty">默认为tue 标识是否重置生成对象的Transform 属性</param> /// <returns></returns> private void Instantiate(string url, Transform parent, LoadAssetModel loadModel, System.Action <GameObject> callback, bool isActivate = true, bool isResetTransProperty = true) { #if UNITY_EDITOR Debug.LogEditorInfor(string.Format("[ResourcesMgr ] Instantiate Begin >>>> url={0} LoadModel={1} Time={2} RederFrameCont={3}", url, loadModel, Time.realtimeSinceStartup, Time.renderedFrameCount)); #endif if (string.IsNullOrEmpty(url)) { if (callback != null) { callback(null); } return; } PrefabLoader.LoadAsset(parent, url, loadModel, (loader) => { #region 加载成功后的处理逻辑 ResourcesLoadTraceMgr.Instance.RecordTraceResourceInfor(loader); if (loader == null || loader.ResultObj == null || (loader.IsCompleted && loader.IsError)) { Debug.LogError("Instantiate GameObject Fail,Not Exit At Path= " + url); if (callback != null) { callback.Invoke(null); } return; } //加载资源出错 GameObject prefabGo = loader.ResultObj as GameObject; if (prefabGo == null) { Debug.LogError("Instantiate GameObject Fail,Load Result Not GameObject Type " + loader.ResultObj.GetType()); if (callback != null) { callback.Invoke(null); } return; } if (isActivate == false) { prefabGo.SetActive(false); //临时改变预制体资源的可见性 返回前恢复 } GameObject go = GameObject.Instantiate(prefabGo, parent); go.name = prefabGo.name; if (isResetTransProperty) { if (go.transform is RectTransform) { (go.transform as RectTransform).ResetRectTransProperty(); } else { go.transform.ResetTransProperty(); } } if (isActivate == false) { prefabGo.SetActive(true); //恢复可见性 } #if UNITY_EDITOR Debug.LogEditorInfor(string.Format("[ResourcesMgr ] Instantiate Complete <<<<< url={0} LoadModel={1} Time={2} RederFrameCont={3}", url, loadModel, Time.realtimeSinceStartup, Time.renderedFrameCount)); #endif if (callback != null) { callback.Invoke(go); } #endregion }); }
protected BaseAbstracResourceLoader() { ResetLoader(0); //创建 时候引用计数为0 LoadassetModel = LoadAssetModel.None; }