public GameResourceData(GameBundleInfo bundleInfo, GameResInfo resInfo) { this.id = bundleInfo.id; this.type = bundleInfo.type; this.name = bundleInfo.name; this.assetbundleName = bundleInfo.assetbundle; this.resPath = resInfo.resPath; }
static int IntToEnum(IntPtr L) { int arg0 = (int)LuaDLL.lua_tonumber(L, 1); GameResType o = (GameResType)arg0; ToLua.Push(L, o); return(1); }
public static AssetBundleCollector CollectAssetBundlesForFolder(GameResType type, string path, string pattern, string assetbundlename, SearchOption searchOption = SearchOption.AllDirectories) { AssetCollector collector = AssetCollector.CreateAndCollect(path, pattern, type, searchOption); List <AssetBundleBuild> buildList = new List <AssetBundleBuild>(); AssetBundleCollector assetbundleCollector = new AssetBundleCollector(); assetbundleCollector.AddBuilder(assetbundlename, collector); return(assetbundleCollector); }
public static void ClearGameRes(GameResType type) { SortedDictionary <string, GameResourceData> dict; if (GameResGenerator.GameResourceDict.TryGetValue(type, out dict)) { dict.Clear(); } }
// 资源清单检查 bool CheckRes(GameResType type, string name, out GameBundleInfo data) { data = GameTable.GetGameBundleRes(type, name); if (data == null) { TTLoger.LogError("资源清单未找到资源 : " + name + ",请检查resBundle"); return(false); } return(true); }
// 同步load方法 public override UnityEngine.Object Load(GameResType type, string name, Type resType = null) { GameResInfo data; if (CheckRes(type, name, out data)) { return(LoadAssetAtPath(data.resPath, resType)); } return(null); }
public static void UpdateGameRes(GameResType type, string name, string abName, string resPath = "") { GameResourceData data = new GameResourceData(); data.type = type; data.name = name; data.id = int.Parse(type.ToString("d")) * 10000; data.resPath = resPath; data.assetbundleName = abName; UpdateGameResWorker(data); }
public override UnityEngine.Object Load(GameResType type, string name, Type resType = null) { GameBundleInfo data; // 检查资源清单是否有该资源 if (CheckRes(type, name, out data)) { // 加载资源 return(LoadAB(data.assetbundle).Load(data.name, resType)); } return(null); }
public static AssetBundleCollector CollectAssetbundlesForEachFile(GameResType type, string path, string pattern, string format = "{0}", SearchOption searchOption = SearchOption.AllDirectories) { AssetCollector collector = AssetCollector.CreateAndCollect(path, pattern, type, searchOption); AssetBundleCollector assetbundleCollector = new AssetBundleCollector(); if (collector == null) { return(assetbundleCollector); } assetbundleCollector.AddBuilderList(format, collector); return(assetbundleCollector); }
public static AssetCollector CreateAndCollect(string path, string pattern, GameResType type, SearchOption searchOption) { string systemFullPath = PathUtil.GetFullPath(path); AssetCollector collector = new AssetCollector(); if (!Directory.Exists(systemFullPath)) { return(collector); } collector.CollectFolder(systemFullPath, pattern, type, searchOption); return(collector); }
// 检查资源表中是否有某个资源 public static bool HasGameRes(GameResType type, string name) { if (AppConst.DevelopMode) { GameResInfo info = GameTable.GetGameRes(type, name); return(info != null); } else { GameBundleInfo info = GameTable.GetGameBundleRes(type, name); return(info != null); } }
public void CollectFolder(string systemFullPath, string pattern, GameResType type, SearchOption searchOption) { if (!Directory.Exists(systemFullPath)) { return; } string[] fileList = Directory.GetFiles(systemFullPath, "*.*", searchOption); List <string> files = PathUtil.FilterPattern(fileList, pattern); for (int i = 0; i < files.Count; ++i) { string path = files[i]; path = PathUtil.SystemPath2AssetPath(path); Add(path, type); } }
public void Collect(BuildOption option, GameResType resType, string path, string pattern, string assetbundleName) { switch (option) { case BuildOption.EachFile: CollectEachFile(resType, path, pattern, assetbundleName); break; case BuildOption.EachFolder: CollectEachSubFolder(resType, path, pattern, assetbundleName); break; case BuildOption.WholeFolder: CollectFolder(resType, path, pattern, assetbundleName); break; } }
public static AssetBundleCollector CollectAssetbundlesForEachSubFolder(GameResType type, string path, string pattern, string format = "{0}", SearchOption searchOption = SearchOption.AllDirectories) { string fullpath = PathUtil.GetFullPath(path); AssetBundleCollector assetBundleCollector = new AssetBundleCollector(); if (!Directory.Exists(fullpath)) { return(assetBundleCollector); } string[] dirList = Directory.GetDirectories(fullpath); List <AssetBundleBuild> bulldList = new List <AssetBundleBuild>(); foreach (string dir in dirList) { string fullPath = dir.Replace("\\", "/"); string[] splitName = PathUtil.splitePath(fullPath); string name = string.Format(format, splitName); AssetBundleCollector abc = CollectAssetBundlesForFolder(type, PathUtil.GetRelativePathToDataPath(fullPath), pattern, name, searchOption); assetBundleCollector.Mearge(abc); } return(assetBundleCollector); }
public void CollectEachSubFolder(GameResType type, string path, string pattern, string format = "{0}", SearchOption searchOption = SearchOption.AllDirectories) { AssetBundleCollector abcollector = CollectAssetbundlesForEachSubFolder(type, path, pattern, format, searchOption); this.Mearge(abcollector); }
// 统一接口,实际直接同步加载并回调 public override void LoadAsync(GameResType type, string name, Action <UnityEngine.Object> callback, Type resType = null) { UnityEngine.Object go = Load(type, name, resType); callback(go); }
public void Add(string assetPath, GameResType type) { buildAssetInfoList.Add(new BuildAssetInfo(assetPath, type)); }
public BuildAssetInfo(string assetPath, GameResType type) { this.resPath = assetPath; this.type = type; }
public Sprite LoadSprite(GameResType type, string spriteName) { return(this.AssetLoader.Load(type, spriteName, typeof(Sprite)) as Sprite); }
public void CollectAppend(AssetBundleCollector mainCollector, BuildOption option, GameResType resType, string path, string pattern, string assetbundleName, bool independent, SearchOption searchOption = SearchOption.AllDirectories) { for (int i = 0; i < mainCollector.buildList.Count; ++i) { AssetBundleBuild bd = mainCollector.buildList[i]; string name = PathUtil.GetFileNameWithoutExtension(bd.assetBundleName); string formatPath = string.Format(path, name); if (independent) { Collect(option, resType, formatPath, pattern, assetbundleName); } else { AssetCollector collector = AssetCollector.CreateAndCollect(formatPath, pattern, resType, searchOption); List <string> assetList = new List <string>(bd.assetNames); List <string> assetList2 = new List <string>(collector.ToAssetStringList()); assetList.AddRange(assetList2); bd.assetNames = assetList.ToArray(); mainCollector.buildList[i] = bd; collector.UpdateGameTable(bd.assetBundleName); } } }
//TODO 这个方法有些复杂,说明需要简化逻辑 public override void LoadAsync(GameResType type, string name, Action <UnityEngine.Object> callback, Type resType = null) { GameBundleInfo data; // 检查资源 if (CheckRes(type, name, out data)) { AssetBundleRef abRef; /* * 测试发现,异步从ab包加载资源时,即使该assetbundle已被unload(true),仍可以载到奇怪的资源,且能被添加到场景上 * 而loader被释放可能引起assetbundle被unload */ Action <UnityEngine.Object> checkCallBack = (asset) => //检查异步加载资源结束时,是否该loader已被释放 { if (abrDict == null || loadingDict == null) // 为null视为已释放 { callback(null); // 直接回调null } else { callback(asset); // 正常回调上层 } }; if (abrDict.TryGetValue(data.assetbundle, out abRef)) { abRef.LoadAsync(name, checkCallBack); // 缓存命中 } else { // 缓存未命中,则要去加载ab,先声明ab载完回调 Action <AssetBundleRef> loadABCallback = (assetbundleRef) => { if (assetbundleRef == null) { checkCallBack(null); } else { assetbundleRef.LoadAsync(name, checkCallBack); } }; /* * loadAssetbundle 可以考虑在继承monoLoader的情况下,自己startCoroutine,就不必处理协程结束,而自己已经被销毁的情况 */ AssetLoading <AssetBundleRef> loading; // 如果已经在异步load assetbundle if (loadingDict.TryGetValue(data.assetbundle, out loading)) { //将本次回调添加到load回调就完事了 loading.callback.Add(loadABCallback); return; } // 创建一个loading loading = new AssetLoading <AssetBundleRef>(); loadingDict.Add(data.assetbundle, loading); loading.callback.Add(loadABCallback); // 异步load Assetbundle LoadABAsync(data.assetbundle, (assetbundleRef) => // 本地缓存未命中,向AssetManager异步请求AssetBundle { // 如果loader自身已被释放 if (abrDict == null || loadingDict == null) { loading.FireCallBack(null); // 回调null } // 正常添加到缓存,并回调 loadingDict.Remove(data.assetbundle); loading.FireCallBack(assetbundleRef); }); } } else { // 没找到这资源 callback(null); } }
// 同步加载资源 public abstract UnityEngine.Object Load(GameResType type, string name, Type resType = null);
// 异步加载资源 public abstract void LoadAsync(GameResType type, string name, Action <UnityEngine.Object> callback, Type resType = null);
public void CollectEachFile(GameResType type, string path, string pattern, string assetbundleName, SearchOption searchOption = SearchOption.AllDirectories) { AssetBundleCollector abcollector = CollectAssetbundlesForEachFile(type, path, pattern, assetbundleName, searchOption); this.Mearge(abcollector); }