All checks were successful
Plugin Library CI / publish (00.BuildOriginality) (push) Successful in 3s
Plugin Library CI / publish (00.StaryEvo) (push) Successful in 8s
Plugin Library CI / publish (00.StaryEvoTools) (push) Successful in 19s
Plugin Library CI / publish (01.HybridCLR) (push) Successful in 5s
Plugin Library CI / publish (02.InformationSave) (push) Successful in 3s
Plugin Library CI / publish (03.YooAsset) (push) Successful in 33s
Plugin Library CI / publish (04.AudioCore) (push) Successful in 3s
Plugin Library CI / publish (05.TableTextConversion) (push) Successful in 4s
Plugin Library CI / publish (06.UIFarme) (push) Successful in 16s
Plugin Library CI / publish (07.RKTools) (push) Successful in 7s
Plugin Library CI / publish (08.UniTask) (push) Successful in 3s
Plugin Library CI / publish (09.CodeChecker) (push) Successful in 16s
Plugin Library CI / publish (10.StoryEditor) (push) Successful in 2s
Plugin Library CI / publish (10.XNode) (push) Successful in 3s
Plugin Library CI / publish (11.PointCloudTools) (push) Successful in 2s
388 lines
15 KiB
C#
388 lines
15 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.IO;
|
||
using System.Linq;
|
||
#if !UNITY_WEBGL
|
||
using HybridCLR.Editor;
|
||
using HybridCLR.Editor.Settings;
|
||
#endif
|
||
using Sirenix.OdinInspector;
|
||
using Sirenix.OdinInspector.Editor;
|
||
using UnityEditor;
|
||
using UnityEditorInternal;
|
||
using UnityEngine;
|
||
|
||
namespace Stary.Evo.Editor
|
||
{
|
||
public class CreatAssetWindow : OdinEditorWindow
|
||
{
|
||
[MenuItem("Evo/Dev/创建Domain作用域", false, 1)]
|
||
static void Init()
|
||
{
|
||
// Get existing open window or if none, make a new one:
|
||
CreatAssetWindow window = (CreatAssetWindow)EditorWindow.GetWindow(typeof(CreatAssetWindow));
|
||
window.Show();
|
||
}
|
||
|
||
[TitleGroup("创建Domain作用域")] public string domain;
|
||
|
||
[TitleGroup("创建Domain作用域")]
|
||
[Button("创建Domain", ButtonSizes.Large)]
|
||
public async void CreatDomain()
|
||
{
|
||
// if (GetCreatDomainAll().Count>0)
|
||
// {
|
||
// EditorUtility.DisplayDialog("错误!", "Domain仅可以创建一个,请在下方删除存在的Domain", "确定");
|
||
// return;
|
||
// }
|
||
|
||
if (string.IsNullOrEmpty(domain))
|
||
{
|
||
EditorUtility.DisplayDialog("错误!", "请输入将要创建Domain的编号", "确定");
|
||
return;
|
||
}
|
||
|
||
string artDomainPath = $"{Application.dataPath}/Art/{domain}";
|
||
if (!Directory.Exists(artDomainPath))
|
||
{
|
||
Directory.CreateDirectory(artDomainPath);
|
||
|
||
if (!Directory.Exists(artDomainPath))
|
||
//创建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");
|
||
File.WriteAllTextAsync(
|
||
$"{artDomainPath}/这里放所有美术的资源,因涉及打包依赖等原因,不建议在上一层节点新增文件夹,如涉及文件夹规范等问题请@张铮.hint", "");
|
||
}
|
||
|
||
//创建Art 测试场景
|
||
/* 2. 再建 Scenes/Test */
|
||
string sceneDir = $"{artDomainPath}/Scenes/Test";
|
||
if (!Directory.Exists(sceneDir))
|
||
{
|
||
Directory.CreateDirectory(sceneDir);
|
||
/* 3. 创建新场景 */
|
||
var newScene = UnityEditor.SceneManagement.EditorSceneManager.NewScene(
|
||
UnityEditor.SceneManagement.NewSceneSetup.DefaultGameObjects,
|
||
UnityEditor.SceneManagement.NewSceneMode.Single);
|
||
|
||
/* 4. 删除默认相机(和灯光)*/
|
||
foreach (var go in newScene.GetRootGameObjects())
|
||
{
|
||
if (go.name == "Main Camera" || go.name == "Directional Light")
|
||
GameObject.DestroyImmediate(go);
|
||
}
|
||
|
||
/* 5. 载入并实例化 RKCameraRig.prefab */
|
||
string prefabPath = "Prefabs/BaseSetting/RKCameraRig";
|
||
|
||
var prefab = Resources.Load<GameObject>(prefabPath);
|
||
var spawned = (GameObject)PrefabUtility.InstantiatePrefab(prefab);
|
||
spawned.name = "RKCameraRigTest";
|
||
|
||
/* 6. 保存场景 */
|
||
string scenePath = Path.Combine("Assets/Art", name, "Scenes", "Test", "TestScene.unity");
|
||
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");
|
||
#if !UNITY_WEBGL
|
||
//创建Dll文件夹
|
||
CreatDirectory(resPath + "/Dll");
|
||
#endif
|
||
//创建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";
|
||
domainClassName = domainClassName.Replace('.', '_');
|
||
string architectureClassName = $"{domain}Architecture";
|
||
architectureClassName = architectureClassName.Replace('.', '_');
|
||
|
||
//编辑器配置资源
|
||
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);
|
||
|
||
//模块配置资源
|
||
DomainConfig moduleConfig = CreateInstance<DomainConfig>();
|
||
moduleConfig.domain = domain;
|
||
moduleConfig.assemblyName = assemblyDefinitionAsset.name;
|
||
moduleConfig.className = domainClassName;
|
||
moduleConfig.mainPrefab = "Prefabs_" + gameObj.name;
|
||
moduleConfig.@namespace = domain;
|
||
AssetDatabase.CreateAsset(moduleConfig, $"Assets/Domain/{domain}/AddressableRes/Config/DomainConfig.asset");
|
||
//
|
||
#if !UNITY_WEBGL
|
||
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();
|
||
|
||
|
||
|
||
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作用域")]
|
||
[ListDrawerSettings(DraggableItems = false, ShowFoldout = false, ShowPaging = false, ShowItemCount = false,
|
||
HideRemoveButton = true, HideAddButton = true)]
|
||
public List<CreatDomainEntity> domainList;
|
||
|
||
protected override void Initialize()
|
||
{
|
||
base.Initialize();
|
||
domainList = GetCreatDomainAll();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取全部作用域
|
||
/// </summary>
|
||
public static string[] GetCreatDomainAllName()
|
||
{
|
||
string domainPath = $"{Application.dataPath}/Domain";
|
||
string[] domains;
|
||
// 新增目录获取代码
|
||
if (Directory.Exists(domainPath))
|
||
{
|
||
var dirInfo = new DirectoryInfo(domainPath);
|
||
// 获取直接子目录(不递归)
|
||
domains = dirInfo.GetDirectories("*", SearchOption.TopDirectoryOnly)
|
||
.Select(d => d.Name)
|
||
.ToArray();
|
||
}
|
||
else
|
||
{
|
||
domains = Array.Empty<string>();
|
||
}
|
||
|
||
|
||
return domains;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取全部作用域
|
||
/// </summary>
|
||
public static List<CreatDomainEntity> GetCreatDomainAll()
|
||
{
|
||
string domainPath = $"{Application.dataPath}/Domain";
|
||
string[] domains;
|
||
// 新增目录获取代码
|
||
if (Directory.Exists(domainPath))
|
||
{
|
||
var dirInfo = new DirectoryInfo(domainPath);
|
||
// 获取直接子目录(不递归)
|
||
domains = dirInfo.GetDirectories("*", SearchOption.TopDirectoryOnly)
|
||
.Select(d => d.Name)
|
||
.ToArray();
|
||
}
|
||
else
|
||
{
|
||
domains = Array.Empty<string>();
|
||
}
|
||
|
||
List<CreatDomainEntity> domainList = new List<CreatDomainEntity>();
|
||
foreach (var item in domains)
|
||
{
|
||
if (File.Exists($"{domainPath}/{item}/AddressableRes/Config/DomainConfig.asset"))
|
||
{
|
||
CreatDomainEntity domainEntity = new CreatDomainEntity(domainList)
|
||
{
|
||
DomainName = item,
|
||
domainPath = $"{domainPath}/{item}"
|
||
};
|
||
domainList.Add(domainEntity);
|
||
}
|
||
}
|
||
|
||
return domainList;
|
||
}
|
||
|
||
private static void CreatDirectory(string artDomainPath)
|
||
{
|
||
if (!Directory.Exists(artDomainPath))
|
||
{
|
||
//创建Animation文件夹
|
||
Directory.CreateDirectory(artDomainPath);
|
||
}
|
||
}
|
||
|
||
public static void CreateDomainDirectory(string domain)
|
||
{
|
||
string artDomainPath = $"{Application.dataPath}/Art/{domain}";
|
||
if (!Directory.Exists(artDomainPath))
|
||
{
|
||
EditorUtility.DisplayDialog("提示", $"不存在此Domain:{domain},无法创建", "确定");
|
||
return;
|
||
}
|
||
|
||
//创建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");
|
||
#if !UNITY_WEBGL
|
||
{
|
||
//创建Dll文件夹
|
||
CreatDirectory(resPath + "/Dll");
|
||
}
|
||
#endif
|
||
//创建Prefabs文件夹
|
||
CreatDirectory(resPath + "/Prefabs");
|
||
//创建Scenes文件夹
|
||
CreatDirectory(resPath + "/Scenes");
|
||
//创建SpriteAtlas文件夹
|
||
CreatDirectory(resPath + "/SpriteAtlas");
|
||
//创建Sprites文件夹
|
||
CreatDirectory(resPath + "/Sprites");
|
||
//创建Video文件夹
|
||
CreatDirectory(resPath + "/Video");
|
||
|
||
AssetDatabase.Refresh();
|
||
}
|
||
}
|
||
} |