【m】框架大更新
This commit is contained in:
631
Assets/00.StaryEvoTools/Editor/MarkAdressable/MarkAdressable.cs
Normal file
631
Assets/00.StaryEvoTools/Editor/MarkAdressable/MarkAdressable.cs
Normal file
@@ -0,0 +1,631 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
#if HotUpdate
|
||||
using HybridCLR.Editor;
|
||||
using HybridCLR.Editor.Commands;
|
||||
#endif
|
||||
using UnityEditor;
|
||||
using UnityEditor.U2D;
|
||||
using UnityEngine;
|
||||
using UnityEngine.U2D;
|
||||
using YooAsset.Editor;
|
||||
|
||||
namespace Stary.Evo.Editor
|
||||
{
|
||||
public class MarkAdressable
|
||||
{
|
||||
private static AssetBundleCollectorPackage package;
|
||||
private static string _packageName;
|
||||
|
||||
|
||||
public static string DomainRoot
|
||||
{
|
||||
get { return Application.dataPath + "/Domain"; }
|
||||
}
|
||||
public static string ArtRoot
|
||||
{
|
||||
get { return Application.dataPath + "/Art"; }
|
||||
}
|
||||
|
||||
//[MenuItem("Evo/Hotfix/Addressable")]
|
||||
public static void AddHotfixAddressableDll()
|
||||
{
|
||||
CopyDllHotUpdateAssembly(BuildAssetWindow.GetBuildPackageName(),
|
||||
$"{DomainRoot}/{BuildAssetWindow.GetBuildPackageName()}/AddressableRes");
|
||||
CopyDllStrippedAOTDllOutputRootDir($"{DomainRoot}/{BuildAssetWindow.GetBuildPackageName()}/AddressableRes");
|
||||
|
||||
|
||||
//EditorUtility.DisplayDialog("自动标记", "自动Hotfix成功", "确定");
|
||||
}
|
||||
|
||||
public static void AddHotfixAddressableDllAll(List<OneKeyBuildEntity> oneKeyBUildEntities)
|
||||
{
|
||||
var DomainAll = CreatAssetWindow.GetCreatDomainAll();
|
||||
|
||||
foreach (var oneKeyBUildEntity in oneKeyBUildEntities)
|
||||
{
|
||||
if (oneKeyBUildEntity.isRaw)
|
||||
{
|
||||
CopyDllHotUpdateAssembly(oneKeyBUildEntity.DomainName,
|
||||
$"{DomainRoot}/{oneKeyBUildEntity.DomainName}/AddressableRes");
|
||||
CopyDllStrippedAOTDllOutputRootDir($"{DomainRoot}/{oneKeyBUildEntity.DomainName}/AddressableRes");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//EditorUtility.DisplayDialog("自动标记", "自动Hotfix成功", "确定");
|
||||
}
|
||||
|
||||
private static void CopyDllHotUpdateAssembly(string domain, string target)
|
||||
{
|
||||
#if HotUpdate
|
||||
//读取打包dll位置
|
||||
string hotUpdateDir =
|
||||
$"{SettingsUtil.HybridCLRSettings.hotUpdateDllCompileOutputRootDir}/{EditorUserBuildSettings.activeBuildTarget}";
|
||||
foreach (var dll in SettingsUtil.HybridCLRSettings.hotUpdateAssemblyDefinitions)
|
||||
{
|
||||
if (dll.name.Contains(domain))
|
||||
{
|
||||
string hotfixDllPath = $"{hotUpdateDir}/{dll.name}.dll";
|
||||
string hotfixDllPathTarget =
|
||||
$"{target}/Dll/{EditorUserBuildSettings.activeBuildTarget}/{dll.name}.dll.bytes";
|
||||
string hotfixDllPathPdb = $"{hotUpdateDir}/{dll.name}.pdb";
|
||||
string hotfixDllPathPdbTarget =
|
||||
$"{target}/Dll/{EditorUserBuildSettings.activeBuildTarget}/{dll.name}.pdb.bytes";
|
||||
FileUtility.Copy(hotfixDllPath, hotfixDllPathTarget, true);
|
||||
FileUtility.Copy(hotfixDllPathPdb, hotfixDllPathPdbTarget, true);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var dll in SettingsUtil.HybridCLRSettings.hotUpdateAssemblies)
|
||||
{
|
||||
if (dll.Contains(domain))
|
||||
{
|
||||
string hotfixDllPath = $"{hotUpdateDir}/{dll}.dll";
|
||||
string hotfixDllPathTarget =
|
||||
$"{target}/Dll/{EditorUserBuildSettings.activeBuildTarget}/{dll}.dll.bytes";
|
||||
string hotfixDllPathPdb = $"{hotUpdateDir}/{dll}.pdb";
|
||||
string hotfixDllPathPdbTarget =
|
||||
$"{target}/Dll/{EditorUserBuildSettings.activeBuildTarget}/{dll}.pdb.bytes";
|
||||
FileUtility.Copy(hotfixDllPath, hotfixDllPathTarget, true);
|
||||
FileUtility.Copy(hotfixDllPathPdb, hotfixDllPathPdbTarget, true);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private static void CopyDllStrippedAOTDllOutputRootDir(string target)
|
||||
{
|
||||
#if HotUpdate
|
||||
//读取打包dll位置
|
||||
string hotUpdateDir =
|
||||
$"{SettingsUtil.HybridCLRSettings.strippedAOTDllOutputRootDir}/{EditorUserBuildSettings.activeBuildTarget}";
|
||||
foreach (var dll in SettingsUtil.HybridCLRSettings.patchAOTAssemblies)
|
||||
{
|
||||
string hotfixDllPath = $"{hotUpdateDir}/{dll}";
|
||||
string hotfixDllPathTarget =
|
||||
$"{target}/Dll/{EditorUserBuildSettings.activeBuildTarget}/{dll}.bytes";
|
||||
FileUtility.Copy(hotfixDllPath, hotfixDllPathTarget, true);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void AddMarkAll(List<OneKeyBuildEntity> oneKeyBUildEntities)
|
||||
{
|
||||
foreach (var oneKeyBUildEntity in oneKeyBUildEntities)
|
||||
{
|
||||
if (oneKeyBUildEntity.isRaw)
|
||||
{
|
||||
string configPath =
|
||||
$"Assets/Domain/{oneKeyBUildEntity.DomainName}/AddressableRes/Config/DomainConfig.asset";
|
||||
DomainConfig domainConfig =
|
||||
AssetDatabase.LoadAssetAtPath<DomainConfig>(configPath);
|
||||
_packageName = domainConfig.domain;
|
||||
// //清空主包旧数据
|
||||
AssetBundleCollectorPackage assetBundleCollectorPackage = null;
|
||||
foreach (var package in AssetBundleCollectorSettingData.Setting.Packages)
|
||||
{
|
||||
if (package.PackageName == _packageName)
|
||||
{
|
||||
assetBundleCollectorPackage = package;
|
||||
}
|
||||
}
|
||||
|
||||
if (assetBundleCollectorPackage != null)
|
||||
{
|
||||
YooAsset.Editor.AssetBundleCollectorSettingData.RemovePackage(assetBundleCollectorPackage);
|
||||
}
|
||||
MarkDomain();
|
||||
|
||||
CreateRes(_packageName,
|
||||
$"{DomainRoot}/{oneKeyBUildEntity.DomainName}/AddressableRes",
|
||||
$"{DomainRoot}/{oneKeyBUildEntity.DomainName}/HotUpdate");
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void AddArtMark(Action complete)
|
||||
{
|
||||
_packageName = BuildArtAssetWindow.GetBuildPackageName();
|
||||
AssetBundleCollectorPackage assetBundleCollectorPackage = null;
|
||||
foreach (var package in AssetBundleCollectorSettingData.Setting.Packages)
|
||||
{
|
||||
if (package.PackageName ==_packageName)
|
||||
{
|
||||
assetBundleCollectorPackage = package;
|
||||
}
|
||||
}
|
||||
if (assetBundleCollectorPackage != null)
|
||||
{
|
||||
YooAsset.Editor.AssetBundleCollectorSettingData.RemovePackage(assetBundleCollectorPackage);
|
||||
}
|
||||
MarkArt();
|
||||
CollectSVC(ArtRoot, _packageName,complete);
|
||||
}
|
||||
|
||||
public static void AddDomainMark()
|
||||
{
|
||||
// //清空主包旧数据
|
||||
AssetBundleCollectorPackage assetBundleCollectorPackage = null;
|
||||
//copydll
|
||||
|
||||
AddHotfixAddressableDll();
|
||||
//清空用户旧数据
|
||||
|
||||
foreach (var package in AssetBundleCollectorSettingData.Setting.Packages)
|
||||
{
|
||||
if (package.PackageName == BuildAssetWindow.GetBuildPackageName())
|
||||
{
|
||||
assetBundleCollectorPackage = package;
|
||||
}
|
||||
}
|
||||
|
||||
if (assetBundleCollectorPackage != null)
|
||||
{
|
||||
YooAsset.Editor.AssetBundleCollectorSettingData.RemovePackage(assetBundleCollectorPackage);
|
||||
}
|
||||
|
||||
string configPath =
|
||||
$"Assets/Domain/{BuildAssetWindow.GetBuildPackageName()}/AddressableRes/Config/DomainConfig.asset";
|
||||
DomainConfig domainConfig =
|
||||
AssetDatabase.LoadAssetAtPath<DomainConfig>(configPath);
|
||||
_packageName = domainConfig.domain;
|
||||
MarkDomain();
|
||||
|
||||
|
||||
CreateRes(_packageName,
|
||||
$"{DomainRoot}/{BuildAssetWindow.GetBuildPackageName()}/AddressableRes",
|
||||
$"{DomainRoot}/{BuildAssetWindow.GetBuildPackageName()}/HotUpdate");
|
||||
CollectSVC(DomainRoot,BuildAssetWindow.GetBuildPackageName(),()=>
|
||||
{
|
||||
EditorUtility.DisplayDialog("自动标记", "自动标记成功", "确定");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// [MenuItem("Evo/Hotfix/一键Res")]
|
||||
public static void CreateRes(string domain, string resPath, string outputPath)
|
||||
{
|
||||
ResFileGet.CreateClass("Res", domain, outputPath,
|
||||
(a) => { ResFileGet.CreateContent(a, resPath, "\t"); });
|
||||
}
|
||||
|
||||
#region 自动标记
|
||||
|
||||
public static Dictionary<string, string> addressDic = new Dictionary<string, string>();
|
||||
|
||||
public static Dictionary<string, AssetBundleCollectorGroup> collectorGroupDic =
|
||||
new Dictionary<string, AssetBundleCollectorGroup>();
|
||||
|
||||
public static void MarkArt()
|
||||
{
|
||||
addressDic.Clear();
|
||||
collectorGroupDic.Clear();
|
||||
///创建分组
|
||||
string remotedRoot = $"{ArtRoot}/{_packageName}";
|
||||
DirectoryInfo[] dirs = new DirectoryInfo(remotedRoot).GetDirectories();
|
||||
|
||||
var setting = YooAsset.Editor.AssetBundleCollectorSettingData.Setting;
|
||||
setting.ShowPackageView = true;
|
||||
setting.UniqueBundleName = true;
|
||||
//创建Package文件
|
||||
package = YooAsset.Editor.AssetBundleCollectorSettingData.CreatePackage(_packageName);
|
||||
|
||||
//检测Packages是否存在TestPackage
|
||||
package.PackageName = _packageName;
|
||||
package.EnableAddressable = true;
|
||||
package.IncludeAssetGUID = true;
|
||||
package.AutoCollectShaders = true;
|
||||
package.IgnoreRuleName = "NormalIgnoreRule";
|
||||
|
||||
//检测Packages是否存在Group
|
||||
foreach (var info in dirs)
|
||||
{
|
||||
string groupName = info.Name;
|
||||
|
||||
if (info.Name == "Scenes"||info.Name == "Config")
|
||||
{
|
||||
AssetBundleCollectorGroup collectorGroup =
|
||||
YooAsset.Editor.AssetBundleCollectorSettingData.CreateGroup(package, groupName);
|
||||
collectorGroup.AssetTags = groupName;
|
||||
if (!collectorGroupDic.ContainsKey(groupName))
|
||||
{
|
||||
collectorGroupDic.Add(groupName, collectorGroup);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("分组 : " + groupName + "已存在,请检查资源目录,避免重复");
|
||||
}
|
||||
AutoMarkRootAddress(info);
|
||||
}
|
||||
}
|
||||
// AssetDatabase.SaveAssets();
|
||||
// AssetDatabase.Refresh();
|
||||
MarkStatus();
|
||||
YooAsset.Editor.AssetBundleCollectorSettingData.SaveFile();
|
||||
|
||||
// CreateRes();
|
||||
|
||||
|
||||
Debug.Log("MarkAsset Successful");
|
||||
}
|
||||
|
||||
public static void MarkDomain()
|
||||
{
|
||||
addressDic.Clear();
|
||||
collectorGroupDic.Clear();
|
||||
|
||||
///创建分组
|
||||
string remotedRoot = $"{DomainRoot}/{_packageName}/AddressableRes";
|
||||
DirectoryInfo[] dirs = new DirectoryInfo(remotedRoot).GetDirectories();
|
||||
|
||||
var setting = YooAsset.Editor.AssetBundleCollectorSettingData.Setting;
|
||||
setting.ShowPackageView = true;
|
||||
setting.UniqueBundleName = true;
|
||||
//创建Package文件
|
||||
package = YooAsset.Editor.AssetBundleCollectorSettingData.CreatePackage(_packageName);
|
||||
|
||||
//检测Packages是否存在TestPackage
|
||||
package.PackageName = _packageName;
|
||||
package.EnableAddressable = true;
|
||||
package.IncludeAssetGUID = true;
|
||||
package.AutoCollectShaders = true;
|
||||
package.IgnoreRuleName = "NormalIgnoreRule";
|
||||
|
||||
|
||||
//检测Packages是否存在Group
|
||||
foreach (var info in dirs)
|
||||
{
|
||||
string groupName = info.Name;
|
||||
|
||||
if (info.Name != "Atlas")
|
||||
{
|
||||
AssetBundleCollectorGroup collectorGroup =
|
||||
YooAsset.Editor.AssetBundleCollectorSettingData.CreateGroup(package, groupName);
|
||||
collectorGroup.AssetTags = groupName;
|
||||
if (!collectorGroupDic.ContainsKey(groupName))
|
||||
{
|
||||
collectorGroupDic.Add(groupName, collectorGroup);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("分组 : " + groupName + "已存在,请检查资源目录,避免重复");
|
||||
}
|
||||
}
|
||||
|
||||
AutoMarkRootAddress(info);
|
||||
// if (info.Name != "SpriteAtlas" && info.Name != "Atlas")
|
||||
// AutoMark(info.Name);
|
||||
}
|
||||
|
||||
|
||||
///自动创建图集
|
||||
Debug.Log("开始创建图集");
|
||||
AutoCreateSpriteAtlas(remotedRoot);
|
||||
// AssetDatabase.SaveAssets();
|
||||
// AssetDatabase.Refresh();
|
||||
MarkStatus();
|
||||
YooAsset.Editor.AssetBundleCollectorSettingData.SaveFile();
|
||||
|
||||
// CreateRes();
|
||||
|
||||
|
||||
Debug.Log("MarkAsset Successful");
|
||||
}
|
||||
|
||||
public static void AutoMarkRootAddress(DirectoryInfo dir)
|
||||
{
|
||||
List<string> fileInfos = new List<string>();
|
||||
FilesUtils.GetFiles(dir.FullName, ref fileInfos);
|
||||
|
||||
//检测用户config下是否存在config文件
|
||||
if (dir.Name == "Config")
|
||||
{
|
||||
List<string> fileNewInfos = new List<string>();
|
||||
foreach (var file in fileInfos)
|
||||
{
|
||||
if (Path.GetExtension(file) != ".meta")
|
||||
{
|
||||
fileNewInfos.Add(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fileInfos != null && fileInfos.Count > 0)
|
||||
{
|
||||
foreach (var file in fileInfos)
|
||||
{
|
||||
if (Path.GetExtension(file) != ".meta" && Path.GetExtension(file) != ".spriteatlas")
|
||||
{
|
||||
// string[] dirSplit = file.Split(new string[] { $"AddressableRes\\{dir.Name}\\" },
|
||||
// StringSplitOptions.RemoveEmptyEntries);
|
||||
// string address = (dirSplit[dirSplit.Length - 1]).Replace("\\", "/");
|
||||
// Debug.Log("address:" + address);
|
||||
string groupName = dir.Name;
|
||||
string assetPath = FilesUtils.AbsoluteToRelativePath("Assets", file); //Asset到文件的路径
|
||||
var guid = AssetDatabase.AssetPathToGUID(assetPath);
|
||||
var group = collectorGroupDic[groupName];
|
||||
if (group != null)
|
||||
{
|
||||
AssetBundleCollector collector = new AssetBundleCollector()
|
||||
{
|
||||
CollectPath = assetPath,
|
||||
CollectorGUID = guid,
|
||||
CollectorType = ECollectorType.MainAssetCollector,
|
||||
AddressRuleName = nameof(AddressByFolderAndFileName),
|
||||
AssetTags = groupName,
|
||||
};
|
||||
|
||||
//TODO 暂时不设置
|
||||
// 如果是video目录,设置
|
||||
// if (groupName == "Video")
|
||||
// {
|
||||
// collector.PackRuleName = nameof(PackVideoFile);
|
||||
// }
|
||||
|
||||
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(group, collector);
|
||||
Debug.Log("GetAssetAddress:" + GetAssetAddress(file));
|
||||
AddAddressInfo(file, GetAssetAddress(file));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("分组 = " + groupName + "不存在");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region 图集
|
||||
|
||||
public static void AutoCreateSpriteAtlas(string domainRootRes)
|
||||
{
|
||||
string AtlasRemotedRoot = domainRootRes + "/SpriteAtlas";
|
||||
string SpriteRemotedAtlas = domainRootRes + "/Sprites";
|
||||
DirectoryInfo[] remotedirs = new DirectoryInfo(SpriteRemotedAtlas).GetDirectories();
|
||||
foreach (var info in remotedirs)
|
||||
{
|
||||
AddSpriteAtlas(SpriteRemotedAtlas + "/" + info.Name, SpriteRemotedAtlas,
|
||||
AtlasRemotedRoot, info);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 自动创建图集
|
||||
/// </summary>
|
||||
/// <param name="path">路径</param>
|
||||
/// <param name="dir">文件夹</param>
|
||||
private static void AddSpriteAtlas(string path, string atlasRoot, string spriteAtlas, DirectoryInfo dir)
|
||||
{
|
||||
var groupname = "SpriteAtlas";
|
||||
var dirs = dir.GetDirectories();
|
||||
if (dirs == null || dirs.Length == 0)
|
||||
{
|
||||
string name = path.Replace(atlasRoot + "/", string.Empty).Replace("/", "_");
|
||||
string filePath = $"{spriteAtlas}/{name}.spriteatlas";
|
||||
// string[] dirSplit =
|
||||
// filePath.Split(new string[] { $"AddressableRes/{Path.GetFileName(spriteAtlas)}" },
|
||||
// StringSplitOptions.RemoveEmptyEntries);
|
||||
// string address = (dirSplit[dirSplit.Length - 1]).Substring(1).Replace("\\", "/");
|
||||
// Debug.Log("spriteatlasaddress:" + address);
|
||||
int assetIndex = filePath.IndexOf("Assets");
|
||||
string guidPath = filePath.Remove(0, assetIndex);
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
SpriteAtlas atlas = new SpriteAtlas();
|
||||
//设置打包参数
|
||||
SpriteAtlasPackingSettings packSetting = new SpriteAtlasPackingSettings()
|
||||
{
|
||||
blockOffset = 1,
|
||||
enableRotation = true,
|
||||
enableTightPacking = false,
|
||||
padding = 2,
|
||||
};
|
||||
atlas.SetPackingSettings(packSetting);
|
||||
|
||||
//设置打包后Texture图集信息
|
||||
SpriteAtlasTextureSettings textureSettings = new SpriteAtlasTextureSettings()
|
||||
{
|
||||
readable = false,
|
||||
generateMipMaps = false,
|
||||
sRGB = true,
|
||||
filterMode = FilterMode.Bilinear,
|
||||
};
|
||||
atlas.SetTextureSettings(textureSettings);
|
||||
|
||||
//设置平台图集大小压缩等信息
|
||||
TextureImporterPlatformSettings platformSettings = new TextureImporterPlatformSettings()
|
||||
{
|
||||
maxTextureSize = 4096,
|
||||
format = TextureImporterFormat.Automatic,
|
||||
crunchedCompression = true,
|
||||
textureCompression = TextureImporterCompression.Compressed,
|
||||
compressionQuality = 50,
|
||||
};
|
||||
atlas.SetPlatformSettings(platformSettings);
|
||||
AssetDatabase.CreateAsset(atlas, guidPath);
|
||||
int pathIndex = path.IndexOf("Assets");
|
||||
string spritePath = path.Remove(0, pathIndex);
|
||||
UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath(spritePath, typeof(UnityEngine.Object));
|
||||
atlas.Add(new[] { obj });
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
var guid = AssetDatabase.AssetPathToGUID(guidPath);
|
||||
|
||||
var group = collectorGroupDic[groupname];
|
||||
if (group != null)
|
||||
{
|
||||
AssetBundleCollector collector = new AssetBundleCollector()
|
||||
{
|
||||
CollectPath = guidPath,
|
||||
CollectorGUID = guid,
|
||||
CollectorType = ECollectorType.MainAssetCollector,
|
||||
AddressRuleName = nameof(AddressByFolderAndFileName),
|
||||
AssetTags = groupname,
|
||||
};
|
||||
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(group, collector);
|
||||
|
||||
|
||||
AddAddressInfo(path, GetAssetAddress(path));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("分组 = " + GetAssetAddress(path) + "不存在");
|
||||
}
|
||||
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dirs.Length > 0)
|
||||
{
|
||||
foreach (var info in dirs)
|
||||
{
|
||||
AddSpriteAtlas(path + "/" + info.Name, atlasRoot, spriteAtlas, info);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private static void AddAddressInfo(string assetPath, string address)
|
||||
{
|
||||
if (addressDic.ContainsKey(assetPath))
|
||||
{
|
||||
Debug.LogError("命名重复,已经存在:" + assetPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
addressDic.Add(assetPath, address);
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetAssetAddress(string assetPath)
|
||||
{
|
||||
string fileName = Path.GetFileNameWithoutExtension(assetPath);
|
||||
FileInfo fileInfo = new FileInfo(assetPath);
|
||||
return $"{fileInfo.Directory.Name}_{fileName}";
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 标记为资源分组
|
||||
/// </summary>
|
||||
private static void MarkStatus()
|
||||
{
|
||||
List<AssetBundleCollectorGroup> deleteList = new List<AssetBundleCollectorGroup>();
|
||||
for (int i = 0; i < package.Groups.Count; i++)
|
||||
{
|
||||
var group = package.Groups[i];
|
||||
if (group.GroupName != "Default Local Group" && group.GroupName != "Built In Data")
|
||||
{
|
||||
if (group.Collectors.Count <= 0)
|
||||
{
|
||||
///删除没有资源的分组
|
||||
deleteList.Add(group);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < deleteList.Count; i++)
|
||||
{
|
||||
package.Groups.Remove(deleteList[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static void CollectSVC(string root,string packageName,Action complete)
|
||||
{
|
||||
string remotedRoot = $"{root}/{packageName}/ShaderVariants";
|
||||
string remotedRootFileName = $"{remotedRoot}/{packageName}.shadervariants";
|
||||
if (!Directory.Exists(remotedRoot))
|
||||
{
|
||||
Directory.CreateDirectory(remotedRoot);
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
string localSavePath = FilesUtils.AbsoluteToRelativePath("Assets", remotedRootFileName); //Asset到文件的路径
|
||||
|
||||
System.Action completedCallback = () =>
|
||||
{
|
||||
ShaderVariantCollection collection =
|
||||
AssetDatabase.LoadAssetAtPath<ShaderVariantCollection>(localSavePath);
|
||||
if (collection != null)
|
||||
{
|
||||
Debug.Log(
|
||||
$"UnityEvo:【{packageName}】ShaderCount : {collection.shaderCount}");
|
||||
Debug.Log(
|
||||
$"UnityEvo:【{packageName}】VariantCount : {collection.variantCount}");
|
||||
|
||||
CreateShaderVariantsGroup(packageName, localSavePath);
|
||||
|
||||
complete?.Invoke();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Failed to Collect shader Variants.");
|
||||
}
|
||||
};
|
||||
ShaderVariantCollector.Run(localSavePath, packageName, 1000, completedCallback);
|
||||
}
|
||||
|
||||
// 新增方法:创建独立的ShaderVariants分组(防止多个package冲突)
|
||||
private static void CreateShaderVariantsGroup(string packageName, string localSavePath)
|
||||
{
|
||||
string groupname = $"ShaderVariants_{packageName}";
|
||||
AssetBundleCollectorGroup collectorGroup = null;
|
||||
|
||||
// 查找或创建package专属分组
|
||||
foreach (var package in AssetBundleCollectorSettingData.Setting.Packages)
|
||||
{
|
||||
if (package.PackageName == packageName)
|
||||
{
|
||||
collectorGroup = YooAsset.Editor.AssetBundleCollectorSettingData.CreateGroup(package, groupname);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var guid = AssetDatabase.AssetPathToGUID(localSavePath);
|
||||
AssetBundleCollector collector = new AssetBundleCollector()
|
||||
{
|
||||
CollectPath = localSavePath,
|
||||
CollectorGUID = guid,
|
||||
CollectorType = ECollectorType.MainAssetCollector,
|
||||
AddressRuleName = nameof(AddressByFolderAndFileName),
|
||||
PackRuleName = nameof(PackShaderVariants),
|
||||
FilterRuleName = nameof(CollectShaderVariants),
|
||||
AssetTags = groupname,
|
||||
};
|
||||
|
||||
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(collectorGroup, collector);
|
||||
YooAsset.Editor.AssetBundleCollectorSettingData.SaveFile();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c4bdee1290d71f34b9346c345de976a3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
132
Assets/00.StaryEvoTools/Editor/MarkAdressable/ResFileGet.cs
Normal file
132
Assets/00.StaryEvoTools/Editor/MarkAdressable/ResFileGet.cs
Normal file
@@ -0,0 +1,132 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Stary.Evo.Editor
|
||||
{
|
||||
public static class ResFileGet
|
||||
{
|
||||
public static void CreateContent(StringBuilder variable, string path, string tab)
|
||||
{
|
||||
tab += "\t\t";
|
||||
DirectoryInfo dir = new DirectoryInfo(path);
|
||||
DirectoryInfo[] first = dir.GetDirectories();
|
||||
FileInfo[] fil = dir.GetFiles();
|
||||
if (first.Length > 0)
|
||||
{
|
||||
foreach (FileInfo f in fil)
|
||||
{
|
||||
CreateFile(variable, f, tab);
|
||||
}
|
||||
|
||||
foreach (DirectoryInfo f in first)
|
||||
{
|
||||
CreateFolder(variable, f, tab);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (FileInfo f in fil)
|
||||
{
|
||||
CreateFile(variable, f, tab);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成脚本文件
|
||||
/// </summary>
|
||||
/// <param name="className">类名</param>
|
||||
/// <param name="content">字符串事件</param>
|
||||
public static void CreateClass(string className, string package, string outputPath,
|
||||
Action<StringBuilder> content = null)
|
||||
{
|
||||
string tdClassName = className;
|
||||
StringBuilder variable = new StringBuilder();
|
||||
//variable.Append("using System;\n");
|
||||
variable.Append("namespace " + "R" + "\n");
|
||||
variable.Append("{\n");
|
||||
variable.Append("\tpublic class " + tdClassName + "\n");
|
||||
variable.Append("\t{\n");
|
||||
variable.Append("\t\tpublic class " + package + "\n");
|
||||
variable.Append("\t\t{\n");
|
||||
content?.Invoke(variable);
|
||||
|
||||
variable.Append("\t\t}\n");
|
||||
variable.Append("\t}\n");
|
||||
variable.Append("}");
|
||||
|
||||
|
||||
outputPath = $"{outputPath}/{tdClassName}.cs";
|
||||
if (File.Exists(outputPath))
|
||||
{
|
||||
File.Delete(outputPath);
|
||||
}
|
||||
FileHelper.WriteFile(outputPath, variable.ToString());
|
||||
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文件夹生成
|
||||
/// </summary>
|
||||
/// <param name="folderName"></param>
|
||||
private static void CreateFolder(StringBuilder variable, DirectoryInfo folderName, string tab)
|
||||
{
|
||||
string classname = FilesUtils.ChineseToPinYin(folderName.Name, false);
|
||||
variable.Append(tab + " public static class " + classname + "\n");
|
||||
variable.Append(tab + "{\n");
|
||||
CreateContent(variable, folderName.FullName, tab);
|
||||
|
||||
variable.Append(tab + "}\n");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文件生成
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
private static void CreateFile(StringBuilder variable, FileInfo fileName, string tab)
|
||||
{
|
||||
var fullname =System.IO.Path.GetExtension(fileName.FullName);
|
||||
if (fullname != ".meta"&&fullname!=".hint" )
|
||||
{
|
||||
Debug.Log("FileInfo:" + fileName.Name);
|
||||
string[] fileSplit = fileName.FullName.Split(new string[] { "AddressableRes\\" },
|
||||
StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] resSplit = fileSplit[fileSplit.Length - 1].Split('\\');
|
||||
// fileSplit = fileName.FullName.Split(new string[] { $"AddressableRes\\{resSplit[0]}\\" },
|
||||
// StringSplitOptions.RemoveEmptyEntries);
|
||||
// string filepath = fileSplit[fileSplit.Length - 1].Replace("\\", "/");
|
||||
// // 删除文件后缀
|
||||
// filepath = Path.Combine(
|
||||
// Path.GetDirectoryName(filepath),
|
||||
// Path.GetFileNameWithoutExtension(filepath)
|
||||
// ).Replace("\\", "/");
|
||||
// Debug.Log(filepath);
|
||||
string filepath;
|
||||
if (MarkAdressable.addressDic.ContainsKey(fileName.FullName))
|
||||
{
|
||||
filepath = MarkAdressable.addressDic[fileName.FullName];
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("未找到地址,请检查资源自动化标记逻辑:" + fileName.FullName);
|
||||
filepath = "";
|
||||
}
|
||||
|
||||
|
||||
string name = FilesUtils.ChineseToPinYin(fileName.Name.Replace(".", "_"), false)
|
||||
.Replace(" ", "")
|
||||
.Replace("-", "_")
|
||||
.Replace(".", "_"); // 保留点号替换为下划线
|
||||
variable.Append(tab + "public const string " + name + " = \"" + filepath + "\";\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 17d52df7853411b46bc8e8ecf271db8a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user