protected void AddDepends(BundlePkgInfo pkginfo, IBundleRef bundle) { if (!isABMode) { return; } if (bundle != null) { for (int i = 0; i < pkginfo.Depends.Length; ++i) { IBundleRef depbund = ResBundleMgr.mIns.Cache.TryGetValue(pkginfo.Depends[i]); if (depbund != null) { bundle.NeedThis(depbund); } else { this.ThrowBundleMissing(pkginfo.Depends[i]); } } } else { this.ThrowBundleMissing(pkginfo.BundleName); } }
private void _LoadBundle(BundlePkgInfo pkginfo) { if (LoadedRefs.ContainsKey(pkginfo.AbFileName)) { if (FrameWorkConfig.Open_DEBUG) { LogMgr.LogFormat("缓存中存在直接加载 :{0} => {1}", pkginfo.BundleName, pkginfo.AbFileName); } this.RunNextTask(); } else if (!isABMode && this.isRunning()) { this.AutoCreateBundle(); } else if (this.isRunning()) { if (!ResBundleMgr.mIns.Cache.ContainsLoadingBundle(pkginfo.BundleName)) { this._PushTaskAndExcute(pkginfo, this.LoadFullAssetToMemAsync(pkginfo)); ResBundleMgr.mIns.Cache.PushLoadingBundle(pkginfo.BundleName); } else { ResBundleMgr.mIns.Cache.PushLoadingBundle(pkginfo.BundleName, this.AttheSametimeUpdate); } } }
private void StartLoad() { while (this.loaderqueue.Count > 0) { BundlePkgInfo pkginfo = this.loaderqueue.Dequeue(); if (this.isRunning()) { bool isasyncLoading = ResBundleMgr.mIns.Cache.ContainsLoadingBundle(pkginfo.BundleName); if (isasyncLoading) { ResBundleMgr.mIns.Cache.PushLoadingBundle(pkginfo.BundleName, this.YiedAsyncDone); } else { this._LoadBundle(pkginfo); current++; this.InvokeProgressHandler(current, total); } } } if (current == total) { AfterDependDone(); } }
private IBundleRef _LoadBundle(BundlePkgInfo pkginfo) { IBundleRef bundle = this.LoadFullAssetToMem(pkginfo); this.AddDepends(pkginfo, bundle); return(bundle); }
public void LoadFromMemory(Stream depStream) { caches.Clear(); StreamReader sr = new StreamReader(depStream); char[] fileHeadChars = new char[6]; sr.Read(fileHeadChars, 0, fileHeadChars.Length); //读取文件头判断文件类型,ABDT 意思即 Asset-Bundle-Data-Text if (fileHeadChars[0] != 'A' || fileHeadChars[1] != 'B' || fileHeadChars[2] != 'D' || fileHeadChars[3] != 'T') { return; } while (true) { string name = sr.ReadLine(); if (string.IsNullOrEmpty(name)) { break; } string shortFileName = sr.ReadLine(); string hash = sr.ReadLine(); string assetpath = sr.ReadLine(); Convert.ToInt32(sr.ReadLine()); int depsCount = Convert.ToInt32(sr.ReadLine()); string[] deps = new string[depsCount]; if (FrameWorkConfig.Open_DEBUG) { LogMgr.Log("asset :" + assetpath); } for (int i = 0; i < depsCount; i++) { deps[i] = sr.ReadLine(); } BundlePkgInfo pkg = new BundlePkgInfo(hash, name, shortFileName, assetpath, BundlePkgInfo.ChooseType(assetpath), deps); this.caches[shortFileName] = pkg; this.caches[name] = pkg; this.caches[assetpath] = pkg; if (BundleConfig.SAFE_MODE) { #if UNITY_EDITOR this.caches.Add(assetpath.Replace("\\", "/"), pkg); #else this.caches.Add(assetpath, pkg); #endif } } if (FrameWorkConfig.Open_DEBUG) { LogMgr.LogFormat("Bundle Count Is {0}", this.caches.Count); } depStream.Close(); }
private void ReadBinary(BinaryReader sr, Stream fs) { int namesCount = sr.ReadInt32(); string[] names = new string[namesCount]; for (int i = 0; i < namesCount; i++) { names[i] = sr.ReadString(); } while (true) { if (fs.Position == fs.Length) { break; } string name = names[sr.ReadInt32()]; string shortFileName = sr.ReadString(); string hash = sr.ReadString(); string assetpath = sr.ReadString(); sr.ReadInt32();//int typeData = int depsCount = sr.ReadInt32(); string[] deps = new string[depsCount]; //LogMgr.LogError(shortFileName +" > "+assetpath); for (int i = 0; i < depsCount; i++) { deps[i] = names[sr.ReadInt32()]; } BundlePkgInfo pkg = new BundlePkgInfo(hash, name, shortFileName, assetpath, BundlePkgInfo.ChooseType(assetpath), deps); #if UNITY_EDITOR TryAdd(assetpath, pkg); TryAdd(shortFileName, pkg); TryAdd(name, pkg); #else this.caches[shortFileName] = pkg; this.caches[name] = pkg;//hashvalue #endif if (BundleConfig.SAFE_MODE) { #if UNITY_EDITOR this.caches[assetpath.Replace("\\", "/")] = pkg; #endif } } if (FrameWorkConfig.Open_DEBUG) { LogMgr.LogFormat("Bundle Count Is {0}", this.caches.Count); } sr.Close(); }
protected AssetBundleCreateRequest LoadFullAssetToMemAsync(BundlePkgInfo pkginfo) { if (Application.isPlaying && MainLoop.getInstance()) { return(KAssetBundle.LoadFromFileAsync(BundlePathConvert.GetRunningPath(pkginfo.AbFileName)));; } else { return(null); } }
void TryAdd(string key, BundlePkgInfo pkg) { if (caches.ContainsKey(key)) { LogMgr.LogErrorFormat("{0} will replace {1}", pkg.BundleName, caches[key].BundleName); } else { caches[key] = pkg; } }
protected BundlePkgInfo _SeekPkgInfo(string name) { BundlePkgInfo pkginfo = ResBundleMgr.mIns.BundleInformation.SeekInfo(name); if (pkginfo == null) { this.LoadState = BundleLoadState.Error; throw new FrameWorkException(string.Format("Not Found {0}", name), ExceptionType.Higher_Excetpion); } return(pkginfo); }
public virtual void RemoveToPool() { this._BundleMainObject = null; this._BundleRef = null; this.loadingpkg = null; this.LoadResPath = null; this.LoadState = BundleLoadState.Prepared; this.onComplete = null; this.LoaderInsObject = null; this.PreParedGameObject = null; this._AsyncOpation = null; }
private void AttheSametimeUpdate(string bundlename) { if (FrameWorkConfig.Open_DEBUG) { BundlePkgInfo pkg = this._SeekPkgInfo(bundlename); LogMgr.LogFormat(":::::其他地方加载了 :{0} => {1}", pkg.BundleName, pkg.AbFileName); } this.RefreshLoaded(); this.RunNextTask(); }
protected IBundleRef LoadFullAssetToMem(BundlePkgInfo pkginfo) { IBundleRef bundle = null; if (ResBundleMgr.mIns.Cache.Contains(pkginfo)) { bundle = ResBundleMgr.mIns.Cache.TryGetValue(pkginfo); return(bundle); } #if UNITY_IOS || UNITY_IPHONE || UNITY_ANDROID if (GameApplication.isPlaying && MainLoop.getInstance().OpenABMode) { AssetBundle ab = null; using (gstring.Block()) { ab = this.LoadAssetBundle(BundlePathConvert.GetRunningPath(pkginfo.AbFileName)); } if (ab == null) { this.ThrowAssetMissing(this.LoadResPath); } bundle = ResBundleMgr.mIns.Cache.PushAsset(pkginfo, ab); return(bundle); } else #endif { UnityEngine.Object target = AssetDatabaseLoad(pkginfo.EditorPath); if (target == null) { if (BundleConfig.SAFE_MODE) { this.ThrowAssetMissing(pkginfo.BundleName); } else { this.LoadState = BundleLoadState.Error; LogMgr.LogErrorFormat("Asset {0} Missing", pkginfo.BundleName); } } else { #if UNITY_EDITOR bundle = ResBundleMgr.mIns.Cache.PushEditorAsset(pkginfo, target); #endif } return(bundle); } }
protected void _PushTaskAndExcute(BundlePkgInfo Pkginfo, object operation) { Task.PushOperation(Pkginfo, operation); if (FrameWorkConfig.Open_DEBUG) { LogMgr.LogFormat("开始异步任务 :{0} => {1} =>", Pkginfo.BundleName, Pkginfo.AbFileName, Task.asyncType); } WaitTaskCommand cmd = WaitTaskCommand.Create(Task, AsyncLoadFinished); cmd.Excute(); }
private void SetLoadRef(BundlePkgInfo pkginfo) { for (int i = 0; i < pkginfo.Depends.Length; ++i) { BundlePkgInfo pkg = this._SeekPkgInfo(pkginfo.Depends[i]); IBundleRef refBundle = ResBundleMgr.mIns.Cache.TryGetValue(pkg); if (refBundle != null) { LoadedRefs[pkg.AbFileName] = refBundle; } //set child pkg SetLoadRef(pkg); } }
public IBundleRef PushEditorAsset(BundlePkgInfo pkg, UnityEngine.Object ab) { IBundleRef bundle = null; if (!this.Contains(pkg.AbFileName)) { bundle = new EditorRef(ab, pkg.BundleName, pkg.AbFileName, pkg.EditorPath); this[pkg.AbFileName] = bundle; } else { bundle = this[pkg.AbFileName]; } return(bundle); }
/// <summary> /// 添加bundle /// </summary> /// <param name="pkg"></param> /// <param name="ab"></param> /// <returns></returns> public IBundleRef PushAsset(BundlePkgInfo pkg, AssetBundle ab) { IBundleRef bundle = null; if (!this.Contains(pkg.AbFileName)) { bundle = BundleRef.Create(this.TryGetPtr(pkg.AbFileName, ab), pkg.AbFileName, pkg.EditorPath, pkg.BundleName); this[pkg.AbFileName] = bundle; } else { bundle = this[pkg.AbFileName]; } return(bundle); }
private void CreateLoadQueue(BundlePkgInfo pkginfo) { for (int i = 0; i < pkginfo.Depends.Length; ++i) { if (this.isRunning()) { BundlePkgInfo pkg = this._SeekPkgInfo(pkginfo.Depends[i]); this.CreateLoadQueue(pkg); } else { LogMgr.LogFormat("{0} asyncloader 状态不符", this.LoadResPath); } } LoadQueue.Enqueue(pkginfo); }
/// <summary> /// 尝试获取引用的bundle /// </summary> /// <param name="assetname"></param> /// <returns></returns> public IBundleRef TryGetValue(string assetname) { IBundleRef bundle; if (this.RefCaches.TryGetValue(assetname, out bundle)) { return(bundle); } //try again BundlePkgInfo pkg = ResBundleMgr.mIns.BundleInformation.SeekInfo(assetname); if (pkg == null) { return(null); } this.RefCaches.TryGetValue(pkg.AbFileName, out bundle); return(bundle); }
private void _PushDepend(BundlePkgInfo pkginfo) { for (int i = 0; i < pkginfo.Depends.Length; ++i) { if (this.isRunning()) { this._PushDepend(this._SeekPkgInfo(pkginfo.Depends[i])); } else if (BundleConfig.Bundle_Log) { LogMgr.LogFormat("{0} loader 状态不符", this.LoadResPath); } else { break; } } this.loaderqueue.Enqueue(pkginfo); }
public void LogDebugInfo() { LogMgr.LogFormat("<color=#0000ffff>----------Bundle In Pool Cnt is {0}-------------</color>", this.CacheCnt); var keys = new List <string>(this.RefCaches.Keys); for (int i = 0; i < keys.Count; ++i) { string key = keys[i]; IBundleRef bundle = this.RefCaches[key]; string bundlename = bundle.name; BundlePkgInfo info = ResBundleMgr.mIns.BundleInformation.SeekInfo(bundle.name); if (info != null) { bundlename = info.BundleName; } LogMgr.LogFormat("<color=#00aa00ff>Root Bundle is {0}:{1} ,InsRefCount is {2} ,DependedCnt is {3} ,SelfRefCount:{4}</color>", bundle.name, bundlename, bundle.InstanceRefCount, bundle.DependCount, bundle.SelfRefCount); bundle.LogDepends(); } LogMgr.Log("<color=#0000ffff>----------Bundle In Pool Log End-------------</color>"); }
/// <summary> /// 搜查并删除 /// </summary> /// <param name="name"></param> /// <param name="force"></param> public static void SeekUnLoad(string name, bool force = false) { if (mIns != null) { BundlePkgInfo info = mIns.Info.SeekInfo(name); if (info != null) { IBundleRef bundle = mIns.Cache.TryGetValue(info); if (bundle != null) { bundle.UnLoad(force); } else { LogMgr.LogErrorFormat("The Bundle which your seek isnt in the Pool Or Loaded Yield :{0}", name); } } else { LogMgr.LogErrorFormat("Not Found your Seek Info :{0}", name); } } }
/// <summary> /// 尝试获取引用的bundle /// </summary> /// <param name="assetname"></param> /// <returns></returns> public IBundleRef TryGetValue(BundlePkgInfo pkg) { return(this.TryGetValue(pkg.AbFileName)); }
public void PushOperation(BundlePkgInfo Pkginfo, object o) { this._currentPkg = Pkginfo; this.currentAsync = o; this.asyncType = this.Swithtp(this.currentAsync); }
private void AutoCreateBundle() { if (Task.asyncType == AsyncBundleTp.AB_LOAD) { AssetBundleRequest abReq = Task.currentAsync as AssetBundleRequest; this.LoadMainAsyncRequest(abReq); } else if (Task.asyncType == AsyncBundleTp.AB_CREATE) { AssetBundleCreateRequest abCreateReq = Task.currentAsync as AssetBundleCreateRequest; if (abCreateReq.assetBundle == null) { ThrowAssetMissing(this.LoadResPath); } IBundleRef bundle = ResBundleMgr.mIns.Cache.PushAsset(Task.CurrentLoadInfo, abCreateReq.assetBundle); BundlePkgInfo pkg = this._SeekPkgInfo(abCreateReq.assetBundle.name); this.AddDepends(pkg, bundle); ResBundleMgr.mIns.Cache.RemoveLoading(pkg.BundleName); if (FrameWorkConfig.Open_DEBUG) { LogMgr.LogFormat("成功加载了 :{0} => {1} => {2} => RefCnt :{3} =>SelfRefCnt:{4}", this.UID, pkg.BundleName, pkg.AbFileName, bundle.InstanceRefCount, bundle.SelfRefCount); } this.RefreshLoaded(); } else if (Task.asyncType == AsyncBundleTp.SCENE_LOAD) { this.LoadSceneAssetFinish(); } else { if (isABMode) { if (BundleConfig.SAFE_MODE) { throw new FrameWorkResNotMatchException(string.Format("不被支持的异步类型 {0}", Task.currentAsync)); } else { LogMgr.LogError("不被支持的异步类型 "); this.LoadState = BundleLoadState.Error; } } else { this._BundleRef = LoadFullAssetToMem(this.loadingpkg); this._BundleMainObject = this._BundleRef.MainObject; this.AddDepends(this.loadingpkg, this._BundleRef); if (isSceneLoad) { SceneOperation asyncOp = GameSceneCtr.LoadSceneAsync(Path.GetFileNameWithoutExtension(this.LoadResPath)); asyncOp.DisableScene(); this._AsyncOpation = asyncOp; this._PushTaskAndExcute(this.loadingpkg, asyncOp); } else { this._FinishAndRelease(); } } } }
/// <summary> /// 是否存在这个bundle /// </summary> /// <param name="abname"></param> /// <returns></returns> public bool Contains(BundlePkgInfo pkg) { return(this.RefCaches.ContainsKey(pkg.AbFileName)); }