public void RefreshFile(bool showNewFile = false) { //if (!File.Exists(abPath)) return; string[] temps = Directory.GetFiles(abPath, "*.*", SearchOption.TopDirectoryOnly). Where(s => GetFileFilter().Contains(Path.GetExtension(s).ToLower())).ToArray(); for (int i = 0; i < temps.Length; ++i) { var path = temps[i].Replace('\\', '/'); if (!files.ContainsKey(path)) { var abName = this.abName + "/" + Path.GetFileNameWithoutExtension(path).ToLower(); int assetType = showNewFile ? 2 : 0; if (abName.Contains("gui/") || abName.Contains("effect/") || abName.Contains("cutscene/")) { assetType = 0; } else if (abName.Contains("models/") || abName.Contains("scenes/") || abName.Contains("sound/")) { assetType = 3; } var child = new ABData(this, path, abName, 1, 0, layer + 1, (int)filterType, showFileOnly, preload, assetType, false, packOrder, downloadOrder, showNewFile); files.Add(path, child); } else { files[path].removeFlag = false; } } var temp_dict = files.OrderBy(p => p.Key).ToDictionary(p => p.Key, p => p.Value); files.Clear(); files = temp_dict; }
public static ABData GetObject(string url, string resname, System.Type type) { ABLoad load = mUti.mFactory.Get(url, version); if (load == null) { return(null); } if (load.Error()) { return(null); } Object o = load.GetObject(resname, type, ShowParticleSys); if (o == null) { return(null); } if (null == type) { return(null); } ABData data = new ABData(url, resname, type, load); datas.Add(data); return(data); }
void OnDestroy() { Clear(); if (_AbData != null) { AssetBundleUti.RemoveAbData(_AbData); _AbData = null; } }
public void DeserializeFolderAndFile(XmlNode node, ABData parent) { for (int i = 0; i < node.ChildNodes.Count; ++i) { var data = DeserializeFromXml(node.ChildNodes[i], parent); if (string.IsNullOrEmpty(Path.GetExtension(data.abPath))) { folders.Add(data.abPath, data); } else { files.Add(data.abPath, data); } } }
void CleanDataByScene() { for (int i = datas.Count - 1; i >= 0; --i) { ABData data = (ABData)datas[i]; if (!data.IsDontDestroyOnLoad()) { datas.Remove(data); data.Dispose(); data = null; } } }
private IEnumerator CoLoadAB(HAssetBundle ab) { ABData abData = null; if (!mABDataMap.TryGetValue(ab.ABName, out abData)) { abData = new ABData(); mABDataMap[ab.ABName] = abData; } if (abData.mAB == null) { string url = PathManager.URL(ab.ABName, mAssetType, false); if (mIsSync) { if (abData.mRequest == null) { abData.mAB = AssetBundle.LoadFromFile(url); } else { abData.mAB = abData.mRequest.assetBundle; } } else { if (abData.mRequest == null) { AssetBundleCreateRequest request = AssetBundle.LoadFromFileAsync(url); abData.mRequest = request; yield return(request); } else { while (!abData.mRequest.isDone) { yield return(null); } } abData.mAB = abData.mRequest.assetBundle; } ab.AB = abData.mAB; } }
void SetResourcesFolder() { string path = EditorUtility.OpenFolderPanel(ABLanguage.SET_RESOURCE_FOLDER, "Assets", ""); if (string.IsNullOrEmpty(path)) { return; } ABData.datas.Clear(); string[] pathes = Directory.GetDirectories(path, "*.*", SearchOption.TopDirectoryOnly); for (int i = 0; i < pathes.Length; ++i) { var abPath = "Assets" + Path.GetFullPath(pathes[i]).Replace(Path.GetFullPath(Application.dataPath), "").Replace('\\', '/'); var data = new ABData(null, abPath, "", 0, 0, 0, 0, false, false, 0, false, 0, 0, false); ABData.datas.Add(abPath, data); } }
public void RefreshFolder(bool showNewFile = false) { try { string[] dirs = Directory.GetDirectories(abPath, "*.*", SearchOption.TopDirectoryOnly); for (int i = 0; i < dirs.Length; ++i) { var path = dirs[i].Replace('\\', '/'); if (path.Contains("Effect/") && !path.Contains("Effect/Body_effect")) { continue; } if (path.Contains("Resources/")) { if (path.Contains("Resources/Font") || path.Contains("Resources/Logo") || path.Contains("Resources/Other")) { continue; } } if (path.Contains("Scenes/") && !path.Contains("Scenes/Level")) { continue; } if (!folders.ContainsKey(path)) { var child = new ABData(this, path, abName, 0, 0, layer + 1, (int)filterType, showFileOnly, preload, showNewFile ? 2 : 0, false, packOrder, downloadOrder, showNewFile); folders.Add(path, child); } else { folders[path].removeFlag = false; } } var temp_dict = folders.OrderBy(p => p.Key).ToDictionary(p => p.Key, p => p.Value); folders.Clear(); folders = temp_dict; } catch (Exception e) { Debug.LogWarning(e.Message); } }
public static void RemoveAbData(ABData _data) { for (int i = datas.Count - 1; i >= 0; --i) { ABData data = (ABData)datas[i]; if (_data == data) { datas.Remove(data); data.Dispose(); data = null; _data = null; break; } } }
public static ABData DeserializeFromXml(XmlNode node, ABData parent) { var abPath = node.Attributes["path"].Value; var abName = node.Attributes["abName"].Value; var dataType = Convert.ToInt32(node.Attributes["dataType"].Value); var packType = Convert.ToInt32(node.Attributes["packType"].Value); var filterType = Convert.ToInt32(node.Attributes["filterType"].Value); var layer = Convert.ToInt32(node.Attributes["layer"].Value); var packOrder = Convert.ToInt32(node.Attributes["packOrder"].Value); var showFileOnly = Convert.ToBoolean(node.Attributes["showFileOnly"].Value); var preload = Convert.ToBoolean(node.Attributes["preload"].Value); var assetType = Convert.ToInt32(node.Attributes["assetType"].Value); var removeFlag = Convert.ToBoolean(node.Attributes["removeFlag"].Value); var downloadOrder = Convert.ToInt32(node.Attributes["downloadOrder"].Value); ABData data = new ABData(parent, abPath, abName, dataType, packType, layer, filterType, showFileOnly, preload, assetType, removeFlag, packOrder, downloadOrder, false); data.DeserializeFolderAndFile(node, data); return(data); }
private void AssetBundleUtiCallBack(string url, string resname, System.Type type, bool success, string errorcode = "") { Debuger.Log("AssetBundleUtiCallBack:" + url + " " + resname + " " + type + " " + success); if (success) { data = AssetBundleUti.GetObject(url, resname, type); Shader.WarmupAllShaders(); } LightmapParam[] lmd = data.gameobject.GetComponentsInChildren <LightmapParam>(true); Debug.Log("LM: " + lmd.Length.ToString()); for (int i = 0; i < lmd.Length; i++) { Renderer r = lmd[i].gameObject.GetComponent <Renderer>(); r.gameObject.isStatic = true; r.lightmapIndex = lmd[i].lightmapIndex; r.lightmapScaleOffset = lmd[i].lightmapScaleOffset; } }
public ABData(ABData parent, string abPath, string abName, int dataType, int packType, int layer, int filterType, bool showFileOnly, bool preload, int assetType, bool removeFlag, int packOrder, int downloadOrder, bool isNew) { this.parent = parent; this.abPath = abPath; this.abName = abName.ToLower(); this.dataType = (ABDataType)dataType; this.packType = (PackType)packType; this.layer = layer; this.packOrder = packOrder; this.filterType = (FileFilterType)filterType; this.showFileOnly = showFileOnly; this.showChild = true; this.preload = preload; this.assetType = assetType; this.removeFlag = removeFlag; this.downloadOrder = downloadOrder; this.isNew = isNew; this.folders = new Dictionary <string, ABData>(); this.files = new Dictionary <string, ABData>(); attrChangeCallbacks.Add(this.OnAttributesChanged); }
void LoadConfig(string path) { ABData.datas.Clear(); XmlDocument doc = new XmlDocument(); doc.Load(path); var root = doc.SelectSingleNode("ABConfig"); if (root.Attributes["lastConfigIndex"] != null) { lastSelectConfigIndex = Convert.ToInt32(root.Attributes["lastConfigIndex"].Value); } var nodes = root.SelectNodes("data"); ABData.datas.Clear(); for (int i = 0; i < nodes.Count; ++i) { var abPath = nodes[i].Attributes["path"].Value; var data = ABData.DeserializeFromXml(nodes[i], null); ABData.datas.Add(abPath, data); } }
public static ABData GetObject(string url, string resname, System.Type type) { ABLoad load = mUti.mFactory.Get(url, version); if (load == null) return null; if (load.Error()) return null; Object o = load.GetObject(resname, type, ShowParticleSys); if (o == null) return null; if (null == type) { return null; } ABData data = new ABData(url, resname, type, load); datas.Add(data); return data; }
/// <summary> /// 生成资源配置表 /// </summary> static void GenerateResourceCfg() { // resPath对应的AB包 Dictionary <string, string> res_to_bundle = new Dictionary <string, string>(); Dictionary <string, string[]> ab_to_abDepences = new Dictionary <string, string[]>(); string[] allBundleNames = AssetDatabase.GetAllAssetBundleNames(); for (int i = 0; i < allBundleNames.Length; i++) { string bundleName = allBundleNames[i]; string[] inBundleAssetPaths = AssetDatabase.GetAssetPathsFromAssetBundle(bundleName); for (int j = 0; j < inBundleAssetPaths.Length; j++) { string assetPath = inBundleAssetPaths[j]; if (!assetPath.EndsWith(".cs") && IsDynamicLoadPath(assetPath)) { // 只有在上面配置中的资源才会进入bundleName res_to_bundle.Add(assetPath, bundleName); } } string[] dependBundleNames = AssetDatabase.GetAssetBundleDependencies(bundleName, false); ab_to_abDepences.Add(bundleName, dependBundleNames); } // 构造每个Res的依赖信息 AssetBundleConfig configs = ScriptableObject.CreateInstance <AssetBundleConfig>(); configs.ResDict = new List <ResData>(); foreach (var item in res_to_bundle) { ResData abBase = new ResData(); string assetFullPath = item.Key; abBase.Path = assetFullPath; abBase.ABName = item.Value; abBase.AssetName = assetFullPath.Remove(0, assetFullPath.LastIndexOf("/") + 1); configs.ResDict.Add(abBase); } // 构造每个AB包的依赖信息 configs.ABDict = new List <ABData>(); foreach (var item in ab_to_abDepences) { ABData abData = new ABData(); abData.Name = item.Key; abData.DependenceNames = item.Value; configs.ABDict.Add(abData); } // lua文件加个.txt后缀 foreach (var item in configs.ResDict) { if (item.Path.EndsWith(".lua")) { item.Path += ".txt"; item.AssetName += ".txt"; } } // 依赖信息写入json string filePath = Path.Combine("Assets/GameData/Configs", "AssetBundleConfig.asset"); File.Delete(filePath); AssetDatabase.CreateAsset(configs, filePath); AssetDatabase.Refresh(); }