【m】框架优化
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
#if HotUpdate
|
||||
using HybridCLR.Editor;
|
||||
@@ -17,14 +18,22 @@ namespace Stary.Evo.Editor
|
||||
public class MarkAdressable
|
||||
{
|
||||
private static AssetBundleCollectorPackage package;
|
||||
private static string _packageName;
|
||||
private static AssetBundleCollectorPackage packageRawFile;
|
||||
|
||||
|
||||
private static Dictionary<string, string> addressDic = new Dictionary<string, string>();
|
||||
|
||||
private static Dictionary<string, AssetBundleCollectorGroup> _collectorGroupDic =
|
||||
new Dictionary<string, AssetBundleCollectorGroup>();
|
||||
|
||||
private static string _packageName;
|
||||
private static string[] rawFiles = new[] { "Video" };
|
||||
|
||||
public static string DomainRoot
|
||||
{
|
||||
get { return Application.dataPath + "/Domain"; }
|
||||
}
|
||||
|
||||
|
||||
public static void AddHotfixAddressableDll()
|
||||
{
|
||||
CopyDllHotUpdateAssembly(BuildAssetWindow.GetBuildPackageName(),
|
||||
@@ -136,26 +145,9 @@ namespace Stary.Evo.Editor
|
||||
|
||||
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 =
|
||||
@@ -173,6 +165,23 @@ namespace Stary.Evo.Editor
|
||||
});
|
||||
}
|
||||
|
||||
public static void AddRawFileMark()
|
||||
{
|
||||
AssetBundleCollectorPackage assetBundleCollectorPackage = null;
|
||||
var packageRawFile = $"{BuildAssetWindow.GetBuildPackageName()}_RawFile";
|
||||
foreach (var package in AssetBundleCollectorSettingData.Setting.Packages)
|
||||
{
|
||||
if (packageRawFile == BuildAssetWindow.GetBuildPackageName())
|
||||
{
|
||||
assetBundleCollectorPackage = package;
|
||||
}
|
||||
}
|
||||
|
||||
if (assetBundleCollectorPackage != null)
|
||||
{
|
||||
YooAsset.Editor.AssetBundleCollectorSettingData.RemovePackage(assetBundleCollectorPackage);
|
||||
}
|
||||
}
|
||||
|
||||
private static void CreateRes(string domain, string resPath, string outputPath)
|
||||
{
|
||||
@@ -182,11 +191,6 @@ namespace Stary.Evo.Editor
|
||||
|
||||
#region 自动标记
|
||||
|
||||
private static Dictionary<string, string> addressDic = new Dictionary<string, string>();
|
||||
|
||||
private static Dictionary<string, AssetBundleCollectorGroup> _collectorGroupDic =
|
||||
new Dictionary<string, AssetBundleCollectorGroup>();
|
||||
|
||||
public static void Mark()
|
||||
{
|
||||
addressDic.Clear();
|
||||
@@ -196,39 +200,26 @@ namespace Stary.Evo.Editor
|
||||
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";
|
||||
|
||||
|
||||
package = CreatePackage(_packageName);
|
||||
packageRawFile = CreatePackage($"{_packageName}_RawFile");
|
||||
//检测Packages是否存在Group
|
||||
foreach (var info in dirs)
|
||||
{
|
||||
string groupName = info.Name;
|
||||
|
||||
if (info.Name != "Atlas")
|
||||
if (groupName.Equals("Atlas"))
|
||||
{
|
||||
AssetBundleCollectorGroup collectorGroup =
|
||||
YooAsset.Editor.AssetBundleCollectorSettingData.CreateGroup(package, groupName);
|
||||
collectorGroup.AssetTags = groupName;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!_collectorGroupDic.ContainsKey(groupName))
|
||||
{
|
||||
_collectorGroupDic.Add(groupName, collectorGroup);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("分组 : " + groupName + "已存在,请检查资源目录,避免重复");
|
||||
}
|
||||
if (rawFiles.Contains(groupName))
|
||||
{
|
||||
AddGroup(packageRawFile, groupName);
|
||||
}
|
||||
else
|
||||
{
|
||||
AddGroup(package, groupName);
|
||||
}
|
||||
|
||||
AutoMarkRootAddress(info);
|
||||
@@ -240,7 +231,7 @@ namespace Stary.Evo.Editor
|
||||
///自动创建图集
|
||||
Debug.Log("开始创建图集");
|
||||
AutoCreateSpriteAtlas(remotedRoot);
|
||||
MarkStatus();
|
||||
DeleteMarkGroup();
|
||||
YooAsset.Editor.AssetBundleCollectorSettingData.SaveFile();
|
||||
|
||||
// CreateRes();
|
||||
@@ -276,33 +267,35 @@ namespace Stary.Evo.Editor
|
||||
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 + "不存在");
|
||||
}
|
||||
AddCollector(groupName, guid, assetPath, file);
|
||||
// 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 + "不存在");
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -380,27 +373,27 @@ namespace Stary.Evo.Editor
|
||||
}
|
||||
|
||||
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) + "不存在");
|
||||
}
|
||||
AddCollector(groupname, guid, guidPath, path);
|
||||
// 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();
|
||||
}
|
||||
@@ -418,6 +411,86 @@ namespace Stary.Evo.Editor
|
||||
|
||||
#endregion
|
||||
|
||||
private static AssetBundleCollectorPackage CreatePackage(string packageName)
|
||||
{
|
||||
var setting = YooAsset.Editor.AssetBundleCollectorSettingData.Setting;
|
||||
setting.ShowPackageView = true;
|
||||
setting.UniqueBundleName = true;
|
||||
AssetBundleCollectorPackage assetBundleCollectorPackage = null;
|
||||
foreach (var package in AssetBundleCollectorSettingData.Setting.Packages)
|
||||
{
|
||||
if (package.PackageName == packageName)
|
||||
{
|
||||
assetBundleCollectorPackage = package;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (assetBundleCollectorPackage != null)
|
||||
{
|
||||
YooAsset.Editor.AssetBundleCollectorSettingData.RemovePackage(assetBundleCollectorPackage);
|
||||
}
|
||||
|
||||
//创建Package文件
|
||||
assetBundleCollectorPackage = YooAsset.Editor.AssetBundleCollectorSettingData.CreatePackage(packageName);
|
||||
|
||||
//检测Packages是否存在TestPackage
|
||||
assetBundleCollectorPackage.PackageName = packageName;
|
||||
assetBundleCollectorPackage.EnableAddressable = true;
|
||||
assetBundleCollectorPackage.IncludeAssetGUID = true;
|
||||
assetBundleCollectorPackage.AutoCollectShaders = true;
|
||||
assetBundleCollectorPackage.IgnoreRuleName = "NormalIgnoreRule";
|
||||
|
||||
return assetBundleCollectorPackage;
|
||||
}
|
||||
|
||||
private static void AddGroup(AssetBundleCollectorPackage package, string groupName)
|
||||
{
|
||||
AssetBundleCollectorGroup collectorGroup =
|
||||
YooAsset.Editor.AssetBundleCollectorSettingData.CreateGroup(package, groupName);
|
||||
collectorGroup.AssetTags = groupName;
|
||||
|
||||
if (!_collectorGroupDic.ContainsKey(groupName))
|
||||
{
|
||||
_collectorGroupDic.Add(groupName, collectorGroup);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("分组 : " + groupName + "已存在,请检查资源目录,避免重复");
|
||||
}
|
||||
}
|
||||
|
||||
private static void AddCollector(string groupName, string guid, string assetPath, string file)
|
||||
{
|
||||
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 (rawFiles.Contains(groupName))
|
||||
{
|
||||
collector.PackRuleName = nameof(PackVideoFile);
|
||||
}
|
||||
|
||||
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(group, collector);
|
||||
Debug.Log("GetAssetAddress:" + GetAssetAddress(file));
|
||||
AddAddressInfo(file, GetAssetAddress(file));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("分组 = " + groupName + "不存在");
|
||||
}
|
||||
}
|
||||
|
||||
private static void AddAddressInfo(string assetPath, string address)
|
||||
{
|
||||
if (addressDic.ContainsKey(assetPath))
|
||||
@@ -447,22 +520,22 @@ namespace Stary.Evo.Editor
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 标记为资源分组
|
||||
/// 删除资源为空的分组
|
||||
/// </summary>
|
||||
private static void MarkStatus()
|
||||
private static void DeleteMarkGroup()
|
||||
{
|
||||
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.GroupName != "Default Local Group" && group.GroupName != "Built In Data")
|
||||
// {
|
||||
if (group.Collectors.Count <= 0)
|
||||
{
|
||||
if (group.Collectors.Count <= 0)
|
||||
{
|
||||
///删除没有资源的分组
|
||||
deleteList.Add(group);
|
||||
}
|
||||
///删除没有资源的分组
|
||||
deleteList.Add(group);
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
for (int i = 0; i < deleteList.Count; i++)
|
||||
@@ -471,6 +544,8 @@ namespace Stary.Evo.Editor
|
||||
}
|
||||
}
|
||||
|
||||
#region 收集shader变体
|
||||
|
||||
public static void CollectSvc(string root, string packageName, Action complete)
|
||||
{
|
||||
string remotedRoot = $"{root}/{packageName}/ShaderVariants";
|
||||
@@ -505,7 +580,6 @@ namespace Stary.Evo.Editor
|
||||
ShaderVariantCollector.Run(localSavePath, packageName, 1000, CompletedCallback);
|
||||
}
|
||||
|
||||
// 新增方法:创建独立的ShaderVariants分组(防止多个package冲突)
|
||||
private static void CreateShaderVariantsGroup(string packageName, string localSavePath)
|
||||
{
|
||||
string groupname = $"ShaderVariants_{packageName}";
|
||||
@@ -537,5 +611,7 @@ namespace Stary.Evo.Editor
|
||||
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(collectorGroup, collector);
|
||||
YooAsset.Editor.AssetBundleCollectorSettingData.SaveFile();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user