public override void Init(string url, params object[] args) { #if UNITY_EDITOR if (KResourceModule.IsEditorLoadAsset) { base.Init(url); LoadInEditor(url); return; } #endif #if UNITY_5 || UNITY_2017_1_OR_NEWER PreLoadManifest(); #endif base.Init(url); _loaderMode = (LoaderMode)args[0]; if (NewAssetBundleLoaderEvent != null) { NewAssetBundleLoaderEvent(url); } RelativeResourceUrl = url; if (AppConfig.IsLogAbLoadCost) { Log.Info("[Start] Load AssetBundle, {0}", RelativeResourceUrl); } KResourceModule.Instance.StartCoroutine(LoadAssetBundle(url)); }
protected IEnumerator InitCo(string url, LoaderMode mode) { //获取资源的真实路径 string actualUrl; ResourcePathType type; ResourceLoaderSingleton.Instance.GetResoureActualPath(url, out actualUrl, out type); //如果资源路径无效,且允许运行时下载,尝试从服务端下载 if (type == ResourcePathType.Invalid && ResourceLoaderSingleton.Instance.HotFixType == ResourceHotFixType.Runtime) { if (mode == LoaderMode.Sync) { ResourceLoaderSingleton.Instance.DownloadFile(url); } else { yield return(ResourceLoaderSingleton.Instance.DownloadFileAsync(url)); } } if (mode == LoaderMode.Sync) { Bytes = ResourceLoaderSingleton.Instance.ReadAllBytes(actualUrl); } else { //TODO 异步加载 yield return(null); } OnFinish(null); }
protected override void Init(string url, params object[] args) { base.Init(url, args); _loaderMode = (LoaderMode)args[0]; KResourceModule.Instance.StartCoroutine(CoLoad(url)); }
protected override void Init(string url, params object[] args) { base.Init(url, args); _loaderMode = (LoaderMode)args[0]; KResourceModule.Instance.StartCoroutine(CoLoad(url)); }
protected override void Init(string url, params object[] args) { base.Init(url, args); LoaderMode mode = (LoaderMode)args[0]; //TODO ResourceLoaderSingleton.Instance.StartCoroutine(InitCo(url, mode)); }
protected override void Init(string url, params object[] args) { base.Init(url, args); _mode = (LoaderMode)args[0]; _url = url; _sceneName = Path.GetFileNameWithoutExtension(_url); KResourceModule.Instance.StartCoroutine(Start()); }
protected override void Init(string url, params object[] args) { base.Init(url, args); _mode = (LoaderMode)args[0]; _url = url; _sceneName = Path.GetFileNameWithoutExtension(_url); KResourceModule.Instance.StartCoroutine(Start()); }
internal static void LogLoadTime(string resType, LoaderMode loadMode, string resPath, System.DateTime begin) { if (LogLevel < LoadingLogLevel.ShowTime) { return; } Debug.LogFormat("[Load] {0}, {1}, {2}, {3}s", resType, loadMode, resPath, (System.DateTime.Now - begin).TotalSeconds); }
public static SceneLoader Load(string url, System.Action<bool> callback = null, LoaderMode mode = LoaderMode.Async) { LoaderDelgate newCallback = null; if (callback != null) { newCallback = (isOk, obj) => callback(isOk); } return AutoNew<SceneLoader>(url, newCallback, false, mode); }
protected override void Init(string url, params object[] args) { ResManager.PreLoadManifest(); base.Init(url); _loaderMode = (LoaderMode)args[0]; ResManager.LogRequest("AssetBundle", url); ResManager.Instance.StartCoroutine(_LoadCoroutine(url)); }
public static StaticAssetLoader Load(string url, AssetFileLoader.AssetFileBridgeDelegate callback = null, LoaderMode loaderMode = LoaderMode.Async) { LoaderDelgate newCallback = null; if (callback != null) { newCallback = (isOk, obj) => callback(isOk, obj as UnityEngine.Object); } return AutoNew<StaticAssetLoader>(url, newCallback, false, loaderMode); }
public static SceneLoader Load(string url, System.Action <bool> callback = null, LoaderMode mode = LoaderMode.Async) { LoaderDelgate newCallback = null; if (callback != null) { newCallback = (isOk, obj) => callback(isOk); } return(AutoNew <SceneLoader>(url, newCallback, false, mode)); }
protected override void Init(string bundlePath, params object[] args) { base.Init(bundlePath, args); LoaderMode mode = (LoaderMode)args[0]; string fullBundlePath = string.Format(@"{0}/{1}/{2}", ResourceLoaderSingleton.Instance.PlatformDir, ResourceLoaderSingleton.Instance.Version, bundlePath); ResourceLoaderSingleton.Instance.StartCoroutine(InitCo(fullBundlePath, mode)); }
protected override void Init(string url, params object[] args) { base.Init(url, args); _loaderMode = (LoaderMode)args[0]; var resMgr = AppFacade.Instance.GetManager <KResourceManager>(); if (resMgr != null) { resMgr.StartCoroutine(CoLoad(url)); } }
public static AssetFileLoader Load(string path, AssetFileBridgeDelegate assetFileLoadedCallback = null, LoaderMode loaderMode = LoaderMode.Async) { // 添加扩展名 path = path + AppEngine.GetConfig(KEngineDefaultConfigs.AssetBundleExt); LoaderDelgate realcallback = null; if (assetFileLoadedCallback != null) { realcallback = (isOk, obj) => assetFileLoadedCallback(isOk, obj as Object); } return AutoNew<AssetFileLoader>(path, realcallback, false, loaderMode); }
/// <summary> /// AssetBundle读取原字节目录 /// </summary> //private KResourceInAppPathType _inAppPathType; public static AssetBundleLoader Load(string url, CAssetBundleLoaderDelegate callback = null, LoaderMode loaderMode = LoaderMode.Async) { LoaderDelgate newCallback = null; if (callback != null) { newCallback = (isOk, obj) => callback(isOk, obj as AssetBundle); } var newLoader = AutoNew <AssetBundleLoader>(url, newCallback, false, loaderMode); return(newLoader); }
protected override void Init(string url, params object[] args) { base.Init(url, args); LoaderMode mode = (LoaderMode)args[0]; //transform url to bundlename string bundlePath = ResourceLoaderSingleton.Instance.GetBundlePathByPath(url); if (bundlePath == null) { OnError(); return; } ResourceLoaderSingleton.Instance.StartCoroutine(LoadAssetBundle(bundlePath, mode)); }
public static SceneLoader Load(string url, System.Action <bool> callback = null, LoaderMode mode = LoaderMode.Async) { UnloadPreScene(); LoaderDelgate newCallback = null; if (callback != null) { newCallback = (isOk, obj) => callback(isOk); } var loader = AutoNew <SceneLoader>(url, newCallback, true, mode); preSceneLoader = loader; return(preSceneLoader); }
IEnumerator InitCo(string url, LoaderMode mode) { Object resObj = null; if (!ResourceLoaderSingleton.Instance.RunBundle && Application.isEditor) { #if UNITY_EDITOR resObj = AssetDatabase.LoadAssetAtPath(ResourceLoaderSingleton.Instance.EditorAssetsPath + url, typeof(Object)); #endif if (resObj == null) { Debug.Log(string.Format("url[{0}] cant find in ResourcesAssets", url)); } } else { //if not in editor, read from Rsources or AssetBundle if (!ResourceLoaderSingleton.Instance.RunBundle) { //remove extension url = url.Substring(0, url.Length - Path.GetExtension(url).Length); //read from resources resObj = Resources.Load(url); if (resObj == null) { Debug.Log(string.Format("url[ {0}] cant find in Resources")); } } else { //load from bundle var loader = AssetBundleLoader.Load(url, null, mode); while (!loader.IsComplete) { yield return(null); } AssetBundle bundle = loader.ResultObj as AssetBundle; resObj = bundle.LoadAsset(url); } } if (resObj == null) { Debug.Log(string.Format("AssetPath [{0}] is NULL or cannot load", url)); } OnFinish(resObj); }
/// <summary> /// AssetBundle读取原字节目录 /// </summary> //private KResourceInAppPathType _inAppPathType; public static AssetBundleLoader Load(string url, CAssetBundleLoaderDelegate callback = null, LoaderMode loaderMode = LoaderMode.Async) { #if UNITY_5 || UNITY_2017_1_OR_NEWER url = url.ToLower(); #endif LoaderDelgate newCallback = null; if (callback != null) { newCallback = (isOk, obj) => callback(isOk, obj as AssetBundle); } var newLoader = AutoNew <AssetBundleLoader>(url, newCallback, false, loaderMode); return(newLoader); }
void _loader_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (e.Cancelled) { if (_mainFormClosing) { this._loader = null; this.Close(); return; } else { Utils.WarningMessage("Операция прервана пользователем!"); } } else if (e.Error != null) { MessageBox.Show(e.Error.Message); } else { if (_mode == LoaderMode.DownloadProgram || _mode == LoaderMode.DownloadProgramAndConfiguration) { _progBuf = _loader.ProgramBinBuffer; lProgram.Text = "Не сохранён"; lProgram.ForeColor = Color.SteelBlue; } if (_mode == LoaderMode.DownloadConfiguration || _mode == LoaderMode.DownloadProgramAndConfiguration) { _confBuf = _loader.ConfigurationBinBuffer; lConfig.Text = "Не сохранён"; lConfig.ForeColor = Color.SteelBlue; } } _loader.ProgressChanged -= new ProgressChangedEventHandler(_loader_ProgressChanged); _loader.RunWorkerCompleted -= new RunWorkerCompletedEventHandler(_loader_RunWorkerCompleted); _mode = LoaderMode.None; GlobProcProgressDefault(); UpdateControlStatus(); }
protected override void Init(string url, params object[] args) { #if UNITY_5 PreLoadManifest(); #endif base.Init(url); _loaderMode = (LoaderMode)args[0]; if (NewAssetBundleLoaderEvent != null) { NewAssetBundleLoaderEvent(url); } RelativeResourceUrl = url; KResourceManager.LogRequest("AssetBundle", RelativeResourceUrl); var resMgr = AppFacade.Instance.GetManager <KResourceManager>(); if (resMgr != null) { resMgr.StartCoroutine(LoadAssetBundle(url)); } }
/// <summary> /// 加载ab /// </summary> /// <param name="url">资源路径</param> /// <param name="callback">加载完成的回调</param> /// <param name="loaderMode">Async异步,sync同步</param> /// <returns></returns> public static AssetBundleLoader Load(string url, CAssetBundleLoaderDelegate callback = null, LoaderMode loaderMode = LoaderMode.Async) { if (!KResourceModule.IsEditorLoadAsset && !url.EndsWith(AppConfig.AssetBundleExt)) { url = url + AppConfig.AssetBundleExt; } #if UNITY_5 || UNITY_2017_1_OR_NEWER url = url.ToLower(); #endif LoaderDelgate newCallback = null; if (callback != null) { newCallback = (isOk, obj) => callback(isOk, obj as AssetBundle); } var newLoader = AutoNew <AssetBundleLoader>(url, newCallback, false, loaderMode); return(newLoader); }
protected override void Init(string url, params object[] args) { #if UNITY_5 || UNITY_2017_1_OR_NEWER PreLoadManifest(); #endif base.Init(url); _loaderMode = (LoaderMode)args[0]; if (NewAssetBundleLoaderEvent != null) { NewAssetBundleLoaderEvent(url); } RelativeResourceUrl = url; KResourceModule.LogRequest("AssetBundle", RelativeResourceUrl); KResourceModule.Instance.StartCoroutine(LoadAssetBundle(url)); }
private IEnumerator LoadAssetBundle(string bundlePath, LoaderMode mode) { //Load bytes via HotBytesLoader var bytesLoader = HotBytesLoader.Load(bundlePath, mode); while (!bytesLoader.IsComplete) { yield return(null); } byte[] btsData = bytesLoader.Bytes; //Parse bytes, get assetbundle Object assetBundleObj = null; if (mode == LoaderMode.Sync) { assetBundleObj = AssetBundle.LoadFromMemory(btsData); } if (assetBundleObj != null) { OnFinish(assetBundleObj); } }
public static HotBytesLoader Load(string path, LoaderMode loaderMode) { var newLoader = AutoNew <HotBytesLoader>(path, null, false, loaderMode); return(newLoader); }
public static HotBytesLoader Load(string path, LoaderMode loaderMode) { var newLoader = AutoNew<HotBytesLoader>(path, null, false, loaderMode); return newLoader; }
private void StartLoader() { if (_mode == LoaderMode.DownloadProgramAndConfiguration) { if (cBUseProgram.Checked && cBUseConfig.Checked) { _mode = LoaderMode.DownloadProgramAndConfiguration; } else { if (cBUseProgram.Checked) { _mode = LoaderMode.DownloadProgram; } else { _mode = LoaderMode.DownloadConfiguration; } } } else //_mode = LoaderMode.UploadProgramAndConfiguration { bool b1 = cBUseProgram.Checked && _progBuf != null; bool b2 = cBUseConfig.Checked && _confBuf != null; if (b1 && b2) { _mode = LoaderMode.UploadProgramAndConfiguration; _loader.ProgramBinBuffer = _progBuf; _loader.ConfigurationBinBuffer = _confBuf; } else { if (b1) { _loader.ProgramBinBuffer = _progBuf; _mode = LoaderMode.UploadProgram; } else { _loader.ConfigurationBinBuffer = _confBuf; _mode = LoaderMode.UploadConfiguration; } } } mmiSaveProgramAs.Enabled = false; mmiSaveConfigurationAs.Enabled = false; mmiUpload.Enabled = btnUpload.Enabled = false; mmiDownload.Enabled = btnDownload.Enabled = false; mmiClearBuffer.Enabled = false; cBPortNumber.Enabled = false; byte[] req = null; if (_currentPort != null) { try { _currentPort.Open(); req = _currentPort.SendRequest(new byte[] { 0x00, 0xA0 }, 2); } finally { _currentPort.Close(); } } if (req != null) { _loader.ProgressChanged += new ProgressChangedEventHandler(_loader_ProgressChanged); _loader.RunWorkerCompleted += new RunWorkerCompletedEventHandler(_loader_RunWorkerCompleted); _loader.Start(_currentPort, _mode); } else { _searcher.RunWorkerAsync(cBPortNumber.SelectedItem.ToString()); } }
private void btnDownload_Click(object sender, EventArgs e) { _loader = new Downloader(); _mode = LoaderMode.DownloadProgramAndConfiguration; StartLoader(); }
private IEnumerator _LoadCoroutine(string path, LoaderMode loaderMode, string package, LoadSceneMode loadSceneMode) { string scenePath = ResourceModuleConfig.GameResourcesDir + "/" + path; object getAsset = null; if (ResManager.IsEdiotrMode && Application.isEditor) { #if UNITY_EDITOR var allScenes = UnityEditor.EditorBuildSettings.scenes; UnityEditor.EditorBuildSettingsScene buildScene = null; foreach (var scene in allScenes) { if (scene.path == scenePath) { buildScene = scene; break; } } if (buildScene == null || !buildScene.enabled) { Debug.LogError("EditorMode must add scene to build settings and active:" + path); OnFinish(null); yield break; } ////编辑器状态下模拟异步加载延迟等待指定秒数 //if (loaderMode == LoaderMode.Async) //{ // yield return new WaitForSecondsRealtime(ResManager.EditorModeLoadDelay); //} #else Debug.LogErrorFormat("`IsEditorLoadAsset` is Unity Editor only"); #endif } else { DateTime beginTime = DateTime.Now; string bundlePath = string.IsNullOrEmpty(package) ? path : package; _bundleLoader = AssetBundleLoader.Load(bundlePath + ResourceModuleConfig.AssetBundleExt, null, loaderMode); while (!_bundleLoader.IsCompleted) { if (IsReadyDisposed) // 中途释放 { _bundleLoader.Release(); OnFinish(null); yield break; } this.Progress = _bundleLoader.Progress / 2f; yield return(null); } if (!_bundleLoader.IsSuccess || !_bundleLoader.Bundle.isStreamedSceneAssetBundle) { Debug.LogErrorFormat("[AssetFileLoader]Load BundleLoader Failed(Error) when Finished: {0}", path); _bundleLoader.Release(); OnFinish(null); yield break; } ResManager.LogLoadTime("AssetFileBridge", loaderMode, path, beginTime); } this.Progress = 0.5f; if (loaderMode == LoaderMode.Async) { var asyncOp = SceneManager.LoadSceneAsync(scenePath, loadSceneMode); while (!asyncOp.isDone) { this.Progress = 0.5f + asyncOp.progress / 2f; yield return(null); } } else { SceneManager.LoadScene(scenePath, loadSceneMode); } this.Progress = 1f; getAsset = true; OnFinish(getAsset); //加载完立即释放Loader ReleaseImmediate(); }
/// <summary> /// AssetBundle读取原字节目录 /// </summary> //private KResourceInAppPathType _inAppPathType; public static AssetBundleLoader Load(string url, CAssetBundleLoaderDelegate callback = null, LoaderMode loaderMode = LoaderMode.Async) { LoaderDelgate newCallback = null; if (callback != null) { newCallback = (isOk, obj) => callback(isOk, obj as AssetBundle); } var newLoader = AutoNew<AssetBundleLoader>(url, newCallback, false, loaderMode); return newLoader; }
public static StaticAssetLoader Load(string url, AssetFileLoader.AssetFileBridgeDelegate callback = null, LoaderMode loaderMode = LoaderMode.Async) { LoaderDelgate newCallback = null; if (callback != null) { newCallback = (isOk, obj) => callback(isOk, obj as UnityEngine.Object); } return(AutoNew <StaticAssetLoader>(url, newCallback, false, loaderMode)); }
public static AssetFileLoader Load(string path, AssetFileBridgeDelegate assetFileLoadedCallback = null, LoaderMode loaderMode = LoaderMode.Async) { // 添加扩展名 if (!IsEditorLoadAsset) { path = path + EngineConfig.instance.ABExtName; } LoaderDelgate realcallback = null; if (assetFileLoadedCallback != null) { realcallback = (isOk, obj) => assetFileLoadedCallback(isOk, obj as Object); } return(AutoNew <AssetFileLoader>(path, realcallback, false, loaderMode)); }
public static AssetFileLoader Load(string path, AssetFileBridgeDelegate assetFileLoadedCallback = null, LoaderMode loaderMode = LoaderMode.Async) { // 添加扩展名 if (!IsEditorLoadAsset) { path = path + AppEngine.GetConfig(KEngineDefaultConfigs.AssetBundleExt); } LoaderDelgate realcallback = null; if (assetFileLoadedCallback != null) { realcallback = (isOk, obj) => assetFileLoadedCallback(isOk, obj as Object); } return(AutoNew <AssetFileLoader>(path, realcallback, false, loaderMode)); }
public static T AutoNew <T>(string url, LoaderDelegate callback, bool forceCreateNew = false, LoaderMode mode = LoaderMode.Sync) where T : AbstractResourceLoader, new() { if (callback != null) { mLoaderCallback = callback; } T loader = new T(); loader.Init(url, mode); return(loader); }
public static SceneResolveLoader Load(string sceneName, string package = null, LoadSceneMode loadSceneMode = LoadSceneMode.Single, LoaderDelgate onFinish = null, LoaderMode loaderMode = LoaderMode.Async) { return(AutoNew <SceneResolveLoader>(sceneName, onFinish, false, loaderMode, package, loadSceneMode)); }
protected override void Init(string url, params object[] args) { #if UNITY_5 PreLoadManifest(); #endif base.Init(url); _loaderMode = (LoaderMode)args[0]; if (NewAssetBundleLoaderEvent != null) NewAssetBundleLoaderEvent(url); RelativeResourceUrl = url; KResourceModule.LogRequest("AssetBundle", RelativeResourceUrl); KResourceModule.Instance.StartCoroutine(LoadAssetBundle(url)); }
private IEnumerator _Init(string path, LoaderMode loaderMode) { IsLoadAssetBundle = AppEngine.GetConfig("KEngine", "IsLoadAssetBundle").ToInt32() != 0; Object getAsset = null; if (IsEditorLoadAsset) { #if UNITY_EDITOR if (path.EndsWith(".unity")) { // scene getAsset = KResourceModule.Instance; Log.LogWarning("Load scene from Build Settings: {0}", path); } else { getAsset = UnityEditor.AssetDatabase.LoadAssetAtPath("Assets/" + KEngineDef.ResourcesBuildDir + "/" + path, typeof(UnityEngine.Object)); if (getAsset == null) { Log.Error("Asset is NULL(from {0} Folder): {1}", KEngineDef.ResourcesBuildDir, path); } } #else Log.Error("`IsEditorLoadAsset` is Unity Editor only"); #endif OnFinish(getAsset); } else if (!IsLoadAssetBundle) { string extension = Path.GetExtension(path); path = path.Substring(0, path.Length - extension.Length); // remove extensions getAsset = Resources.Load <Object>(path); if (getAsset == null) { Log.Error("Asset is NULL(from Resources Folder): {0}", path); } OnFinish(getAsset); } else { _bundleLoader = AssetBundleLoader.Load(path, null, loaderMode); while (!_bundleLoader.IsCompleted) { if (IsReadyDisposed) // 中途释放 { _bundleLoader.Release(); OnFinish(null); yield break; } yield return(null); } if (!_bundleLoader.IsSuccess) { Log.Error("[AssetFileLoader]Load BundleLoader Failed(Error) when Finished: {0}", path); _bundleLoader.Release(); OnFinish(null); yield break; } var assetBundle = _bundleLoader.Bundle; DateTime beginTime = DateTime.Now; #if UNITY_5 || UNITY_2017_1_OR_NEWER // Unity 5 下,不能用mainAsset, 要取对象名 var abAssetName = Path.GetFileNameWithoutExtension(Url).ToLower(); if (!assetBundle.isStreamedSceneAssetBundle) { if (loaderMode == LoaderMode.Sync) { getAsset = assetBundle.LoadAsset(abAssetName); Debuger.Assert(getAsset); _bundleLoader.PushLoadedAsset(getAsset); } else { var request = assetBundle.LoadAssetAsync(abAssetName); while (!request.isDone) { yield return(null); } Debuger.Assert(getAsset = request.asset); _bundleLoader.PushLoadedAsset(getAsset); } } else { // if it's a scene in asset bundle, did nothing // but set a fault Object the result getAsset = KResourceModule.Instance; } #else // 经过AddWatch调试,.mainAsset这个getter第一次执行时特别久,要做序列化 //AssetBundleRequest request = assetBundle.LoadAsync("", typeof(Object));// mainAsset //while (!request.isDone) //{ // yield return null; //} try { Debuger.Assert(getAsset = assetBundle.mainAsset); } catch { Log.Error("[OnAssetBundleLoaded:mainAsset]{0}", path); } #endif KResourceModule.LogLoadTime("AssetFileBridge", path, beginTime); if (getAsset == null) { Log.Error("Asset is NULL: {0}", path); } } if (Application.isEditor) { if (getAsset != null) { KResoourceLoadedAssetDebugger.Create(getAsset.GetType().Name, Url, getAsset as Object); } // 编辑器环境下,如果遇到GameObject,对Shader进行Fix if (getAsset is GameObject) { var go = getAsset as GameObject; foreach (var r in go.GetComponentsInChildren <Renderer>(true)) { RefreshMaterialsShaders(r); } } } if (getAsset != null) { // 更名~ 注明来源asset bundle 带有类型 getAsset.name = String.Format("{0}~{1}", getAsset, Url); } OnFinish(getAsset); }
private IEnumerator _Init(string path, LoaderMode loaderMode) { IsLoadAssetBundle = AppEngine.GetConfig("KEngine", "IsLoadAssetBundle").ToInt32() != 0; Object getAsset = null; if (!IsLoadAssetBundle) { string extension = Path.GetExtension(path); path = path.Substring(0, path.Length - extension.Length); // remove extensions getAsset = Resources.Load<Object>(path); if (getAsset == null) { Log.Error("Asset is NULL(from Resources Folder): {0}", path); } OnFinish(getAsset); } else { _bundleLoader = AssetBundleLoader.Load(path, null, loaderMode); while (!_bundleLoader.IsCompleted) { if (IsReadyDisposed) // 中途释放 { _bundleLoader.Release(); OnFinish(null); yield break; } yield return null; } if (!_bundleLoader.IsSuccess) { Log.Error("[AssetFileLoader]Load BundleLoader Failed(Error) when Finished: {0}", path); _bundleLoader.Release(); OnFinish(null); yield break; } var assetBundle = _bundleLoader.Bundle; DateTime beginTime = DateTime.Now; #if UNITY_5 // Unity 5 下,不能用mainAsset, 要取对象名 var abAssetName = Path.GetFileNameWithoutExtension(Url).ToLower(); if (!assetBundle.isStreamedSceneAssetBundle) { if (loaderMode == LoaderMode.Sync) { getAsset = assetBundle.LoadAsset(abAssetName); Debuger.Assert(getAsset); } else { var request = assetBundle.LoadAssetAsync(abAssetName); while (!request.isDone) { yield return null; } Debuger.Assert(getAsset = request.asset); } } else { // if it's a scene in asset bundle, did nothing // but set a fault Object the result getAsset = KResourceModule.Instance; } #else // 经过AddWatch调试,.mainAsset这个getter第一次执行时特别久,要做序列化 //AssetBundleRequest request = assetBundle.LoadAsync("", typeof(Object));// mainAsset //while (!request.isDone) //{ // yield return null; //} try { Debuger.Assert(getAsset = assetBundle.mainAsset); } catch { Log.Error("[OnAssetBundleLoaded:mainAsset]{0}", path); } #endif KResourceModule.LogLoadTime("AssetFileBridge", path, beginTime); if (getAsset == null) { Log.Error("Asset is NULL: {0}", path); } } if (Application.isEditor) { if (getAsset != null) KResoourceLoadedAssetDebugger.Create(getAsset.GetType().Name, Url, getAsset as Object); // 编辑器环境下,如果遇到GameObject,对Shader进行Fix if (getAsset is GameObject) { var go = getAsset as GameObject; foreach (var r in go.GetComponentsInChildren<Renderer>(true)) { RefreshMaterialsShaders(r); } } } if (getAsset != null) { // 更名~ 注明来源asset bundle 带有类型 getAsset.name = String.Format("{0}~{1}", getAsset, Url); } OnFinish(getAsset); }