public CustomYieldInstruction Initialize(ILoadOperator loadOperator, int maxDownloadCount, int maxLoadCount, Action onSuccess, Action <Exception> onFail) { Log.Debug("[ilib-abloader] Initialize {0}.", loadOperator); bool complete = false; var wait = new WaitUntil(() => complete); //起動済みの際はリセットを先にする必要がある if (State != ABLoaderState.None) { complete = true; Log.Error("[ilib-abloader] already initialized. use ABLoader.Stop()"); onFail?.Invoke(new InvalidOperationException("already initialized. use ABLoader.Stop()")); return(wait); } State = ABLoaderState.Initialize; Cache.Init(loadOperator); m_LoadOperator = loadOperator; m_Downloader = new RequestHander <DownloadRequest>(maxDownloadCount); m_Loader = new RequestHander <LoadOperation>(maxLoadCount); #if UNITY_EDITOR if (ABLoader.UseEditorAsset) { Log.Debug("[ilib-abloader] use editor asset mode."); State = ABLoaderState.Active; onSuccess?.Invoke(); complete = true; return(wait); } #endif var initializer = m_LoadOperator.Init(); initializer.AddCompleteEvent((data, ex) => { complete = true; if (ex != null) { State = ABLoaderState.Error; onFail(ex); } else if (data != null) { State = ABLoaderState.Active; m_BundleData = data; onSuccess?.Invoke(); } }); initializer.DoStart(); return(wait); }
public CustomYieldInstruction Stop(Action onComplete) { if (State == ABLoaderState.Abort) { Log.Warning("[ilib-abloader] current aborting."); throw new InvalidOperationException("current aborting."); } Log.Debug("[ilib-abloader] start aborting."); bool complete = false; State = ABLoaderState.Abort; //ダウンロードの中断は即実行される m_Downloader.Abort(() => { m_Loader.Abort(() => { Log.Debug("[ilib-abloader] complete abort."); lock (m_UnloadList) { m_UnloadList.Clear(); } foreach (var bundleRef in m_LoadedBundles.Values) { bundleRef.Dispose(); } m_LoadedBundles.Clear(); foreach (var container in m_Container.Values.ToArray()) { container.Dispose(); } m_Container.Clear(); Log.Debug("[ilib-abloader] unload all assetbundle."); State = ABLoaderState.Stop; complete = true; onComplete?.Invoke(); }); }); return(new WaitUntil(() => complete)); }