public SceneLoadTask(string assetName, bool _isKeepInMemory) { ResGroupCfg cfg = GameCfgMgr.Instance.GetGroupInfo(assetName); mIsGrop = cfg != null; loadType = mIsGrop ? new LoadGroup(cfg) : new AutoLoadAsset(assetName, _isKeepInMemory) as ISceneLoad; }
/// <summary> /// 删除所有某个资源组 /// </summary> /// <param name="b"></param> internal static void HandleGroupsDelete(List <string> groupNames) { List <string> delAssets = new List <string>(); foreach (string groupName in groupNames) { ResGroupCfg load = null; foreach (ResGroupCfg da in resInfo.groups) { if (da.groupName == groupName) { load = da; break; } } if (load != null) { resInfo.groups.Remove(load); delAssets.AddRange(load.keys); } } foreach (string assetName in delAssets) { if (!resInfo.groups.Exists(a => a.keys.Contains(assetName))) { resInfo.resources.Remove(resInfo.GetResInfo(assetName)); } } Update(); }
/// <summary> /// 删除所有某个资源组 /// </summary> /// <param name="b"></param> internal static void HandleGroupsDelete(List <AssetMode.GroupInfo> b) { List <string> delAssets = new List <string>(); foreach (AssetMode.GroupInfo groupName in b) { ResGroupCfg load = null; foreach (ResGroupCfg da in resInfo.groups) { if (da.sceneName == groupName.Name) { load = da; break; } } if (load != null) { resInfo.groups.Remove(load); delAssets.AddRange(load.keys); } } foreach (string assetName in delAssets) { resInfo.resources.Remove(resInfo.GetResInfo(assetName)); } Update(); RefreshGroupList(); }
/// <summary> /// 在某个资源组里面移出某个资源 /// </summary> /// <param name="assetName">资源名称</param> /// <param name="name">资源组名称</param> public static void RemoveAsset(string assetName, string name) { ResGroupCfg data = resInfo.GetGroupInfo(name); if (data != null) { if (data.keys.Contains(assetName)) { data.keys.Remove(assetName); } } foreach (ResGroupCfg sld in resInfo.groups) { if (sld.keys.Contains(assetName)) { return; } } if (resInfo.resources.Exists(a => a.name == assetName)) { ResInfoData da = resInfo.GetResInfo(assetName); if (da != null) { resInfo.resources.Remove(da); } } }
/// <summary> /// 添加文件 /// </summary> /// <param name="path"></param> /// <param name="groupName"></param> public static string AddAssetToGroup(string path, string groupName) { ResGroupCfg data = resInfo.GetGroupInfo(groupName); if (data == null) { return(""); } string assetName = Path.GetFileNameWithoutExtension(path); if (!data.keys.Contains(assetName)) { data.keys.Add(assetName); if (!resInfo.resources.Exists(a => a.name == assetName)) { ResInfoData da = new ResInfoData(); da.name = assetName; da.path = path.Replace("\\", "/"); da.type = Path.GetExtension(path); da.isFairyGuiPack = false; if (da.type == ".bytes") { TextAsset text = AssetDatabase.LoadAssetAtPath <TextAsset>(da.path); byte [] descBytes = text.bytes; if (descBytes.Length > 4 && descBytes[0] == 0x50 && descBytes[1] == 0x4b && descBytes[2] == 0x03 && descBytes[3] == 0x04) { da.isFairyGuiPack = true; Debug.LogError(text.bytes[0] + "/" + text.bytes[1] + "/" + text.bytes[2] + "/" + text.bytes[3] + "/"); } } da.isKeepInMemory = true; da.isResourcesPath = da.path.Contains("Assets/Resources"); if (da.isResourcesPath) { string rootPath = da.path .Replace("Assets/Resources/", ""); rootPath = Path.GetDirectoryName(rootPath); da.ABName = rootPath; //da.ABName = da.path.Replace(Application.dataPath + "/Resources") } else { string rootPath = Path.GetDirectoryName(da.path); rootPath = rootPath.Substring(rootPath.LastIndexOf("/") + 1); da.ABName = rootPath.ToLower(); } resInfo.resources.Add(da); } } return(assetName); }
/// <summary> /// 创建一个资源组 /// </summary> internal static string HandleGroupCreate() { ResGroupCfg data = new ResGroupCfg(); data.keys = new List <string>(); data.groupName = GetGetUniqueName(); resInfo.groups.Add(data); return(data.groupName); }
/// <summary> /// 加载一个资源组加载完成后会发送事件回调 /// </summary> /// <param name="groupData">资源组信息</param> public void LoadGroup(ResGroupCfg groupData, string groupName) { if (groupData == null) { this.QueueEvent(new ResGroupLoadError(groupName)); Debug.LogError("资源配置信息不存在资源组名称:" + groupName); } else { new LoadGroup(groupData).Load(null); } }
internal static void RemoveAssets(List <string> reAssets, string name) { ResGroupCfg data = resInfo.GetGroupInfo(name); if (data == null) { return; } foreach (string assetName in reAssets) { RemoveAsset(assetName, name); } Update(); }
public ResGroupCfg GetGroupInfo(string groupName) { ResGroupCfg cfg = null; if (this.resCfg != null) { foreach (ResGroupCfg da in this.resCfg.groups) { if (da.sceneName == groupName) { cfg = da; break; } } } return(cfg); }
/// <summary> /// 获得这个资源组里面的所有AB /// </summary> /// <returns></returns> public Dictionary <string, List <ResInfoData> > GetGroupABs(ResGroupCfg groupData) { Dictionary <string, List <ResInfoData> > aBToAssets = new Dictionary <string, List <ResInfoData> >(); foreach (string str in groupData.keys) { ResInfoData data = GetResInfo(str); if (data != null) { if (!data.isResourcesPath) { if (!string.IsNullOrEmpty(data.ABName)) { if (aBToAssets.ContainsKey(data.ABName)) { aBToAssets[data.ABName].Add(data); } else { aBToAssets[data.ABName] = new List <ResInfoData>() { data }; } } else { if (!AppConst.DebugMode) { Debug.LogError("这个资源不存在ab里面 资源名称:" + str + "abName:" + data.ABName); } } } } else { Debug.LogError("资源未配置到资源设置,请打开 Tool->资源配置 资源名称:" + str); } } return(aBToAssets); }
/// <summary> /// 在某个资源组里面移出某个资源 /// </summary> /// <param name="assetName">资源名称</param> /// <param name="name">资源组名称</param> public static void RemoveAsset(string assetName, string name) { ResGroupCfg data = resInfo.GetGroupInfo(name); if (data != null) { if (data.keys.Contains(assetName)) { data.keys.Remove(assetName); } } if (!resInfo.groups.Exists(a => a.keys.Contains(assetName))) { var res = resInfo.GetResInfo(assetName); if (res != null) { resInfo.resources.Remove(res); } } }
/// <summary> /// 拖了一个文件到资源里面 /// </summary> /// <param name="paths"></param> internal static List <string> AddAssetToGroup(string[] paths, string groupName) { List <string> fileNames = new List <string>(); ResGroupCfg data = resInfo.GetGroupInfo(groupName); if (data == null) { return(fileNames); } foreach (string str in paths) { if (AssetDatabase.IsValidFolder(str)) { string[] files = Directory.GetFiles(str); foreach (string fileName in files) { if (Path.GetExtension(fileName) == ".meta") { continue; } string assetName = AddAssetToGroup(fileName, groupName); if (!string.IsNullOrEmpty(assetName)) { fileNames.Add(assetName); } } } else { string assetName = AddAssetToGroup(str, groupName); if (!string.IsNullOrEmpty(assetName)) { fileNames.Add(assetName); } } } return(fileNames); }
public LoadGroup(ResGroupCfg cfg) { //LuaInterface.Debugger.LogError("开始加载资源组:" + cfg.sceneName); mNeedLoadABs.Clear(); needLoadAssets.Clear(); this.groupInfo = cfg; List <ResInfoData> allAssets = new List <ResInfoData>(); foreach (string assetName in this.groupInfo.keys) { ResInfoData info = GameCfgMgr.Instance.GetResInfo(assetName); if (info == null) { Debug.LogWarning("加载了重未为使用的资源 -----assetNane:" + assetName); } else { if (!allAssets.Contains(info)) { if (!ResMgr.Intstance.GetAsset(assetName)) { allAssets.Add(info); } } else { Debug.LogWarning("重复的添加资源 -----assetNane:" + assetName); } } } if (!AppConst.DebugMode) { mNeedLoadABs = GameCfgMgr.Instance.GetGroupABs(cfg); List <string> loadedAb = new List <string>(); foreach (KeyValuePair <string, List <ResInfoData> > kv in mNeedLoadABs) { for (int i = kv.Value.Count - 1; i >= 0; i--) { if (ResMgr.Intstance.GetAsset(kv.Value[i].name)) { kv.Value.RemoveAt(i); } } if (kv.Value.Count == 0) { loadedAb.Add(kv.Key); } } foreach (string ab in loadedAb) { mNeedLoadABs.Remove(ab); } } foreach (List <ResInfoData> assets in mNeedLoadABs.Values) { foreach (ResInfoData fileName in assets) { if (allAssets.Contains(fileName)) { allAssets.Remove(fileName); } } } foreach (ResInfoData assetName in allAssets) { needLoadAssets.Add(assetName.name); } }