public List <AssetBundleEntitly> GetList() { list.Clear(); XDocument xDocunment = XDocument.Load(this.path); XElement root = xDocunment.Root; XElement assetBundly = root.Element("AssetBundle"); IEnumerable <XElement> Items = assetBundly.Elements("Item"); int index = 0; foreach (var item in Items) { AssetBundleEntitly entitly = new AssetBundleEntitly(); entitly.Key = "key" + ++index; entitly.Name = item.Attribute("Name").Value; entitly.Tag = item.Attribute("Tag").Value; entitly.Version = item.Attribute("Tag").Value.ToInt(); entitly.Size = item.Attribute("Tag").Value.ToLong(); entitly.ToPath = item.Attribute("ToPath").Value; IEnumerable <XElement> paths = item.Elements("Path"); foreach (var path in paths) { entitly.Path.Add(string.Format("Assets/{0}", path.Attribute("Value").Value)); } list.Add(entitly); } return(list); }
/// <summary> /// 绘制窗口 /// </summary> void OnGUI() { if (list == null || list.Count == 0) { return; } #region 钮行 GUILayout.BeginHorizontal("box"); tagIndex = EditorGUILayout.Popup(tagIndex, arrTag, GUILayout.Width(100)); if (GUILayout.Button("选定Tag", GUILayout.Width(100))) { EditorApplication.delayCall = OnSelectTagCallBack; } buildTargetIndex = EditorGUILayout.Popup(buildTargetIndex, arrayBuildTarget, GUILayout.Width(100)); if (GUILayout.Button("选定Target", GUILayout.Width(100))) { EditorApplication.delayCall = OnSelectTargetCallBack; } if (GUILayout.Button("打包AssetBundle", GUILayout.Width(200))) { EditorApplication.delayCall = OnAssetBundleCallBack; } if (GUILayout.Button("清空AssetBundle", GUILayout.Width(200))) { EditorApplication.delayCall = OnClearAssetBundleCallBack; } GUILayout.EndHorizontal(); #endregion GUILayout.BeginHorizontal("box"); GUILayout.Label("包名"); GUILayout.Label("标记", GUILayout.Width(100)); GUILayout.Label("保存路径", GUILayout.Width(200)); GUILayout.Label("版本", GUILayout.Width(100)); GUILayout.Label("大小", GUILayout.Width(100)); GUILayout.EndHorizontal(); pos = EditorGUILayout.BeginScrollView(pos); for (int i = 0; i < list.Count; i++) { AssetBundleEntitly entity = list[i]; GUILayout.BeginHorizontal("box"); dic[list[i].Key] = EditorGUILayout.Toggle(dic[list[i].Key], GUILayout.Width(20)); GUILayout.Label(entity.Name); GUILayout.Label(entity.Tag, GUILayout.Width(100)); GUILayout.Label(entity.ToPath, GUILayout.Width(200)); GUILayout.Label(entity.Version.ToString(), GUILayout.Width(100)); GUILayout.Label(entity.Size.ToString(), GUILayout.Width(100)); GUILayout.EndHorizontal(); foreach (var item in entity.Path) { GUILayout.BeginHorizontal("box"); GUILayout.Space(40); GUILayout.Label(item); GUILayout.EndHorizontal(); } } EditorGUILayout.EndScrollView(); }
private void RunAssetBundBuild(AssetBundleEntitly entitly) { AssetBundleBuild[] arrBuild = new AssetBundleBuild[1]; AssetBundleBuild build = new AssetBundleBuild(); build.assetBundleName = string.Format("{0}.{1}", entitly.Name, entitly.Tag.Equals("Scene", StringComparison.CurrentCultureIgnoreCase) ? "Scene" : "AssetBundle"); build.assetNames = entitly.Path.ToArray(); arrBuild[0] = build; Debug.Log(entitly.ToPath); string toPath = Application.dataPath + "/../AssetBundles/" + arrayBuildTarget[buildTargetIndex] + entitly.ToPath; if (!Directory.Exists(toPath)) { Directory.CreateDirectory(toPath); } BuildPipeline.BuildAssetBundles(toPath, arrBuild, BuildAssetBundleOptions.None, buildTarget); }
/// <summary> /// 绘制窗口 /// </summary> void OnGUI() { if (list == null || list.Count == 0) { return; } #region 钮行 GUILayout.BeginHorizontal("box"); selectTagIndex = EditorGUILayout.Popup(tagIndex, arrTag, GUILayout.Width(100)); if (selectTagIndex != tagIndex) { tagIndex = selectTagIndex; EditorApplication.delayCall = OnSelectTagCallBack; } selectBuildTarget = EditorGUILayout.Popup(buildTargetIndex, arrayBuildTarget, GUILayout.Width(100)); if (selectBuildTarget != buildTargetIndex) { buildTargetIndex = selectBuildTarget; EditorApplication.delayCall = OnSelectTargetCallBack; } if (GUILayout.Button("保存设置", GUILayout.Width(200))) { EditorApplication.delayCall = OnSaveSettingCallBack; } if (GUILayout.Button("打包AssetBundle", GUILayout.Width(200))) { EditorApplication.delayCall = OnAssetBundleCallBack; } if (GUILayout.Button("清空AssetBundle", GUILayout.Width(200))) { EditorApplication.delayCall = OnClearAssetBundleCallBack; } GUILayout.EndHorizontal(); #endregion GUILayout.BeginHorizontal("box"); GUILayout.Label("包名"); GUILayout.Label("标记", GUILayout.Width(100)); GUILayout.Label("文件夹", GUILayout.Width(200)); GUILayout.Label("初始资源", GUILayout.Width(200)); GUILayout.EndHorizontal(); pos = EditorGUILayout.BeginScrollView(pos); for (int i = 0; i < list.Count; i++) { AssetBundleEntitly entity = list[i]; GUILayout.BeginHorizontal("box"); dic[list[i].Key] = EditorGUILayout.Toggle(dic[list[i].Key], GUILayout.Width(20)); GUILayout.Label(entity.Name); GUILayout.Label(entity.Tag, GUILayout.Width(100)); GUILayout.Label(entity.IsFolder.ToString(), GUILayout.Width(200)); GUILayout.Label(entity.IsFirstData.ToString(), GUILayout.Width(200)); GUILayout.EndHorizontal(); foreach (var item in entity.Path) { GUILayout.BeginHorizontal("box"); GUILayout.Space(40); GUILayout.Label(item); GUILayout.EndHorizontal(); } } EditorGUILayout.EndScrollView(); }