public static void ModifyCollector(AssetBundleCollectorGroup group, AssetBundleCollector collector) { if (group != null && collector != null) { IsDirty = true; } }
public static void ModifyGroup(AssetBundleCollectorGroup group) { if (group != null) { IsDirty = true; } }
// 资源收集器编辑相关 public static void CreateCollector(AssetBundleCollectorGroup group, string collectPath) { AssetBundleCollector collector = new AssetBundleCollector(); collector.CollectPath = collectPath; group.Collectors.Add(collector); IsDirty = true; }
private List <string> GetAssetTags(AssetBundleCollectorGroup group) { List <string> tags = StringUtility.StringToStringList(group.AssetTags, ';'); List <string> temper = StringUtility.StringToStringList(AssetTags, ';'); tags.AddRange(temper); return(tags); }
// 资源分组编辑相关 public static void CreateGroup(string groupName) { AssetBundleCollectorGroup group = new AssetBundleCollectorGroup(); group.GroupName = groupName; Setting.Groups.Add(group); IsDirty = true; }
private CollectAssetInfo CreateCollectAssetInfo(AssetBundleCollectorGroup group, string assetPath, bool isRawAsset) { string address = GetAddress(group, assetPath); string bundleName = GetBundleName(group, assetPath); List <string> assetTags = GetAssetTags(group); CollectAssetInfo collectAssetInfo = new CollectAssetInfo(CollectorType, bundleName, address, assetPath, assetTags, isRawAsset); collectAssetInfo.DependAssets = GetAllDependencies(assetPath); return(collectAssetInfo); }
public static void RemoveCollector(AssetBundleCollectorGroup group, AssetBundleCollector collector) { if (group.Collectors.Remove(collector)) { IsDirty = true; } else { Debug.LogWarning($"Failed remove collector : {collector.CollectPath}"); } }
public static void RemoveGroup(AssetBundleCollectorGroup group) { if (Setting.Groups.Remove(group)) { IsDirty = true; } else { Debug.LogWarning($"Failed remove group : {group.GroupName}"); } }
private string GetAddress(AssetBundleCollectorGroup group, string assetPath) { if (CollectorType != ECollectorType.MainAssetCollector) { return(string.Empty); } IAddressRule addressRuleInstance = AssetBundleCollectorSettingData.GetAddressRuleInstance(AddressRuleName); string adressValue = addressRuleInstance.GetAssetAddress(new AddressRuleData(assetPath, CollectPath, group.GroupName)); return(adressValue); }
private void RefreshFoldout(Foldout foldout, AssetBundleCollectorGroup group, AssetBundleCollector collector) { // 清空旧元素 foldout.Clear(); if (collector.IsValid() == false) { Debug.LogWarning($"The collector is invalid : {collector.CollectPath} in group : {group.GroupName}"); return; } if (collector.CollectorType == ECollectorType.MainAssetCollector || collector.CollectorType == ECollectorType.StaticAssetCollector) { List <CollectAssetInfo> collectAssetInfos = null; try { collectAssetInfos = collector.GetAllCollectAssets(group); } catch (System.Exception e) { Debug.LogError(e.ToString()); } if (collectAssetInfos != null) { foreach (var collectAssetInfo in collectAssetInfos) { VisualElement elementRow = new VisualElement(); elementRow.style.flexDirection = FlexDirection.Row; foldout.Add(elementRow); string showInfo = collectAssetInfo.AssetPath; if (_enableAddressableToogle.value) { IAddressRule instance = AssetBundleCollectorSettingData.GetAddressRuleInstance(collector.AddressRuleName); AddressRuleData ruleData = new AddressRuleData(collectAssetInfo.AssetPath, collector.CollectPath, group.GroupName); string addressValue = instance.GetAssetAddress(ruleData); showInfo = $"[{addressValue}] {showInfo}"; } var label = new Label(); label.text = showInfo; label.style.width = 300; label.style.marginLeft = 0; label.style.flexGrow = 1; elementRow.Add(label); } } } }
private string GetBundleName(AssetBundleCollectorGroup group, string assetPath) { // 如果自动收集所有的着色器 if (AssetBundleCollectorSettingData.Setting.AutoCollectShaders) { System.Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath); if (assetType == typeof(UnityEngine.Shader)) { string bundleName = AssetBundleCollectorSettingData.Setting.ShadersBundleName; return(EditorTools.GetRegularPath(bundleName).ToLower()); } } // 根据规则设置获取资源包名称 { IPackRule packRuleInstance = AssetBundleCollectorSettingData.GetPackRuleInstance(PackRuleName); string bundleName = packRuleInstance.GetBundleName(new PackRuleData(assetPath, CollectPath, group.GroupName)); return(EditorTools.GetRegularPath(bundleName).ToLower()); } }
/// <summary> /// 导入XML配置表 /// </summary> 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}"); } // 加载配置文件 XmlDocument xml = new XmlDocument(); xml.Load(filePath); XmlElement root = xml.DocumentElement; // 读取配置版本 string configVersion = root.GetAttribute(XmlVersion); if (configVersion != ConfigVersion) { throw new Exception($"The config version is invalid : {configVersion}"); } // 读取公共配置 bool enableAddressable = false; bool autoCollectShaders = false; string shaderBundleName = string.Empty; var commonNodeList = root.GetElementsByTagName(XmlCommon); if (commonNodeList.Count > 0) { XmlElement commonElement = commonNodeList[0] as XmlElement; if (commonElement.HasAttribute(XmlEnableAddressable) == false) { throw new Exception($"Not found attribute {XmlEnableAddressable} in {XmlCommon}"); } if (commonElement.HasAttribute(XmlAutoCollectShader) == false) { throw new Exception($"Not found attribute {XmlAutoCollectShader} in {XmlCommon}"); } if (commonElement.HasAttribute(XmlShaderBundleName) == false) { throw new Exception($"Not found attribute {XmlShaderBundleName} in {XmlCommon}"); } enableAddressable = commonElement.GetAttribute(XmlEnableAddressable) == "True" ? true : false; autoCollectShaders = commonElement.GetAttribute(XmlAutoCollectShader) == "True" ? true : false; shaderBundleName = commonElement.GetAttribute(XmlShaderBundleName); } // 读取分组配置 List <AssetBundleCollectorGroup> groupTemper = new List <AssetBundleCollectorGroup>(); var groupNodeList = root.GetElementsByTagName(XmlGroup); foreach (var groupNode in groupNodeList) { XmlElement groupElement = groupNode as XmlElement; if (groupElement.HasAttribute(XmlGroupName) == false) { throw new Exception($"Not found attribute {XmlGroupName} in {XmlGroup}"); } if (groupElement.HasAttribute(XmlGroupDesc) == false) { throw new Exception($"Not found attribute {XmlGroupDesc} in {XmlGroup}"); } if (groupElement.HasAttribute(XmlAssetTags) == false) { throw new Exception($"Not found attribute {XmlAssetTags} in {XmlGroup}"); } AssetBundleCollectorGroup group = new AssetBundleCollectorGroup(); group.GroupName = groupElement.GetAttribute(XmlGroupName); group.GroupDesc = groupElement.GetAttribute(XmlGroupDesc); group.AssetTags = groupElement.GetAttribute(XmlAssetTags); groupTemper.Add(group); // 读取收集器配置 var collectorNodeList = groupElement.GetElementsByTagName(XmlCollector); foreach (var collectorNode in collectorNodeList) { XmlElement collectorElement = collectorNode as XmlElement; if (collectorElement.HasAttribute(XmlCollectPath) == false) { throw new Exception($"Not found attribute {XmlCollectPath} in {XmlCollector}"); } if (collectorElement.HasAttribute(XmlCollectorType) == false) { throw new Exception($"Not found attribute {XmlCollectorType} in {XmlCollector}"); } if (collectorElement.HasAttribute(XmlAddressRule) == false) { throw new Exception($"Not found attribute {XmlAddressRule} in {XmlCollector}"); } if (collectorElement.HasAttribute(XmlPackRule) == false) { throw new Exception($"Not found attribute {XmlPackRule} in {XmlCollector}"); } if (collectorElement.HasAttribute(XmlFilterRule) == false) { throw new Exception($"Not found attribute {XmlFilterRule} in {XmlCollector}"); } if (collectorElement.HasAttribute(XmlAssetTags) == false) { throw new Exception($"Not found attribute {XmlAssetTags} in {XmlCollector}"); } AssetBundleCollector collector = new AssetBundleCollector(); collector.CollectPath = collectorElement.GetAttribute(XmlCollectPath); collector.CollectorType = StringUtility.NameToEnum <ECollectorType>(collectorElement.GetAttribute(XmlCollectorType)); collector.AddressRuleName = collectorElement.GetAttribute(XmlAddressRule); collector.PackRuleName = collectorElement.GetAttribute(XmlPackRule); collector.FilterRuleName = collectorElement.GetAttribute(XmlFilterRule); collector.AssetTags = collectorElement.GetAttribute(XmlAssetTags);; group.Collectors.Add(collector); } } // 保存配置数据 AssetBundleCollectorSettingData.ClearAll(); AssetBundleCollectorSettingData.Setting.EnableAddressable = enableAddressable; AssetBundleCollectorSettingData.Setting.AutoCollectShaders = autoCollectShaders; AssetBundleCollectorSettingData.Setting.ShadersBundleName = shaderBundleName; AssetBundleCollectorSettingData.Setting.Groups.AddRange(groupTemper); AssetBundleCollectorSettingData.SaveFile(); Debug.Log($"导入配置完毕!"); }
/// <summary> /// 获取打包收集的资源文件 /// </summary> public List <CollectAssetInfo> GetAllCollectAssets(AssetBundleCollectorGroup group) { // 注意:模拟构建模式下只收集主资源 if (AssetBundleCollectorSetting.BuildMode == EBuildMode.SimulateBuild) { if (CollectorType != ECollectorType.MainAssetCollector) { return(new List <CollectAssetInfo>()); } } Dictionary <string, CollectAssetInfo> result = new Dictionary <string, CollectAssetInfo>(1000); bool isRawAsset = PackRuleName == nameof(PackRawFile); // 检测原生资源包的收集器类型 if (isRawAsset && CollectorType != ECollectorType.MainAssetCollector) { throw new Exception($"The raw file must be set to {nameof(ECollectorType)}.{ECollectorType.MainAssetCollector} : {CollectPath}"); } if (string.IsNullOrEmpty(CollectPath)) { throw new Exception($"The collect path is null or empty in group : {group.GroupName}"); } // 收集打包资源 if (AssetDatabase.IsValidFolder(CollectPath)) { string collectDirectory = CollectPath; string[] findAssets = EditorTools.FindAssets(EAssetSearchType.All, collectDirectory); foreach (string assetPath in findAssets) { if (IsValidateAsset(assetPath) && IsCollectAsset(assetPath)) { if (result.ContainsKey(assetPath) == false) { var collectAssetInfo = CreateCollectAssetInfo(group, assetPath, isRawAsset); result.Add(assetPath, collectAssetInfo); } else { throw new Exception($"The collecting asset file is existed : {assetPath} in collector : {CollectPath}"); } } } } else { string assetPath = CollectPath; if (IsValidateAsset(assetPath) && IsCollectAsset(assetPath)) { var collectAssetInfo = CreateCollectAssetInfo(group, assetPath, isRawAsset); result.Add(assetPath, collectAssetInfo); } else { throw new Exception($"The collecting single asset file is invalid : {assetPath} in collector : {CollectPath}"); } } // 检测可寻址地址是否重复 if (AssetBundleCollectorSettingData.Setting.EnableAddressable) { HashSet <string> adressTemper = new HashSet <string>(); foreach (var collectInfoPair in result) { if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector) { string address = collectInfoPair.Value.Address; if (adressTemper.Contains(address) == false) { adressTemper.Add(address); } else { throw new Exception($"The address is existed : {address} in collector : {CollectPath}"); } } } } // 返回列表 return(result.Values.ToList()); }