void LoadSource(string assetName, System.Action <Object> callback) { #if UNITY_EDITOR if (string.IsNullOrEmpty(assetName)) { return; } GTResourceUnit unit = null; Units.TryGetValue(assetName, out unit); if (unit == null) { Debug.LogError("配置表中不存在:" + assetName); return; } Object asset = UnityEditor.AssetDatabase.LoadAssetAtPath <Object>(unit.Path); if (asset == null) { Debug.LogError("不存在这个资源:" + assetName); return; } if (callback != null) { callback.Invoke(asset); } #endif }
public void LoadConfig() { #if UNITY_EDITOR #else Type = ResourceType.TYPE_BUNDLE; #endif if (IsRead) { return; } IsRead = true; string fsPath = AssetConfigPath + "/Asset.xml"; StreamReader fs = new StreamReader(fsPath); XmlDocument doc = new XmlDocument(); doc.LoadXml(fs.ReadToEnd()); XmlNodeList list = doc.SelectSingleNode("root").ChildNodes; foreach (var current in list) { XmlElement element = current as XmlElement; if (element == null) { continue; } GTResourceUnit u = new GTResourceUnit(); for (int i = 0; i < element.Attributes.Count; i++) { XmlAttribute attr = element.Attributes[i]; switch (attr.Name) { case "AssetBundleName": u.AssetBundleName = attr.Value; break; case "AssetName": u.AssetName = attr.Value; break; case "Path": u.Path = attr.Value; break; case "GUID": u.GUID = attr.Value; break; } } Units.Add(u.AssetName, u); GTResourceBundle bundle = null; Bundles.TryGetValue(u.AssetBundleName, out bundle); if (bundle == null) { bundle = new GTResourceBundle(); bundle.AssetBundleName = u.AssetBundleName; Bundles.Add(u.AssetBundleName, bundle); } } fs.Dispose(); fs.Close(); }
public void UnloadAssetBundleByAssetName(string assetName, bool all = false) { GTResourceUnit unit = null; Units.TryGetValue(assetName, out unit); if (unit != null) { UnloadAssetBundle(unit.AssetBundleName); } }
static void SetBundleNames() { foreach (var current in Units) { GTResourceUnit bundle = current.Value; var assetImporter = AssetImporter.GetAtPath(bundle.Path); if (assetImporter != null) { assetImporter.assetBundleName = bundle.AssetBundleName.ToLower(); } } }
static void SetBundleNames() { Dictionary <string, GTResourceUnit> units = GTResourceManager.Instance.Units; foreach (var current in units) { GTResourceUnit bundle = current.Value; var assetImporter = AssetImporter.GetAtPath(bundle.Path); if (assetImporter != null) { assetImporter.assetBundleName = bundle.AssetBundleName.ToLower(); } } }
void LoadBundle(string assetName, System.Action <Object> callback) { GTResourceUnit unit = null; Units.TryGetValue(assetName, out unit); if (unit == null) { Debug.LogError("配置表中不存在:" + assetName); return; } GTResourceBundle bundle = null; Bundles.TryGetValue(unit.AssetBundleName, out bundle); if (bundle == null) { Debug.LogError("不存在这个Bundle:" + unit.AssetBundleName); return; } AddLoadBundleTask(unit.AssetName, bundle, null, callback); }
static void SetBundleConfig() { List <GTResourceUnit> list = new List <GTResourceUnit>(); UnityEngine.Object[] assets = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.DeepAssets); for (int i = 0; i < assets.Length; i++) { UnityEngine.Object obj = assets[i]; string assetPath = AssetDatabase.GetAssetPath(obj); string extenName = System.IO.Path.GetExtension(assetPath).ToLower(); if (string.IsNullOrEmpty(extenName) || extenName == ".meta") { continue; } GTResourceUnit bundle = new GTResourceUnit(); switch (extenName) { case ".prefab": { bundle.AssetName = obj.name; bundle.AssetBundleName = GetParentPathName(assetPath) + ".pre.assetbundle"; bundle.Path = assetPath; bundle.GUID = AssetDatabase.AssetPathToGUID(bundle.Path); } break; case ".mp3": { bundle.AssetName = obj.name; bundle.AssetBundleName = obj.name + extenName + ".assetbundle"; bundle.Path = assetPath; bundle.GUID = AssetDatabase.AssetPathToGUID(bundle.Path); } break; case ".png": { if (assetPath.Contains("Image")) { bundle.AssetName = obj.name; bundle.AssetBundleName = GetParentPathName(assetPath) + ".atlas.assetbundle"; bundle.Path = assetPath; bundle.GUID = AssetDatabase.AssetPathToGUID(bundle.Path); } if (assetPath.Contains("T_Background")) { bundle.AssetName = obj.name; bundle.AssetBundleName = obj.name + ".tex.assetbundle"; bundle.Path = assetPath; bundle.GUID = AssetDatabase.AssetPathToGUID(bundle.Path); } } break; case ".fbx": { bundle.AssetName = obj.name; bundle.AssetBundleName = obj.name + extenName + ".assetbundle"; bundle.Path = assetPath; bundle.GUID = AssetDatabase.AssetPathToGUID(bundle.Path); } break; } if (string.IsNullOrEmpty(bundle.AssetName)) { continue; } bundle.AssetBundleName = bundle.AssetBundleName.ToLower(); list.Add(bundle); } list.Sort((a1, a2) => { return(a1.AssetName.CompareTo(a2.AssetName)); }); Units.Clear(); foreach (var current in list) { Units[current.AssetName] = current; } XmlDocument doc = new XmlDocument(); XmlNode root = doc.CreateElement("root"); doc.AppendChild(root); foreach (var current in list) { GTResourceUnit bundle = current; XmlElement child = doc.CreateElement("row"); root.AppendChild(child); child.SetAttribute("AssetName", bundle.AssetName); child.SetAttribute("AssetBundleName", bundle.AssetBundleName); child.SetAttribute("Path", bundle.Path); child.SetAttribute("GUID", bundle.GUID); } string fileName = Application.streamingAssetsPath + "/Asset.xml"; FileStream fs = null; if (!File.Exists(fileName)) { fs = File.Create(fileName); } doc.Save(fileName); if (fs != null) { fs.Flush(); fs.Dispose(); fs.Close(); } }