From 1278d76f49eaf24e293fcb482a563c5f4c326ce5 Mon Sep 17 00:00:00 2001 From: hevinci Date: Sat, 2 Apr 2022 15:12:51 +0800 Subject: [PATCH] Update AssetBundleCollector Remove files --- .../YooAsset/Editor/AssetBundleCollector.meta | 8 - .../AssetBundleCollectorSetting.cs | 68 --- .../AssetBundleCollectorSetting.cs.meta | 11 - .../AssetBundleCollectorSettingData.cs | 477 ------------------ .../AssetBundleCollectorSettingData.cs.meta | 11 - .../AssetBundleCollectorWindow.cs | 243 --------- .../AssetBundleCollectorWindow.cs.meta | 11 - .../AssetBundleCollector/CollectAssetInfo.cs | 30 -- .../CollectAssetInfo.cs.meta | 11 - .../CollectorConfigImporter.cs | 99 ---- .../CollectorConfigImporter.cs.meta | 11 - .../AssetBundleCollector/DefaultFilterRule.cs | 53 -- .../DefaultFilterRule.cs.meta | 11 - .../AssetBundleCollector/DefaultPackRule.cs | 55 -- .../DefaultPackRule.cs.meta | 11 - .../AssetBundleCollector/IFilterRule.cs | 16 - .../AssetBundleCollector/IFilterRule.cs.meta | 11 - .../Editor/AssetBundleCollector/IPackRule.cs | 14 - .../AssetBundleCollector/IPackRule.cs.meta | 11 - 19 files changed, 1162 deletions(-) delete mode 100644 Assets/YooAsset/Editor/AssetBundleCollector.meta delete mode 100644 Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSetting.cs delete mode 100644 Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSetting.cs.meta delete mode 100644 Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs delete mode 100644 Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs.meta delete mode 100644 Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs delete mode 100644 Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs.meta delete mode 100644 Assets/YooAsset/Editor/AssetBundleCollector/CollectAssetInfo.cs delete mode 100644 Assets/YooAsset/Editor/AssetBundleCollector/CollectAssetInfo.cs.meta delete mode 100644 Assets/YooAsset/Editor/AssetBundleCollector/CollectorConfigImporter.cs delete mode 100644 Assets/YooAsset/Editor/AssetBundleCollector/CollectorConfigImporter.cs.meta delete mode 100644 Assets/YooAsset/Editor/AssetBundleCollector/DefaultFilterRule.cs delete mode 100644 Assets/YooAsset/Editor/AssetBundleCollector/DefaultFilterRule.cs.meta delete mode 100644 Assets/YooAsset/Editor/AssetBundleCollector/DefaultPackRule.cs delete mode 100644 Assets/YooAsset/Editor/AssetBundleCollector/DefaultPackRule.cs.meta delete mode 100644 Assets/YooAsset/Editor/AssetBundleCollector/IFilterRule.cs delete mode 100644 Assets/YooAsset/Editor/AssetBundleCollector/IFilterRule.cs.meta delete mode 100644 Assets/YooAsset/Editor/AssetBundleCollector/IPackRule.cs delete mode 100644 Assets/YooAsset/Editor/AssetBundleCollector/IPackRule.cs.meta diff --git a/Assets/YooAsset/Editor/AssetBundleCollector.meta b/Assets/YooAsset/Editor/AssetBundleCollector.meta deleted file mode 100644 index 9afb783..0000000 --- a/Assets/YooAsset/Editor/AssetBundleCollector.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 0dbd5f557007d574e80c42d4a15421a9 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSetting.cs b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSetting.cs deleted file mode 100644 index 183e2ae..0000000 --- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSetting.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -namespace YooAsset.Editor -{ - public class AssetBundleCollectorSetting : ScriptableObject - { - [Serializable] - public class Collector - { - /// - /// 收集的文件夹路径 - /// - public string CollectDirectory = string.Empty; - - /// - /// 打包规则类名 - /// - public string PackRuleName = string.Empty; - - /// - /// 过滤规则类名 - /// - public string FilterRuleName = string.Empty; - - /// - /// 不写入资源路径到清单文件 - /// 注意:对于不依赖于代码加载的收集资源,可以禁止写入资源路径信息到清单文件 - /// - public bool DontWriteAssetPath = false; - - /// - /// 资源标记 - /// - public string AssetTags = string.Empty; - - /// - /// 获取资源标记列表 - /// - public List GetAssetTags() - { - return StringUtility.StringToStringList(AssetTags, ';'); - } - - public override string ToString() - { - return $"Directory : {CollectDirectory} | {PackRuleName} | {FilterRuleName} | {DontWriteAssetPath} | {AssetTags}"; - } - } - - /// - /// 自动收集着色器 - /// - public bool AutoCollectShaders = false; - - /// - /// 自动收集的着色器资源包名 - /// - public string ShadersBundleName = "myshaders"; - - /// - /// 收集列表 - /// - public List Collectors = new List(); - } -} \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSetting.cs.meta b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSetting.cs.meta deleted file mode 100644 index 7bdd4a4..0000000 --- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSetting.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 4cc54f0173b27fb40aee29e7eb3364da -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs deleted file mode 100644 index 572e40c..0000000 --- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs +++ /dev/null @@ -1,477 +0,0 @@ -using System; -using System.IO; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using UnityEngine; -using UnityEditor; - -namespace YooAsset.Editor -{ - public static class AssetBundleCollectorSettingData - { - private static readonly Dictionary _cachePackRuleTypes = new Dictionary(); - private static readonly Dictionary _cachePackRuleInstance = new Dictionary(); - - private static readonly Dictionary _cacheFilterRuleTypes = new Dictionary(); - private static readonly Dictionary _cacheFilterRuleInstance = new Dictionary(); - - - private static AssetBundleCollectorSetting _setting = null; - public static AssetBundleCollectorSetting Setting - { - get - { - if (_setting == null) - LoadSettingData(); - return _setting; - } - } - - public static List GetPackRuleNames() - { - if (_setting == null) - LoadSettingData(); - - List names = new List(); - foreach (var pair in _cachePackRuleTypes) - { - names.Add(pair.Key); - } - return names; - } - public static List GetFilterRuleNames() - { - if (_setting == null) - LoadSettingData(); - - List names = new List(); - foreach (var pair in _cacheFilterRuleTypes) - { - names.Add(pair.Key); - } - return names; - } - public static bool HasPackRuleName(string ruleName) - { - foreach (var pair in _cachePackRuleTypes) - { - if (pair.Key == ruleName) - return true; - } - return false; - } - public static bool HasFilterRuleName(string ruleName) - { - foreach (var pair in _cacheFilterRuleTypes) - { - if (pair.Key == ruleName) - return true; - } - return false; - } - - /// - /// 加载配置文件 - /// - private static void LoadSettingData() - { - // 加载配置文件 - _setting = AssetDatabase.LoadAssetAtPath(EditorDefine.AssetBundleCollectorSettingFilePath); - if (_setting == null) - { - Debug.LogWarning($"Create new {nameof(AssetBundleCollectorSetting)}.asset : {EditorDefine.AssetBundleCollectorSettingFilePath}"); - _setting = ScriptableObject.CreateInstance(); - EditorTools.CreateFileDirectory(EditorDefine.AssetBundleCollectorSettingFilePath); - AssetDatabase.CreateAsset(Setting, EditorDefine.AssetBundleCollectorSettingFilePath); - AssetDatabase.SaveAssets(); - AssetDatabase.Refresh(); - } - else - { - Debug.Log($"Load {nameof(AssetBundleCollectorSetting)}.asset ok"); - } - - // IPackRule - { - // 清空缓存集合 - _cachePackRuleTypes.Clear(); - _cachePackRuleInstance.Clear(); - - // 获取所有类型 - List types = new List(100) - { - typeof(PackExplicit), - typeof(PackDirectory), - typeof(PackRawFile), - }; - var customTypes = AssemblyUtility.GetAssignableTypes(AssemblyUtility.UnityDefaultAssemblyEditorName, typeof(IPackRule)); - types.AddRange(customTypes); - for (int i = 0; i < types.Count; i++) - { - Type type = types[i]; - if (_cachePackRuleTypes.ContainsKey(type.Name) == false) - _cachePackRuleTypes.Add(type.Name, type); - } - } - - // IFilterRule - { - // 清空缓存集合 - _cacheFilterRuleTypes.Clear(); - _cacheFilterRuleInstance.Clear(); - - // 获取所有类型 - List types = new List(100) - { - typeof(CollectAll), - typeof(CollectScene), - typeof(CollectPrefab), - typeof(CollectSprite) - }; - var customTypes = AssemblyUtility.GetAssignableTypes(AssemblyUtility.UnityDefaultAssemblyEditorName, typeof(IFilterRule)); - types.AddRange(customTypes); - for (int i = 0; i < types.Count; i++) - { - Type type = types[i]; - if (_cacheFilterRuleTypes.ContainsKey(type.Name) == false) - _cacheFilterRuleTypes.Add(type.Name, type); - } - } - } - - /// - /// 存储文件 - /// - public static void SaveFile() - { - if (Setting != null) - { - EditorUtility.SetDirty(Setting); - AssetDatabase.SaveAssets(); - } - } - - // 着色器相关 - public static void ModifyShader(bool isCollectAllShaders, string shadersBundleName) - { - if (string.IsNullOrEmpty(shadersBundleName)) - return; - Setting.AutoCollectShaders = isCollectAllShaders; - Setting.ShadersBundleName = shadersBundleName; - SaveFile(); - } - - // 收集器相关 - public static void ClearAllCollector() - { - Setting.Collectors.Clear(); - SaveFile(); - } - public static void AddCollector(string directory, string packRuleName, string filterRuleName, bool dontWriteAssetPath, string assetTags, bool saveFile = true) - { - // 末尾添加路径分隔符号 - if (directory.EndsWith("/") == false) - directory = $"{directory}/"; - - // 检测收集器路径冲突 - if (CheckConflict(directory)) - return; - - // 检测资源标签 - if (dontWriteAssetPath && string.IsNullOrEmpty(assetTags) == false) - Debug.LogWarning($"Collector {directory} has asset tags : {assetTags}, It is not vliad when enable dontWriteAssetPath."); - - AssetBundleCollectorSetting.Collector element = new AssetBundleCollectorSetting.Collector(); - element.CollectDirectory = directory; - element.PackRuleName = packRuleName; - element.FilterRuleName = filterRuleName; - element.DontWriteAssetPath = dontWriteAssetPath; - element.AssetTags = assetTags; - Setting.Collectors.Add(element); - - if (saveFile) - SaveFile(); - } - public static void RemoveCollector(string directory) - { - for (int i = 0; i < Setting.Collectors.Count; i++) - { - if (Setting.Collectors[i].CollectDirectory == directory) - { - Setting.Collectors.RemoveAt(i); - break; - } - } - SaveFile(); - } - public static void ModifyCollector(string directory, string packRuleName, string filterRuleName, bool dontWriteAssetPath, string assetTags) - { - // 检测资源标签 - if (dontWriteAssetPath && string.IsNullOrEmpty(assetTags) == false) - Debug.LogWarning($"Collector '{directory}' has asset tags '{assetTags}', It is invalid when enable dontWriteAssetPath."); - - for (int i = 0; i < Setting.Collectors.Count; i++) - { - var collector = Setting.Collectors[i]; - if (collector.CollectDirectory == directory) - { - collector.PackRuleName = packRuleName; - collector.FilterRuleName = filterRuleName; - collector.DontWriteAssetPath = dontWriteAssetPath; - collector.AssetTags = assetTags; - break; - } - } - SaveFile(); - } - public static bool IsContainsCollector(string directory) - { - for (int i = 0; i < Setting.Collectors.Count; i++) - { - if (Setting.Collectors[i].CollectDirectory == directory) - return true; - } - return false; - } - public static bool CheckConflict(string directory) - { - if (IsContainsCollector(directory)) - { - Debug.LogError($"Asset collector already existed : {directory}"); - return true; - } - - for (int i = 0; i < Setting.Collectors.Count; i++) - { - var wrapper = Setting.Collectors[i]; - string compareDirectory = wrapper.CollectDirectory; - if (directory.StartsWith(compareDirectory)) - { - Debug.LogError($"New asset collector \"{directory}\" conflict with \"{compareDirectory}\""); - return true; - } - if (compareDirectory.StartsWith(directory)) - { - Debug.LogError($"New asset collector {directory} conflict with {compareDirectory}"); - return true; - } - } - - return false; - } - - /// - /// 获取所有的DLC标记 - /// - public static List GetAllAssetTags() - { - List result = new List(); - for (int i = 0; i < Setting.Collectors.Count; i++) - { - var tags = Setting.Collectors[i].GetAssetTags(); - foreach (var tag in tags) - { - if (result.Contains(tag) == false) - result.Add(tag); - } - } - return result; - } - - /// - /// 获取收集器总数 - /// - public static int GetCollecterCount() - { - return Setting.Collectors.Count; - } - - /// - /// 获取所有的收集路径 - /// - public static List GetAllCollectDirectory() - { - List result = new List(); - for (int i = 0; i < Setting.Collectors.Count; i++) - { - AssetBundleCollectorSetting.Collector collector = Setting.Collectors[i]; - result.Add(collector.CollectDirectory); - } - return result; - } - - /// - /// 获取所有收集的资源 - /// 注意:跳过了不写入资源路径的收集器 - /// - public static List GetAllCollectAssets() - { - Dictionary result = new Dictionary(10000); - for (int i = 0; i < Setting.Collectors.Count; i++) - { - AssetBundleCollectorSetting.Collector collector = Setting.Collectors[i]; - - // 注意:跳过不需要写入资源路径的收集器 - if (collector.DontWriteAssetPath) - continue; - - bool isRawAsset = collector.PackRuleName == nameof(PackRawFile); - string[] findAssets = EditorTools.FindAssets(EAssetSearchType.All, collector.CollectDirectory); - foreach (string assetPath in findAssets) - { - if (IsValidateAsset(assetPath) == false) - continue; - if (IsCollectAsset(assetPath, collector.FilterRuleName) == false) - continue; - - if (result.ContainsKey(assetPath) == false) - { - var collectInfo = new CollectAssetInfo(assetPath, collector.GetAssetTags(), isRawAsset); - result.Add(assetPath, collectInfo); - } - } - } - return result.Values.ToList(); - } - private static bool IsCollectAsset(string assetPath, string filterRuleName) - { - if (Setting.AutoCollectShaders) - { - Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath); - if (assetType == typeof(UnityEngine.Shader)) - return true; - } - - // 根据规则设置获取标签名称 - IFilterRule filterRuleInstance = GetFilterRuleInstance(filterRuleName); - return filterRuleInstance.IsCollectAsset(assetPath); - } - - /// - /// 检测资源路径是否被收集器覆盖 - /// - public static bool HasCollector(string assetPath) - { - // 如果收集全路径着色器 - if (Setting.AutoCollectShaders) - { - System.Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath); - if (assetType == typeof(UnityEngine.Shader)) - return true; - } - - for (int i = 0; i < Setting.Collectors.Count; i++) - { - AssetBundleCollectorSetting.Collector collector = Setting.Collectors[i]; - if (assetPath.StartsWith(collector.CollectDirectory)) - return true; - } - - return false; - } - - /// - /// 检测资源是否有效 - /// - public static bool IsValidateAsset(string assetPath) - { - if (assetPath.StartsWith("Assets/") == false && assetPath.StartsWith("Packages/") == false) - return false; - - if (AssetDatabase.IsValidFolder(assetPath)) - return false; - - // 注意:忽略编辑器下的类型资源 - Type type = AssetDatabase.GetMainAssetTypeAtPath(assetPath); - if (type == typeof(LightingDataAsset)) - return false; - - string ext = System.IO.Path.GetExtension(assetPath); - if (ext == "" || ext == ".dll" || ext == ".cs" || ext == ".js" || ext == ".boo" || ext == ".meta") - return false; - - return true; - } - - /// - /// 获取资源包名 - /// - public static string GetBundleLabel(string assetPath) - { - // 如果收集全路径着色器 - if (Setting.AutoCollectShaders) - { - System.Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath); - if (assetType == typeof(UnityEngine.Shader)) - { - return EditorTools.GetRegularPath(Setting.ShadersBundleName); - } - } - - // 获取收集器 - AssetBundleCollectorSetting.Collector findCollector = null; - for (int i = 0; i < Setting.Collectors.Count; i++) - { - AssetBundleCollectorSetting.Collector collector = Setting.Collectors[i]; - if (assetPath.StartsWith(collector.CollectDirectory)) - { - findCollector = collector; - break; - } - } - - // 如果没有找到收集器 - string bundleLabel; - if (findCollector == null) - { - IPackRule defaultInstance = new PackDirectory(); - bundleLabel = defaultInstance.GetAssetBundleLabel(assetPath); - } - else - { - // 根据规则设置获取标签名称 - IPackRule getInstance = GetPackRuleInstance(findCollector.PackRuleName); - bundleLabel = getInstance.GetAssetBundleLabel(assetPath); - } - - // 返回包名 - return EditorTools.GetRegularPath(bundleLabel); - } - - private static IPackRule GetPackRuleInstance(string ruleName) - { - if (_cachePackRuleInstance.TryGetValue(ruleName, out IPackRule instance)) - return instance; - - // 如果不存在创建类的实例 - if (_cachePackRuleTypes.TryGetValue(ruleName, out Type type)) - { - instance = (IPackRule)Activator.CreateInstance(type); - _cachePackRuleInstance.Add(ruleName, instance); - return instance; - } - else - { - throw new Exception($"{nameof(IPackRule)}类型无效:{ruleName}"); - } - } - private static IFilterRule GetFilterRuleInstance(string ruleName) - { - if (_cacheFilterRuleInstance.TryGetValue(ruleName, out IFilterRule instance)) - return instance; - - // 如果不存在创建类的实例 - if (_cacheFilterRuleTypes.TryGetValue(ruleName, out Type type)) - { - instance = (IFilterRule)Activator.CreateInstance(type); - _cacheFilterRuleInstance.Add(ruleName, instance); - return instance; - } - else - { - throw new Exception($"{nameof(IFilterRule)}类型无效:{ruleName}"); - } - } - } -} \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs.meta b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs.meta deleted file mode 100644 index 2bd8874..0000000 --- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 5d4d2a4e23c5e0646a07add04fd8e18a -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs deleted file mode 100644 index 0c14a1b..0000000 --- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs +++ /dev/null @@ -1,243 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using UnityEditor; - -namespace YooAsset.Editor -{ - public class AssetBundleCollectorWindow : EditorWindow - { - static AssetBundleCollectorWindow _thisInstance; - - [MenuItem("YooAsset/AssetBundle Collector", false, 101)] - static void ShowWindow() - { - if (_thisInstance == null) - { - _thisInstance = EditorWindow.GetWindow(typeof(AssetBundleCollectorWindow), false, "资源包收集工具", true) as AssetBundleCollectorWindow; - _thisInstance.minSize = new Vector2(800, 600); - } - _thisInstance.Show(); - } - - /// - /// 上次打开的文件夹路径 - /// - private string _lastOpenFolderPath = "Assets/"; - - // GUI相关 - private const float GuiDirecotryMinSize = 300f; - private const float GuiDirecotryMaxSize = 800f; - private const float GuiPackRuleSize = 130f; - private const float GuiFilterRuleSize = 130f; - private const float GuiDontWriteAssetPathSize = 130f; - private const float GuiAssetTagsMinSize = 100f; - private const float GuiAssetTagsMaxSize = 300f; - private const float GuiBtnSize = 40f; - private Vector2 _scrollPos = Vector2.zero; - - // 初始化相关 - private string[] _packRuleArray = null; - private string[] _filterRuleArray = null; - private bool _isInit = false; - - - private void Init() - { - List packRuleNames = AssetBundleCollectorSettingData.GetPackRuleNames(); - _packRuleArray = packRuleNames.ToArray(); - - List filterRuleNames = AssetBundleCollectorSettingData.GetFilterRuleNames(); - _filterRuleArray = filterRuleNames.ToArray(); - } - private int PackRuleNameToIndex(string name) - { - for (int i = 0; i < _packRuleArray.Length; i++) - { - if (_packRuleArray[i] == name) - return i; - } - return 0; - } - private string IndexToPackRuleName(int index) - { - for (int i = 0; i < _packRuleArray.Length; i++) - { - if (i == index) - return _packRuleArray[i]; - } - return string.Empty; - } - private int FilterRuleNameToIndex(string name) - { - for (int i = 0; i < _filterRuleArray.Length; i++) - { - if (_filterRuleArray[i] == name) - return i; - } - return 0; - } - private string IndexToFilterRuleName(int index) - { - for (int i = 0; i < _filterRuleArray.Length; i++) - { - if (i == index) - return _filterRuleArray[i]; - } - return string.Empty; - } - - private void OnGUI() - { - if (_isInit == false) - { - _isInit = true; - Init(); - } - - OnDrawShader(); - OnDrawHeadBar(); - OnDrawCollector(); - } - private void OnDrawShader() - { - bool isCollectAllShader = AssetBundleCollectorSettingData.Setting.AutoCollectShaders; - string shadersBundleName = AssetBundleCollectorSettingData.Setting.ShadersBundleName; - - EditorGUILayout.Space(); - - bool newToggleValue = EditorGUILayout.Toggle("收集所有着色器", isCollectAllShader); - if (newToggleValue != isCollectAllShader) - { - isCollectAllShader = newToggleValue; - AssetBundleCollectorSettingData.ModifyShader(isCollectAllShader, shadersBundleName); - } - - if (isCollectAllShader) - { - string newTextValue = EditorGUILayout.TextField("AssetBundle名称", shadersBundleName, GUILayout.MaxWidth(300)); - if (newTextValue != shadersBundleName) - { - shadersBundleName = newTextValue; - AssetBundleCollectorSettingData.ModifyShader(isCollectAllShader, shadersBundleName); - } - } - } - private void OnDrawHeadBar() - { - EditorGUILayout.Space(); - EditorGUILayout.Space(); - EditorGUILayout.BeginHorizontal(); - EditorGUILayout.LabelField("Directory", GUILayout.MinWidth(GuiDirecotryMinSize), GUILayout.MaxWidth(GuiDirecotryMaxSize)); - EditorGUILayout.LabelField("PackRule", GUILayout.MinWidth(GuiPackRuleSize), GUILayout.MaxWidth(GuiPackRuleSize)); - EditorGUILayout.LabelField("FilterRule", GUILayout.MinWidth(GuiFilterRuleSize), GUILayout.MaxWidth(GuiFilterRuleSize)); - EditorGUILayout.LabelField("DontWriteAssetPath", GUILayout.MinWidth(GuiDontWriteAssetPathSize), GUILayout.MaxWidth(GuiDontWriteAssetPathSize)); - EditorGUILayout.LabelField("AssetTags", GUILayout.MinWidth(GuiAssetTagsMinSize), GUILayout.MaxWidth(GuiAssetTagsMaxSize)); - EditorGUILayout.LabelField("", GUILayout.MinWidth(GuiBtnSize), GUILayout.MaxWidth(GuiBtnSize)); - EditorGUILayout.EndHorizontal(); - } - private void OnDrawCollector() - { - // 列表显示 - EditorGUILayout.Space(); - _scrollPos = EditorGUILayout.BeginScrollView(_scrollPos); - for (int i = 0; i < AssetBundleCollectorSettingData.Setting.Collectors.Count; i++) - { - var collector = AssetBundleCollectorSettingData.Setting.Collectors[i]; - string directory = collector.CollectDirectory; - string packRuleName = collector.PackRuleName; - string filterRuleName = collector.FilterRuleName; - bool dontWriteAssetPath = collector.DontWriteAssetPath; - string assetTags = collector.AssetTags; - - EditorGUILayout.BeginHorizontal(); - { - // Directory - EditorGUILayout.LabelField(directory, GUILayout.MinWidth(GuiDirecotryMinSize), GUILayout.MaxWidth(GuiDirecotryMaxSize)); - - // IPackRule - { - int index = PackRuleNameToIndex(packRuleName); - int newIndex = EditorGUILayout.Popup(index, _packRuleArray, GUILayout.MinWidth(GuiPackRuleSize), GUILayout.MaxWidth(GuiPackRuleSize)); - if (newIndex != index) - { - packRuleName = IndexToPackRuleName(newIndex); - AssetBundleCollectorSettingData.ModifyCollector(directory, packRuleName, filterRuleName, dontWriteAssetPath, assetTags); - } - } - - // IFilterRule - { - int index = FilterRuleNameToIndex(filterRuleName); - int newIndex = EditorGUILayout.Popup(index, _filterRuleArray, GUILayout.MinWidth(GuiFilterRuleSize), GUILayout.MaxWidth(GuiFilterRuleSize)); - if (newIndex != index) - { - filterRuleName = IndexToFilterRuleName(newIndex); - AssetBundleCollectorSettingData.ModifyCollector(directory, packRuleName, filterRuleName, dontWriteAssetPath, assetTags); - } - } - - // DontWriteAssetPath - { - bool newToggleValue = EditorGUILayout.Toggle(dontWriteAssetPath, GUILayout.MinWidth(GuiDontWriteAssetPathSize), GUILayout.MaxWidth(GuiDontWriteAssetPathSize)); - if (newToggleValue != dontWriteAssetPath) - { - dontWriteAssetPath = newToggleValue; - AssetBundleCollectorSettingData.ModifyCollector(directory, packRuleName, filterRuleName, dontWriteAssetPath, assetTags); - } - } - - // AssetTags - { - if (collector.DontWriteAssetPath) - { - EditorGUILayout.LabelField(assetTags, GUILayout.MinWidth(GuiAssetTagsMinSize), GUILayout.MaxWidth(GuiAssetTagsMaxSize)); - } - else - { - string newTextValue = EditorGUILayout.TextField(assetTags, GUILayout.MinWidth(GuiAssetTagsMinSize), GUILayout.MaxWidth(GuiAssetTagsMaxSize)); - if (newTextValue != assetTags) - { - assetTags = newTextValue; - AssetBundleCollectorSettingData.ModifyCollector(directory, packRuleName, filterRuleName, dontWriteAssetPath, assetTags); - } - } - } - - if (GUILayout.Button("-", GUILayout.MinWidth(GuiBtnSize), GUILayout.MaxWidth(GuiBtnSize))) - { - AssetBundleCollectorSettingData.RemoveCollector(directory); - break; - } - } - EditorGUILayout.EndHorizontal(); - } - EditorGUILayout.EndScrollView(); - - // 添加按钮 - if (GUILayout.Button("+")) - { - string resultPath = EditorTools.OpenFolderPanel("Select Folder", _lastOpenFolderPath); - if (resultPath != null) - { - _lastOpenFolderPath = EditorTools.AbsolutePathToAssetPath(resultPath); - string defaultPackRuleName = nameof(PackExplicit); - string defaultFilterRuleName = nameof(CollectAll); - bool defaultDontWriteAssetPathValue = false; - string defaultAssetTag = string.Empty; - AssetBundleCollectorSettingData.AddCollector(_lastOpenFolderPath, defaultPackRuleName, defaultFilterRuleName, defaultDontWriteAssetPathValue, defaultAssetTag); - } - } - - // 导入配置按钮 - if (GUILayout.Button("Import Config")) - { - string resultPath = EditorTools.OpenFilePath("Select File", "Assets/", "xml"); - if (resultPath != null) - { - CollectorConfigImporter.ImportXmlConfig(resultPath); - } - } - } - } -} \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs.meta b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs.meta deleted file mode 100644 index 78d3ed7..0000000 --- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: cfca8094e2a905a4da05586b2d7fa919 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/CollectAssetInfo.cs b/Assets/YooAsset/Editor/AssetBundleCollector/CollectAssetInfo.cs deleted file mode 100644 index 2d2734e..0000000 --- a/Assets/YooAsset/Editor/AssetBundleCollector/CollectAssetInfo.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.Collections; -using System.Collections.Generic; - -namespace YooAsset.Editor -{ - public class CollectAssetInfo - { - /// - /// 资源路径 - /// - public string AssetPath { private set; get; } - - /// - /// 资源标记列表 - /// - public List AssetTags { private set; get; } - - /// - /// 是否为原生资源 - /// - public bool IsRawAsset { private set; get; } - - public CollectAssetInfo(string assetPath, List assetTags, bool isRawAsset) - { - AssetPath = assetPath; - AssetTags = assetTags; - IsRawAsset = isRawAsset; - } - } -} \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/CollectAssetInfo.cs.meta b/Assets/YooAsset/Editor/AssetBundleCollector/CollectAssetInfo.cs.meta deleted file mode 100644 index 4e3c4c6..0000000 --- a/Assets/YooAsset/Editor/AssetBundleCollector/CollectAssetInfo.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: b44b2cc585bc59c4d879d1edac67f7c4 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/CollectorConfigImporter.cs b/Assets/YooAsset/Editor/AssetBundleCollector/CollectorConfigImporter.cs deleted file mode 100644 index 8c50764..0000000 --- a/Assets/YooAsset/Editor/AssetBundleCollector/CollectorConfigImporter.cs +++ /dev/null @@ -1,99 +0,0 @@ -using System; -using System.IO; -using System.Xml; -using System.Collections.Generic; -using UnityEditor; -using UnityEngine; - -namespace YooAsset.Editor -{ - public static class CollectorConfigImporter - { - private class CollectWrapper - { - public string CollectDirectory; - public string PackRuleName; - public string FilterRuleName; - public bool DontWriteAssetPath; - public string AssetTags; - - public CollectWrapper(string directory, string packRuleName, string filterRuleName, bool dontWriteAssetPath, string assetTags) - { - CollectDirectory = directory; - PackRuleName = packRuleName; - FilterRuleName = filterRuleName; - DontWriteAssetPath = dontWriteAssetPath; - AssetTags = assetTags; - } - } - - public const string XmlCollector = "Collector"; - public const string XmlDirectory = "Directory"; - public const string XmlPackRule = "PackRule"; - public const string XmlFilterRule = "FilterRule"; - public const string XmlDontWriteAssetPath = "DontWriteAssetPath"; - public const string XmlAssetTags = "AssetTags"; - - public static void ImportXmlConfig(string filePath) - { - if (File.Exists(filePath) == false) - throw new FileNotFoundException(filePath); - - if (Path.GetExtension(filePath) != ".xml") - throw new Exception($"Only support xml : {filePath}"); - - List wrappers = new List(); - - // 加载文件 - XmlDocument xml = new XmlDocument(); - xml.Load(filePath); - - // 解析文件 - XmlElement root = xml.DocumentElement; - XmlNodeList nodeList = root.GetElementsByTagName(XmlCollector); - if (nodeList.Count == 0) - throw new Exception($"Not found any {XmlCollector}"); - foreach (XmlNode node in nodeList) - { - XmlElement collect = node as XmlElement; - string directory = collect.GetAttribute(XmlDirectory); - string packRuleName = collect.GetAttribute(XmlPackRule); - string filterRuleName = collect.GetAttribute(XmlFilterRule); - string dontWriteAssetPath = collect.GetAttribute(XmlDontWriteAssetPath); - string assetTags = collect.GetAttribute(XmlAssetTags); - - if (Directory.Exists(directory) == false) - throw new Exception($"Not found directory : {directory}"); - - if (collect.HasAttribute(XmlPackRule) == false) - throw new Exception($"Not found attribute {XmlPackRule} in collector : {directory}"); - if (collect.HasAttribute(XmlFilterRule) == false) - throw new Exception($"Not found attribute {XmlFilterRule} in collector : {directory}"); - if (collect.HasAttribute(XmlDontWriteAssetPath) == false) - throw new Exception($"Not found attribute {XmlDontWriteAssetPath} in collector : {directory}"); - if (collect.HasAttribute(XmlAssetTags) == false) - throw new Exception($"Not found attribute {XmlAssetTags} in collector : {directory}"); - - if (AssetBundleCollectorSettingData.HasPackRuleName(packRuleName) == false) - throw new Exception($"Invalid {nameof(IPackRule)} class type : {packRuleName}"); - if (AssetBundleCollectorSettingData.HasFilterRuleName(filterRuleName) == false) - throw new Exception($"Invalid {nameof(IFilterRule)} class type : {filterRuleName}"); - - bool dontWriteAssetPathValue = StringUtility.StringToBool(dontWriteAssetPath); - CollectWrapper collectWrapper = new CollectWrapper(directory, packRuleName, filterRuleName, dontWriteAssetPathValue, assetTags); - wrappers.Add(collectWrapper); - } - - // 导入配置数据 - AssetBundleCollectorSettingData.ClearAllCollector(); - foreach (var wrapper in wrappers) - { - AssetBundleCollectorSettingData.AddCollector(wrapper.CollectDirectory, wrapper.PackRuleName, wrapper.FilterRuleName, wrapper.DontWriteAssetPath, wrapper.AssetTags, false); - } - - // 保存配置数据 - AssetBundleCollectorSettingData.SaveFile(); - Debug.Log($"导入配置完毕,一共导入{wrappers.Count}个收集器。"); - } - } -} \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/CollectorConfigImporter.cs.meta b/Assets/YooAsset/Editor/AssetBundleCollector/CollectorConfigImporter.cs.meta deleted file mode 100644 index 241f964..0000000 --- a/Assets/YooAsset/Editor/AssetBundleCollector/CollectorConfigImporter.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: c35b6554a4bedd049a8868d9249846d7 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/DefaultFilterRule.cs b/Assets/YooAsset/Editor/AssetBundleCollector/DefaultFilterRule.cs deleted file mode 100644 index 95adedb..0000000 --- a/Assets/YooAsset/Editor/AssetBundleCollector/DefaultFilterRule.cs +++ /dev/null @@ -1,53 +0,0 @@ -using UnityEngine; -using UnityEditor; -using System.IO; - -namespace YooAsset.Editor -{ - /// - /// 收集所有资源 - /// - public class CollectAll : IFilterRule - { - public bool IsCollectAsset(string assetPath) - { - return true; - } - } - - /// - /// 只收集场景 - /// - public class CollectScene : IFilterRule - { - public bool IsCollectAsset(string assetPath) - { - return Path.GetExtension(assetPath) == ".unity"; - } - } - - /// - /// 只收集预制体 - /// - public class CollectPrefab : IFilterRule - { - public bool IsCollectAsset(string assetPath) - { - return Path.GetExtension(assetPath) == ".prefab"; - } - } - - /// - /// 只收集精灵类型的资源 - /// - public class CollectSprite : IFilterRule - { - public bool IsCollectAsset(string assetPath) - { - if (AssetDatabase.GetMainAssetTypeAtPath(assetPath) == typeof(Sprite)) - return true; - else - return false; - } - } -} \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/DefaultFilterRule.cs.meta b/Assets/YooAsset/Editor/AssetBundleCollector/DefaultFilterRule.cs.meta deleted file mode 100644 index df88655..0000000 --- a/Assets/YooAsset/Editor/AssetBundleCollector/DefaultFilterRule.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: a74c81d149472fb4c960a1db1fd8accc -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/DefaultPackRule.cs b/Assets/YooAsset/Editor/AssetBundleCollector/DefaultPackRule.cs deleted file mode 100644 index 28c1cbb..0000000 --- a/Assets/YooAsset/Editor/AssetBundleCollector/DefaultPackRule.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System; -using System.IO; -using UnityEditor; - -namespace YooAsset.Editor -{ - /// - /// 以文件路径作为AssetBundle标签名 - /// - public class PackExplicit : IPackRule - { - string IPackRule.GetAssetBundleLabel(string assetPath) - { - return StringUtility.RemoveExtension(assetPath); //"Assets/Config/test.txt" --> "Assets/Config/test" - } - } - - /// - /// 以父文件夹路径作为AssetBundle标签名 - /// 注意:该文件夹下所有资源被打到一个AssetBundle文件里 - /// - public class PackDirectory : IPackRule - { - string IPackRule.GetAssetBundleLabel(string assetPath) - { - return Path.GetDirectoryName(assetPath); //"Assets/Config/test.txt" --> "Assets/Config" - } - } - - /// - /// 原生文件打包模式 - /// 注意:原生文件打包支持:图片,音频,视频,文本 - /// - public class PackRawFile : IPackRule - { - string IPackRule.GetAssetBundleLabel(string assetPath) - { - string extension = StringUtility.RemoveFirstChar(Path.GetExtension(assetPath)); - if (extension == EAssetFileExtension.unity.ToString() || extension == EAssetFileExtension.prefab.ToString() || - extension == EAssetFileExtension.mat.ToString() || extension == EAssetFileExtension.controller.ToString() || - extension == EAssetFileExtension.fbx.ToString() || extension == EAssetFileExtension.anim.ToString() || - extension == EAssetFileExtension.shader.ToString()) - { - throw new Exception($"{nameof(PackRawFile)} is not support file estension : {extension}"); - } - - // 注意:原生文件只支持无依赖关系的资源 - string[] depends = AssetDatabase.GetDependencies(assetPath, true); - if (depends.Length != 1) - throw new Exception($"{nameof(PackRawFile)} is not support estension : {extension}"); - - return StringUtility.RemoveExtension(assetPath); - } - } -} \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/DefaultPackRule.cs.meta b/Assets/YooAsset/Editor/AssetBundleCollector/DefaultPackRule.cs.meta deleted file mode 100644 index 13b1c8c..0000000 --- a/Assets/YooAsset/Editor/AssetBundleCollector/DefaultPackRule.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 4a924dc0a22fc104781bf9aaadd60c29 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/IFilterRule.cs b/Assets/YooAsset/Editor/AssetBundleCollector/IFilterRule.cs deleted file mode 100644 index 80b5972..0000000 --- a/Assets/YooAsset/Editor/AssetBundleCollector/IFilterRule.cs +++ /dev/null @@ -1,16 +0,0 @@ - -namespace YooAsset.Editor -{ - /// - /// 资源过滤规则接口 - /// - public interface IFilterRule - { - /// - /// 是否为收集资源 - /// - /// 资源路径 - /// 如果收集该资源返回TRUE - bool IsCollectAsset(string assetPath); - } -} \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/IFilterRule.cs.meta b/Assets/YooAsset/Editor/AssetBundleCollector/IFilterRule.cs.meta deleted file mode 100644 index 470ca48..0000000 --- a/Assets/YooAsset/Editor/AssetBundleCollector/IFilterRule.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: ffe1385deb0bd9844a514f1c2fd65e62 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/IPackRule.cs b/Assets/YooAsset/Editor/AssetBundleCollector/IPackRule.cs deleted file mode 100644 index e48376e..0000000 --- a/Assets/YooAsset/Editor/AssetBundleCollector/IPackRule.cs +++ /dev/null @@ -1,14 +0,0 @@ - -namespace YooAsset.Editor -{ - /// - /// 资源打包规则接口 - /// - public interface IPackRule - { - /// - /// 获取资源的打包标签 - /// - string GetAssetBundleLabel(string assetPath); - } -} \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/IPackRule.cs.meta b/Assets/YooAsset/Editor/AssetBundleCollector/IPackRule.cs.meta deleted file mode 100644 index 8094b86..0000000 --- a/Assets/YooAsset/Editor/AssetBundleCollector/IPackRule.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 577f7c1abcdf0a140958f1d1d44d6f40 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: