This commit is contained in:
2025-10-24 11:50:03 +08:00
parent cdd5eafa64
commit 655dfcf974
4 changed files with 124 additions and 379 deletions

View File

@@ -11,10 +11,6 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.IO.Compression; using System.IO.Compression;
using System.Threading.Tasks; using System.Threading.Tasks;
#if HotUpdate
using HybridCLR.Editor;
using HybridCLR.Editor.Commands;
#endif
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using Sirenix.OdinInspector; using Sirenix.OdinInspector;
@@ -26,22 +22,21 @@ using YooAsset.Editor;
namespace Stary.Evo.Editor namespace Stary.Evo.Editor
{ {
public class BuildAssetWindow : OdinEditorWindow public class BuildArtAssetWindow : OdinEditorWindow
{ {
public static OdinEditorWindow window; public static OdinEditorWindow window;
private HotfixMainResDomain hotfixMainResDomain; private HotfixMainResDomain hotfixMainResDomain;
[MenuItem("Evo/Art资源打包工具")] [MenuItem("Evo/Art/Art资源打包工具")]
static void ShowWindows() static void ShowWindows()
{ {
if (CreatAssetWindow.GetCreatDomainAll().Count <= 0) if (CreatAssetWindow.GetCreatDomainAll().Count <= 0)
{ {
EditorUtility.DisplayDialog("提示", "不存在Domain元素,无法打开此面板,请先创建Domain元素", "确定"); EditorUtility.DisplayDialog("提示", "不存在Art元素,无法打开此面板,请先创建Art元素", "确定");
return; return;
} }
window = (BuildAssetWindow)EditorWindow.GetWindow(typeof(BuildAssetWindow)); window = (BuildArtAssetWindow)EditorWindow.GetWindow(typeof(BuildArtAssetWindow));
window.Show(); window.Show();
} }
@@ -64,7 +59,7 @@ namespace Stary.Evo.Editor
else else
{ {
ip = hotfixMainResDomain.hotfixMainResDomainEntity.ipconfig; ip = hotfixMainResDomain.hotfixMainResDomainEntity.ipconfig;
EditorPrefs.SetString("ip",ip); EditorPrefs.SetString("ip", ip);
userName = hotfixMainResDomain.hotfixMainResDomainEntity.username; userName = hotfixMainResDomain.hotfixMainResDomainEntity.username;
password = hotfixMainResDomain.hotfixMainResDomainEntity.password; password = hotfixMainResDomain.hotfixMainResDomainEntity.password;
} }
@@ -79,11 +74,20 @@ namespace Stary.Evo.Editor
if (isValidateToken) if (isValidateToken)
{ {
buildAssetType = BuildAssetType.Build; buildAssetType = BuildAssetType.Build;
return; }
else
{
buildAssetType = BuildAssetType.Login;
} }
buildAssetType = BuildAssetType.Login; //初始化打包管线
_buildPipelineViewer = new ScriptableBuildPipelineViewer(packageName,
EBuildPipeline.ScriptableBuildPipeline.ToString(), packageVersion);
_buildPipelineViewer.clearBuildCacheToggle = true;
_buildPipelineViewer.useAssetDependencyDBToggle = false;
_buildPipelineViewer.SetBuildCacheToggle();
_buildPipelineViewer.SetUseAssetDependencyDB();
} }
public static void RemoveBuildAssetWindow() public static void RemoveBuildAssetWindow()
@@ -129,7 +133,7 @@ namespace Stary.Evo.Editor
hotfixMainResDomain.hotfixMainResDomainEntity.ipconfig = ip; hotfixMainResDomain.hotfixMainResDomainEntity.ipconfig = ip;
hotfixMainResDomain.hotfixMainResDomainEntity.username = userName; hotfixMainResDomain.hotfixMainResDomainEntity.username = userName;
hotfixMainResDomain.hotfixMainResDomainEntity.password = password; hotfixMainResDomain.hotfixMainResDomainEntity.password = password;
EditorPrefs.SetString("ip",ip); EditorPrefs.SetString("ip", ip);
EditorUtility.SetDirty(hotfixMainResDomain); EditorUtility.SetDirty(hotfixMainResDomain);
AssetDatabase.SaveAssets(); AssetDatabase.SaveAssets();
} }
@@ -150,8 +154,8 @@ namespace Stary.Evo.Editor
protected void OnSelectionChange() protected void OnSelectionChange()
{ {
EditorUtility.SetDirty(BuildAssetDataSetting); // EditorUtility.SetDirty(BuildAssetDataSetting);
AssetDatabase.SaveAssets(); // AssetDatabase.SaveAssets();
//AssetDatabase.Refresh(); //AssetDatabase.Refresh();
} }
@@ -170,44 +174,25 @@ namespace Stary.Evo.Editor
[HorizontalGroup("Build/BuildPipeline"), HideLabel] [HorizontalGroup("Build/BuildPipeline"), HideLabel]
public string buildTarget; public string buildTarget;
public static string packageName; private static string packageName;
#region HyBridCLRBuild [Title("版本号", titleAlignment: TitleAlignments.Centered)]
[HorizontalGroup("Build/PackageVersion"), HideLabel]
[BoxGroup("Build", showLabel: false)]
[HideIf("@ buildAssetType!= BuildAssetType.Build")]
[Title("打包dll(子包仅打一次)", titleAlignment: TitleAlignments.Centered)]
[HorizontalGroup("Build/HyBridClrBuildEntity"), HideLabel]
public BuildAssetEntity hyBridClrBuildEntity =
new BuildAssetEntity("HyBridCLRBuild", "DllBuildTarget", () =>
{
#if HotUpdate
//PrebuildCommand.GenerateAll();
CompileDllCommand.CompileDllActiveBuildTarget();
#endif
});
#endregion
#region MarkAsset
[BoxGroup("Build", showLabel: false)]
[ShowIf("@ buildAssetType== BuildAssetType.Build")] [ShowIf("@ buildAssetType== BuildAssetType.Build")]
[Title("标记资源", titleAlignment: TitleAlignments.Centered)] [OnValueChanged("OnPackageValueChanged")]
[HorizontalGroup("Build/HyBridClrBuildEntity"), HideLabel] public string packageVersion;
public BuildAssetEntity markAssetEntity =
new BuildAssetEntity("MarkAsset", "MarkAsset", MarkAdressable.AddMark);
private AbstractBuildPipelineViewer _buildPipelineViewer;
#endregion
#region BuildAsset #region BuildAsset
[BoxGroup("Build", showLabel: false)] public void OnPackageValueChanged()
[ShowIf("@ buildAssetType== BuildAssetType.Build")] {
[InlineEditor(InlineEditorObjectFieldModes.CompletelyHidden)] _buildPipelineViewer.SetBuildPackageData(packageName, EBuildPipeline.ScriptableBuildPipeline.ToString(),
[HideLabel] packageVersion);
public BuildAssetDataSetting BuildAssetDataSetting; }
/// <summary> /// <summary>
/// 检测当前所有包裹 /// 检测当前所有包裹
@@ -216,61 +201,20 @@ namespace Stary.Evo.Editor
private List<string> GetBuildPackageNames() private List<string> GetBuildPackageNames()
{ {
List<string> result = new List<string>(); List<string> result = new List<string>();
foreach (var name in CreatAssetWindow.GetCreatDomainAllName()) foreach (var name in CreatArtAssetWindow.GetCreatDomainAllName())
{ {
result.Add(name); result.Add(name);
} }
if (selectedPackageNames.IsNullOrEmpty()) if (selectedPackageNames.IsNullOrEmpty())
{ {
// string buildPackageName = DataSetting.packageName;
// if (result.Exists(p => p == buildPackageName))
// {
// selectedPackageNames = buildPackageName;
// }
// else
// {
selectedPackageNames = result[0]; selectedPackageNames = result[0];
//}
} }
SetBuildPackageNames(); SetBuildPackageNames();
return result; return result;
} }
/// <summary>
/// 设置当前包裹
/// </summary>
/// <returns></returns>
private void SetBuildPackageNames()
{
//PlayerPrefs.SetString("BuildPackageNames", selectedPackageNames);
// DataSetting.packageName = selectedPackageNames;
// DataSetting = Resources.Load<BuildAssetDataSetting>("BuildAssetDataSetting");
string buildAssetDataSettingPath =
$"Assets/Domain/{selectedPackageNames}/Conf/BuildAssetDataSetting.asset";
BuildAssetDataSetting buildAssetDataSetting =
AssetDatabase.LoadAssetAtPath<BuildAssetDataSetting>(buildAssetDataSettingPath);
if (buildAssetDataSetting != null)
{
BuildAssetDataSetting = buildAssetDataSetting;
Init();
}
else
{
Debug.LogError($"UnityEvo:BuildAssetDataSetting 不存在,请检查路径{buildAssetDataSettingPath}");
}
if (selectedPackageNames != packageName)
{
GetHostBuildPackageVersion(buildAssetDataSetting);
}
packageName = selectedPackageNames;
}
/// <summary> /// <summary>
/// 获取当前包裹 /// 获取当前包裹
/// </summary> /// </summary>
@@ -280,6 +224,22 @@ namespace Stary.Evo.Editor
return packageName; return packageName;
} }
/// <summary>
/// 设置当前包裹
/// </summary>
/// <returns></returns>
private void SetBuildPackageNames()
{
if (selectedPackageNames != packageName)
{
GetHostBuildPackageVersion();
Init();
}
packageName = selectedPackageNames;
OnPackageValueChanged();
}
#endregion #endregion
#region Update #region Update
@@ -291,10 +251,9 @@ namespace Stary.Evo.Editor
public BuildAssetEntity onBuildPipelineEntity; public BuildAssetEntity onBuildPipelineEntity;
[BoxGroup("Build", showLabel: false)] [BoxGroup("Build", showLabel: false)]
[ShowIf("@ buildAssetType== BuildAssetType.Build")]
[Title("上传资源", titleAlignment: TitleAlignments.Centered)] [Title("上传资源", titleAlignment: TitleAlignments.Centered)]
[HideLabel] [HideLabel]
[ShowIf(
"@ BuildAssetDataSetting.environmentType== EnvironmentType.Release && buildAssetType== BuildAssetType.Build")]
public BuildAssetEntity onUpdateBuildPipelineEntity; public BuildAssetEntity onUpdateBuildPipelineEntity;
@@ -303,7 +262,7 @@ namespace Stary.Evo.Editor
if (EditorUtility.DisplayDialog("提示", $"开始构建资源包[{selectedPackageNames}]", "Yes", "No")) if (EditorUtility.DisplayDialog("提示", $"开始构建资源包[{selectedPackageNames}]", "Yes", "No"))
{ {
EditorTools.ClearUnityConsole(); EditorTools.ClearUnityConsole();
EditorApplication.delayCall += BuildAssetDataSetting.viewer.ExecuteBuild; MarkAdressable.AddArtMark(() => { EditorApplication.delayCall += _buildPipelineViewer.ExecuteBuild; });
} }
else else
{ {
@@ -316,8 +275,8 @@ namespace Stary.Evo.Editor
if (EditorUtility.DisplayDialog("提示", $"开始上传至服务器[{selectedPackageNames}]", "Yes", "No")) if (EditorUtility.DisplayDialog("提示", $"开始上传至服务器[{selectedPackageNames}]", "Yes", "No"))
{ {
// 新增打包为zip的逻辑 // 新增打包为zip的逻辑
string zipFilePath = BuildZip(BuildAssetDataSetting); string zipFilePath = BuildZip();
await UpdateFileDataResDomain(BuildAssetDataSetting, zipFilePath); await UpdateFileDataResDomain(zipFilePath);
await Task.Delay(1000); await Task.Delay(1000);
EditorUtility.ClearProgressBar(); EditorUtility.ClearProgressBar();
} }
@@ -330,21 +289,21 @@ namespace Stary.Evo.Editor
} }
public static string BuildZip(BuildAssetDataSetting setting) public string BuildZip()
{ {
EditorUtility.DisplayProgressBar("提示", $"开始上传{setting.packageName}(打包zip)", 0.0f); EditorUtility.DisplayProgressBar("提示", $"开始上传{packageName}(打包zip)", 0.0f);
// 新增打包为zip的逻辑 // 新增打包为zip的逻辑
string zipFileName = string zipFileName =
$"{setting.packageName}_{setting.packageVersion}.zip"; $"{packageName}_{packageVersion}.zip";
//原yooAsset目录 //原yooAsset目录
var outputPackageDirectory = var outputPackageDirectory =
$"{AssetBundleBuilderHelper.GetDefaultBuildOutputRoot()}/{EditorUserBuildSettings.activeBuildTarget}/{setting.packageName}"; $"{AssetBundleBuilderHelper.GetDefaultBuildOutputRoot()}/{EditorUserBuildSettings.activeBuildTarget}/{packageName}";
//拷贝目录 //拷贝目录
string outFilePath = $"{outputPackageDirectory}/{setting.packageVersion}"; string outFilePath = $"{outputPackageDirectory}/{packageVersion}";
var copyPackageDirectory = var copyPackageDirectory =
$"{Application.streamingAssetsPath}/{YooAssetSettingsData.GetDefaultYooFolderName()}/{setting.packageName}"; $"{Application.streamingAssetsPath}/{YooAssetSettingsData.GetDefaultYooFolderName()}/{packageName}";
//拷贝BuildinCatalog文件 //拷贝BuildinCatalog文件
CreateBuildinCatalogFile("BuildinCatalog.json", copyPackageDirectory, outFilePath); CreateBuildinCatalogFile("BuildinCatalog.json", copyPackageDirectory, outFilePath);
CreateBuildinCatalogFile("BuildinCatalog.bytes", copyPackageDirectory, outFilePath); CreateBuildinCatalogFile("BuildinCatalog.bytes", copyPackageDirectory, outFilePath);
@@ -382,7 +341,7 @@ namespace Stary.Evo.Editor
} }
Debug.Log($"成功打包为zip{zipFilePath}"); Debug.Log($"成功打包为zip{zipFilePath}");
EditorUtility.DisplayProgressBar("提示", $"开始上传{setting.packageName}(打包zip)", 0.25f); EditorUtility.DisplayProgressBar("提示", $"开始上传{packageName}(打包zip)", 0.25f);
return zipFilePath; return zipFilePath;
} }
catch (Exception ex) catch (Exception ex)
@@ -398,7 +357,7 @@ namespace Stary.Evo.Editor
// 假设 BuildinCatalog 文件名为 BuildinCatalog.json // 假设 BuildinCatalog 文件名为 BuildinCatalog.json
string sourcePath = Path.Combine(copyPackageDirectory, fileName); // 源文件路径 string sourcePath = Path.Combine(copyPackageDirectory, fileName); // 源文件路径
string destinationPath = Path.Combine(outFilePath, fileName); // 目标文件路径 string destinationPath = Path.Combine(outFilePath, fileName); // 目标文件路径
// 如果目标文件已存在,则覆盖 // 如果目标文件已存在,则覆盖
if (File.Exists(destinationPath)) if (File.Exists(destinationPath))
@@ -408,10 +367,9 @@ namespace Stary.Evo.Editor
// 执行拷贝操作 // 执行拷贝操作
File.Copy(sourcePath, destinationPath); File.Copy(sourcePath, destinationPath);
} }
public static async Task UpdateFileDataResDomain(BuildAssetDataSetting setting, string zipFilePath) public async Task UpdateFileDataResDomain(string zipFilePath)
{ {
//初始化读取资源配置表 //初始化读取资源配置表
HotfixMainResDomain hotfixMainResDomain = Resources.Load<HotfixMainResDomain>("HotfixMainResDomain"); HotfixMainResDomain hotfixMainResDomain = Resources.Load<HotfixMainResDomain>("HotfixMainResDomain");
@@ -423,7 +381,7 @@ namespace Stary.Evo.Editor
var ip = hotfixMainResDomain.hotfixMainResDomainEntity.ipconfig; var ip = hotfixMainResDomain.hotfixMainResDomainEntity.ipconfig;
var messageEntity = await WebRequestSystem.PostFile(ip + "/FileLoad/UpLoadFile", new[] { zipFilePath }); var messageEntity = await WebRequestSystem.PostFile(ip + "/FileLoad/UpLoadFile", new[] { zipFilePath });
EditorUtility.DisplayProgressBar("提示", $"开始上传{setting.packageName}(上传zip文件)", 0.5f); EditorUtility.DisplayProgressBar("提示", $"开始上传{packageName}(上传zip文件)", 0.5f);
if (messageEntity.code == 200) if (messageEntity.code == 200)
{ {
List<ResultMessageEntity> resultMessageEntities = List<ResultMessageEntity> resultMessageEntities =
@@ -438,9 +396,9 @@ namespace Stary.Evo.Editor
ResDmainAddRequst resDmainAddRequst = new ResDmainAddRequst() ResDmainAddRequst resDmainAddRequst = new ResDmainAddRequst()
{ {
ProductName = Application.identifier, ProductName = Application.identifier,
DomainName = setting.packageName, DomainName = packageName,
Platform = EditorUserBuildSettings.activeBuildTarget.ToString(), Platform = EditorUserBuildSettings.activeBuildTarget.ToString(),
PackageVersion = setting.packageVersion, PackageVersion = packageVersion,
DocumentFileId = fileId DocumentFileId = fileId
}; };
var resResultMessage = await WebRequestSystem.Post(ip + "/ResDomain/AddResDomain", var resResultMessage = await WebRequestSystem.Post(ip + "/ResDomain/AddResDomain",
@@ -451,18 +409,31 @@ namespace Stary.Evo.Editor
ResDmainVersionResponse dmainVersionResponse = ResDmainVersionResponse dmainVersionResponse =
JsonConvert.DeserializeObject<ResDmainVersionResponse>(resResultMessage.data JsonConvert.DeserializeObject<ResDmainVersionResponse>(resResultMessage.data
.ToString()); .ToString());
string[] versions = dmainVersionResponse.PackageVersion.Split('.');
setting.packageVersionX = int.Parse(versions[0]);
setting.packageVersionY = int.Parse(versions[1]);
setting.packageVersionZ = int.Parse(versions[2]);
EditorUtility.DisplayDialog("提示",
$"{resResultMessage.message + $"\n{resResultMessage.data.ToString()}"}", "确定");
}
setting.GetBuildPackageVersion(true);
bool isEndWithDigit =
System.Text.RegularExpressions.Regex.IsMatch(dmainVersionResponse.PackageVersion,
@"\d$");
if (isEndWithDigit)
{
// 提取版本号结尾的数字部分
string versionEndDigits = System.Text.RegularExpressions.Regex
.Match(dmainVersionResponse.PackageVersion, @"(\d+)$").Groups[1].Value;
int versionEndDigit = int.Parse(versionEndDigits) + 1;
// 或者移除版本号结尾的数字
string versionWithoutEndDigits =
System.Text.RegularExpressions.Regex.Replace(dmainVersionResponse.PackageVersion,
@"\d+$", "");
packageVersion = versionWithoutEndDigits + versionEndDigit;
}
EditorUtility.DisplayDialog("提示",
$"{resResultMessage.message + $"\n{resResultMessage.data.ToString()},{packageVersion}"}",
"确定");
}
} }
EditorUtility.DisplayProgressBar("提示", $"开始上传{setting.packageName}(更新数据库)", 1f); EditorUtility.DisplayProgressBar("提示", $"开始上传{packageName}(更新数据库)", 1f);
} }
} }
else else
@@ -478,7 +449,7 @@ namespace Stary.Evo.Editor
/// <summary> /// <summary>
/// 获取服务器上版本号 /// 获取服务器上版本号
/// </summary> /// </summary>
private async void GetHostBuildPackageVersion(BuildAssetDataSetting setting) private async void GetHostBuildPackageVersion()
{ {
var resDmainAddRequst = new ResDmainRequst() var resDmainAddRequst = new ResDmainRequst()
{ {
@@ -496,11 +467,7 @@ namespace Stary.Evo.Editor
ResDmainResponse domainResponse = ResDmainResponse domainResponse =
JsonConvert.DeserializeObject<ResDmainResponse>(resResultMessage.data JsonConvert.DeserializeObject<ResDmainResponse>(resResultMessage.data
.ToString()); .ToString());
string[] versions = domainResponse.PackageVersion.Split('.'); packageVersion = domainResponse.PackageVersion;
setting.packageVersionX = int.Parse(versions[0]);
setting.packageVersionY = int.Parse(versions[1]);
setting.packageVersionZ = int.Parse(versions[2]);
setting.GetBuildPackageVersion(true);
} }
else else
{ {
@@ -510,11 +477,8 @@ namespace Stary.Evo.Editor
else else
{ {
EditorUtility.DisplayDialog("提示", EditorUtility.DisplayDialog("提示",
$"{resResultMessage.message},默认1.0.0版本 ", "确定"); $"{resResultMessage.message},默认test_1.0版本 ", "确定");
setting.packageVersionX = 1; packageVersion = "test_1.0";
setting.packageVersionY = 0;
setting.packageVersionZ = 0;
setting.GetBuildPackageVersion(false);
} }
} }
@@ -525,9 +489,9 @@ namespace Stary.Evo.Editor
//Update //Update
buildTarget = EditorUserBuildSettings.activeBuildTarget.ToString(); buildTarget = EditorUserBuildSettings.activeBuildTarget.ToString();
onBuildPipelineEntity = onBuildPipelineEntity =
new BuildAssetEntity("打包", $"打包资源包【版本:{BuildAssetDataSetting.packageVersion}】", OnBuildPipeline); new BuildAssetEntity("打包", $"打包资源包【版本:{packageVersion}】", OnBuildPipeline);
onUpdateBuildPipelineEntity = onUpdateBuildPipelineEntity =
new BuildAssetEntity("更新", $"更新至服务器【版本:{BuildAssetDataSetting.packageVersion}】", new BuildAssetEntity("更新", $"更新至服务器【版本:{packageVersion}】",
OnUpdateBuildPipeline); OnUpdateBuildPipeline);
} }
@@ -540,41 +504,13 @@ namespace Stary.Evo.Editor
base.DrawEditor(index); base.DrawEditor(index);
} }
GUILayout.EndScrollView(); GUILayout.EndScrollView();
BuildServerPath();
UpdateBuildPipelineButtonName(); UpdateBuildPipelineButtonName();
} }
public void UpdateBuildPipelineButtonName() public void UpdateBuildPipelineButtonName()
{ {
onBuildPipelineEntity.SetButtonName($"打包资源包【版本:{BuildAssetDataSetting.packageVersion}】"); onBuildPipelineEntity.SetButtonName($"打包资源包【版本:{packageVersion}】");
onUpdateBuildPipelineEntity.SetButtonName($"更新至服务器【版本:{BuildAssetDataSetting.packageVersion}】"); onUpdateBuildPipelineEntity.SetButtonName($"更新至服务器【版本:{packageVersion}】");
} }
/// <summary>
/// 生成服务器路径
/// </summary>
private void BuildServerPath()
{
// if (!_isCheckDriveExist)
// {
// return;
// }
//
// updateServerPath =
// $"Z:/{Application.productName}/{BuildAssetDataSetting.packageName}/{EditorUserBuildSettings.activeBuildTarget}/{BuildAssetDataSetting.packageVersion}";
// if (!Directory.Exists(updateServerPath))
// Directory.CreateDirectory(updateServerPath);
//更新Button文字
onBuildPipelineEntity.SetButtonName($"打包资源包【版本:{BuildAssetDataSetting.packageVersion}】");
onUpdateBuildPipelineEntity.SetButtonName($"更新至服务器【版本:{BuildAssetDataSetting.packageVersion}】");
}
}
public enum BuildAssetType
{
Login,
Build,
} }
} }

View File

@@ -14,20 +14,20 @@ using UnityEngine;
namespace Stary.Evo.Editor namespace Stary.Evo.Editor
{ {
public class CreatAssetWindow : OdinEditorWindow public class CreatArtAssetWindow : OdinEditorWindow
{ {
[MenuItem("Evo/创建Domain作用域")] [MenuItem("Evo/Art/创建Art作用域")]
static void Init() static void Init()
{ {
// Get existing open window or if none, make a new one: // Get existing open window or if none, make a new one:
CreatAssetWindow window = (CreatAssetWindow)EditorWindow.GetWindow(typeof(CreatAssetWindow)); CreatArtAssetWindow window = (CreatArtAssetWindow)EditorWindow.GetWindow(typeof(CreatArtAssetWindow));
window.Show(); window.Show();
} }
[TitleGroup("创建Domain作用域")] public string domain; [TitleGroup("创建Art作用域")] public string domain;
[TitleGroup("创建Domain作用域")] [TitleGroup("创建Art作用域")]
[Button("创建Domain", ButtonSizes.Large)] [Button("创建Art", ButtonSizes.Large)]
public async void CreatDomain() public async void CreatDomain()
{ {
// if (GetCreatDomainAll().Count>0) // if (GetCreatDomainAll().Count>0)
@@ -38,7 +38,7 @@ namespace Stary.Evo.Editor
if (string.IsNullOrEmpty(domain)) if (string.IsNullOrEmpty(domain))
{ {
EditorUtility.DisplayDialog("错误!", "请输入将要创建Domain的编号", "确定"); EditorUtility.DisplayDialog("错误!", "请输入将要创建Art的编号", "确定");
return; return;
} }
@@ -63,7 +63,7 @@ namespace Stary.Evo.Editor
//创建Scenes文件夹 //创建Scenes文件夹
CreatDirectory(artDomainPath + "/Scenes"); CreatDirectory(artDomainPath + "/Scenes");
//创建/Scenes/Test文件夹 //创建/Scenes/Test文件夹
CreatDirectory(artDomainPath + "/Scenes/Test"); CreatDirectory(artDomainPath + "/Scenes");
//创建Shader文件夹 //创建Shader文件夹
CreatDirectory(artDomainPath + "/Shader"); CreatDirectory(artDomainPath + "/Shader");
//创建Textures文件夹 //创建Textures文件夹
@@ -71,9 +71,10 @@ namespace Stary.Evo.Editor
File.WriteAllTextAsync( File.WriteAllTextAsync(
$"{artDomainPath}/这里放所有美术的资源,因涉及打包依赖等原因,不建议在上一层节点新增文件夹,如涉及文件夹规范等问题请@张铮.hint", ""); $"{artDomainPath}/这里放所有美术的资源,因涉及打包依赖等原因,不建议在上一层节点新增文件夹,如涉及文件夹规范等问题请@张铮.hint", "");
} }
//创建Art 测试场景 //创建Art 测试场景
/* 2. 再建 Scenes/Test */ /* 2. 再建 Scenes/Test */
string sceneDir = $"{artDomainPath}/Scenes/Test"; string sceneDir = $"{artDomainPath}/Scenes";
if (!Directory.Exists(sceneDir)) if (!Directory.Exists(sceneDir))
{ {
Directory.CreateDirectory(sceneDir); Directory.CreateDirectory(sceneDir);
@@ -97,153 +98,20 @@ namespace Stary.Evo.Editor
spawned.name = "RKCameraRig"; spawned.name = "RKCameraRig";
/* 6. 保存场景 */ /* 6. 保存场景 */
string scenePath = Path.Combine("Assets/Art", name, "Scenes", "Test", "TestScene.unity"); string scenePath = Path.Combine("Assets/Art", domain, "Scenes", "TestScene.unity");
UnityEditor.SceneManagement.EditorSceneManager.SaveScene(newScene, scenePath); UnityEditor.SceneManagement.EditorSceneManager.SaveScene(newScene, scenePath);
} }
string domainPath = $"{Application.dataPath}/Domain/{domain}";
if (Directory.Exists(domainPath + "/AddressableRes/Config/DomainConfig.asset"))
{
EditorUtility.DisplayDialog("错误!", $"\"{domain}\"已经存在,无法创建", "确定");
return;
}
CreatDirectory(domainPath);
//程序资源存放文件夹
string resPath = $"{domainPath}/AddressableRes";
CreatDirectory(resPath);
//创建音频文件夹
CreatDirectory(resPath + "/Audios");
//创建Config文件夹
CreatDirectory(resPath + "/Config");
//创建Dll文件夹
CreatDirectory(resPath + "/Dll");
//创建Prefabs文件夹
CreatDirectory(resPath + "/Prefabs");
//创建Scenes文件夹
CreatDirectory(resPath + "/Scenes");
//创建SpriteAtlas文件夹
CreatDirectory(resPath + "/SpriteAtlas");
//创建Sprites文件夹
CreatDirectory(resPath + "/Sprites");
//创建Video文件夹
CreatDirectory(resPath + "/Video");
File.WriteAllTextAsync($"{resPath}/这里放所有参与热更的资源.hint", "");
//主入口预制件
GameObject gameObj = new GameObject(domain);
gameObj.transform.position = Vector3.zero;
gameObj.transform.rotation = Quaternion.identity;
gameObj.name = domain;
CreatDirectory($"{resPath}/Prefabs");
string rootPfbFilePath = $"Assets/Domain/{domain}/AddressableRes/Prefabs/{domain}.prefab";
var localPath = AssetDatabase.GenerateUniqueAssetPath(rootPfbFilePath);
PrefabUtility.SaveAsPrefabAsset(gameObj, localPath);
//存放脚本文件夹
string scriptsPath = $"{domainPath}/HotUpdate";
CreatDirectory(scriptsPath);
File.WriteAllTextAsync($"{scriptsPath}/这里放所有参与热更的脚本文件.hint", "该文件夹中的程序集定义文件,请勿删除,非常重要。");
//创建配置文件夹
string confPath = $"{domainPath}/Conf";
CreatDirectory(confPath);
//程序集配置资源
string hotfixDomain = $"HotUpdate_{domain}";
string hotfixDomainAsmdef = $"{scriptsPath}/{hotfixDomain}.asmdef";
await using (var writer = new StreamWriter(hotfixDomainAsmdef))
{
string body = Resources.Load<TextAsset>("AssemblyDefinitionTemplate").text;
body = body.Replace("MODULE_IDENT", hotfixDomain);
body = body.Replace("ROOT_NAMESPACE", hotfixDomain);
await writer.WriteAsync(body);
}
//模块化脚本生成配置
string domainClassName = $"{domain}Domain";
string architectureClassName = $"{domain}Architecture";
#if HotUpdate
//模块配置资源
DomainConfig moduleConfig = CreateInstance<DomainConfig>();
moduleConfig.domain = domain;
moduleConfig.className = domainClassName;
moduleConfig.mainPrefab = "Prefabs_" + gameObj.name;
moduleConfig.@namespace = domain;
AssetDatabase.CreateAsset(moduleConfig, $"Assets/Domain/{domain}/AddressableRes/Config/DomainConfig.asset");
//
//编辑器配置资源
BuildAssetDataSetting buildAssetDataSetting = CreateInstance<BuildAssetDataSetting>();
buildAssetDataSetting.packageName = domain;
AssetDatabase.CreateAsset(buildAssetDataSetting,
$"Assets/Domain/{domain}/Conf/BuildAssetDataSetting.asset");
AssetDatabase.Refresh();
string configPath = $"Assets/Domain/{domain}/HotUpdate/{hotfixDomain}.asmdef";
AssemblyDefinitionAsset assemblyDefinitionAsset =
AssetDatabase.LoadAssetAtPath<AssemblyDefinitionAsset>(configPath);
if (domain != "Main")
{
// 将程序集定义添加到 HybridCLR 热更列表
var settings = SettingsUtil.HybridCLRSettings;
if (!settings.hotUpdateAssemblyDefinitions.Contains(assemblyDefinitionAsset))
{
var assemblyList = settings.hotUpdateAssemblyDefinitions.ToList();
assemblyList.Add(assemblyDefinitionAsset);
SettingsUtil.HybridCLRSettings.hotUpdateAssemblyDefinitions = assemblyList.ToArray();
}
List<AssemblyDefinitionAsset> assemblies = new List<AssemblyDefinitionAsset>();
for (int i = 0; i < settings.hotUpdateAssemblyDefinitions.Length; i++)
{
if (settings.hotUpdateAssemblyDefinitions[i] != null)
{
assemblies.Add(settings.hotUpdateAssemblyDefinitions[i]);
}
}
HybridCLRSettings.Instance.hotUpdateAssemblyDefinitions = assemblies.ToArray();
HybridCLRSettings.Save();
}
#endif
AssetDatabase.SaveAssets(); AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
string domainClassPath = $"{scriptsPath}/{domainClassName}.cs";
//await File.WriteAllTextAsync($"{scriptsPath}/{domainClassName}.cs", domainTemplate);
await using (var writer = new StreamWriter(domainClassPath))
{
string domainTemplate = Resources.Load<TextAsset>("DomainTemplate").text;
domainTemplate = domainTemplate.Replace("ClassNameXX", domainClassName)
.Replace("ReturnArchitecture", architectureClassName)
.Replace("ArchitectureX", architectureClassName)
.Replace("NamespaceX", domain)
.Replace("DomainNameXX", domain);
await writer.WriteAsync(domainTemplate);
}
} }
[TitleGroup("预览Domain作用域")] [TitleGroup("预览Art作用域")]
[ListDrawerSettings(DraggableItems = false, ShowFoldout = false, ShowPaging = false, ShowItemCount = false, [ListDrawerSettings(DraggableItems = false, ShowFoldout = false, ShowPaging = false, ShowItemCount = false,
HideRemoveButton = true,HideAddButton = true)] HideRemoveButton = true, HideAddButton = true)]
public List<CreatDomainEntity> domainList; public List<CreatArtDomainEntity> domainList;
protected override void Initialize() protected override void Initialize()
{ {
@@ -256,32 +124,21 @@ namespace Stary.Evo.Editor
/// </summary> /// </summary>
public static string[] GetCreatDomainAllName() public static string[] GetCreatDomainAllName()
{ {
string domainPath = $"{Application.dataPath}/Domain"; var creatDomainEntities = GetCreatDomainAll();
string[] domains; string[] domains = new string[creatDomainEntities.Count];
// 新增目录获取代码 for (int i = 0; i < creatDomainEntities.Count; i++)
if (Directory.Exists(domainPath))
{ {
var dirInfo = new DirectoryInfo(domainPath); domains[i] = creatDomainEntities[i].DomainName;
// 获取直接子目录(不递归)
domains = dirInfo.GetDirectories("*", SearchOption.TopDirectoryOnly)
.Select(d => d.Name)
.ToArray();
} }
else
{
domains = Array.Empty<string>();
}
return domains; return domains;
} }
/// <summary> /// <summary>
/// 获取全部作用域 /// 获取全部作用域
/// </summary> /// </summary>
public static List<CreatDomainEntity> GetCreatDomainAll() public static List<CreatArtDomainEntity> GetCreatDomainAll()
{ {
string domainPath = $"{Application.dataPath}/Domain"; string domainPath = $"{Application.dataPath}/Art";
string[] domains; string[] domains;
// 新增目录获取代码 // 新增目录获取代码
if (Directory.Exists(domainPath)) if (Directory.Exists(domainPath))
@@ -297,12 +154,12 @@ namespace Stary.Evo.Editor
domains = Array.Empty<string>(); domains = Array.Empty<string>();
} }
List<CreatDomainEntity> domainList = new List<CreatDomainEntity>(); List<CreatArtDomainEntity> domainList = new List<CreatArtDomainEntity>();
foreach (var item in domains) foreach (var item in domains)
{ {
if (File.Exists($"{domainPath}/{item}/AddressableRes/Config/DomainConfig.asset")) if (File.Exists($"{domainPath}/{item}/Scenes/TestScene.unity"))
{ {
CreatDomainEntity domainEntity = new CreatDomainEntity(domainList) CreatArtDomainEntity domainEntity = new CreatArtDomainEntity(domainList)
{ {
DomainName = item, DomainName = item,
domainPath = $"{domainPath}/{item}" domainPath = $"{domainPath}/{item}"
@@ -322,53 +179,5 @@ namespace Stary.Evo.Editor
Directory.CreateDirectory(artDomainPath); Directory.CreateDirectory(artDomainPath);
} }
} }
public static void CreateDomainDirectory(string domain)
{
string artDomainPath = $"{Application.dataPath}/Art/{domain}";
//创建Animation文件夹
CreatDirectory(artDomainPath + "/Animation");
//创建Effects文件夹
CreatDirectory(artDomainPath + "/Effects");
//创建Fbx文件夹
CreatDirectory(artDomainPath + "/Fbx");
//创建Font文件夹
CreatDirectory(artDomainPath + "/Font");
//创建Materials文件夹
CreatDirectory(artDomainPath + "/Materials");
//创建Prefabs文件夹
CreatDirectory(artDomainPath + "/Prefabs");
//创建Scenes文件夹
CreatDirectory(artDomainPath + "/Scenes");
//创建/Scenes/Test文件夹
CreatDirectory(artDomainPath + "/Scenes/Test");
//创建Shader文件夹
CreatDirectory(artDomainPath + "/Shader");
//创建Textures文件夹
CreatDirectory(artDomainPath + "/Textures");
string domainPath = $"{Application.dataPath}/Domain/{domain}";
//程序资源存放文件夹
string resPath = $"{domainPath}/AddressableRes";
CreatDirectory(resPath);
//创建音频文件夹
CreatDirectory(resPath + "/Audios");
//创建Config文件夹
CreatDirectory(resPath + "/Config");
//创建Dll文件夹
CreatDirectory(resPath + "/Dll");
//创建Prefabs文件夹
CreatDirectory(resPath + "/Prefabs");
//创建Scenes文件夹
CreatDirectory(resPath + "/Scenes");
//创建SpriteAtlas文件夹
CreatDirectory(resPath + "/SpriteAtlas");
//创建Sprites文件夹
CreatDirectory(resPath + "/Sprites");
//创建Video文件夹
CreatDirectory(resPath + "/Video");
AssetDatabase.Refresh();
}
} }
} }

View File

@@ -8,16 +8,16 @@ using UnityEditor;
namespace Stary.Evo.Editor namespace Stary.Evo.Editor
{ {
[Serializable] [Serializable]
public class CreatDomainEntity public class CreatArtDomainEntity
{ {
private List<CreatDomainEntity> domainList; private List<CreatArtDomainEntity> domainList;
[HorizontalGroup] [ReadOnly] public string DomainName; [HorizontalGroup] [ReadOnly] public string DomainName;
[ReadOnly] [ReadOnly]
public string domainPath; public string domainPath;
public CreatDomainEntity(List<CreatDomainEntity> domainList) public CreatArtDomainEntity(List<CreatArtDomainEntity> domainList)
{ {
this.domainList = domainList; this.domainList = domainList;
} }
@@ -45,7 +45,7 @@ namespace Stary.Evo.Editor
EditorUtility.DisplayDialog("提示", "主包Main作用域无法删除", "确定"); EditorUtility.DisplayDialog("提示", "主包Main作用域无法删除", "确定");
return; return;
} }
bool isOk = EditorUtility.DisplayDialog("提示", "是否删除此Domain", "是", "否"); bool isOk = EditorUtility.DisplayDialog("提示", "是否删除此Art", "是", "否");
if (isOk) if (isOk)
{ {
BuildArtAssetWindow.RemoveBuildAssetWindow(); BuildArtAssetWindow.RemoveBuildAssetWindow();

View File

@@ -1,6 +1,6 @@
{ {
"name": "com.staryevo.main", "name": "com.staryevo.main",
"version": "2.0.14", "version": "2.0.15",
"displayName": "00.StaryEvo", "displayName": "00.StaryEvo",
"description": "This is an Framework package(后台服务器版本端口9527)", "description": "This is an Framework package(后台服务器版本端口9527)",
"unity": "2021.3", "unity": "2021.3",