2025-10-24 11:11:59 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
#if HotUpdate
|
|
|
|
|
|
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
|
|
|
|
|
|
{
|
2025-10-24 11:50:03 +08:00
|
|
|
|
public class CreatArtAssetWindow : OdinEditorWindow
|
2025-10-24 11:11:59 +08:00
|
|
|
|
{
|
2025-10-24 19:08:10 +08:00
|
|
|
|
[MenuItem("Evo/Art/创建Art作用域",false, 0)]
|
2025-10-24 11:11:59 +08:00
|
|
|
|
static void Init()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Get existing open window or if none, make a new one:
|
2025-10-24 11:50:03 +08:00
|
|
|
|
CreatArtAssetWindow window = (CreatArtAssetWindow)EditorWindow.GetWindow(typeof(CreatArtAssetWindow));
|
2025-10-24 11:11:59 +08:00
|
|
|
|
window.Show();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-24 11:50:03 +08:00
|
|
|
|
[TitleGroup("创建Art作用域")] public string domain;
|
2025-10-24 11:11:59 +08:00
|
|
|
|
|
2025-10-24 11:50:03 +08:00
|
|
|
|
[TitleGroup("创建Art作用域")]
|
|
|
|
|
|
[Button("创建Art", ButtonSizes.Large)]
|
2025-10-24 11:11:59 +08:00
|
|
|
|
public async void CreatDomain()
|
|
|
|
|
|
{
|
|
|
|
|
|
// if (GetCreatDomainAll().Count>0)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// EditorUtility.DisplayDialog("错误!", "Domain仅可以创建一个,请在下方删除存在的Domain", "确定");
|
|
|
|
|
|
// return;
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(domain))
|
|
|
|
|
|
{
|
2025-10-24 11:50:03 +08:00
|
|
|
|
EditorUtility.DisplayDialog("错误!", "请输入将要创建Art的编号", "确定");
|
2025-10-24 11:11:59 +08:00
|
|
|
|
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文件夹
|
2025-10-24 11:50:03 +08:00
|
|
|
|
CreatDirectory(artDomainPath + "/Scenes");
|
2025-10-24 11:11:59 +08:00
|
|
|
|
//创建Shader文件夹
|
|
|
|
|
|
CreatDirectory(artDomainPath + "/Shader");
|
|
|
|
|
|
//创建Textures文件夹
|
|
|
|
|
|
CreatDirectory(artDomainPath + "/Textures");
|
|
|
|
|
|
File.WriteAllTextAsync(
|
|
|
|
|
|
$"{artDomainPath}/这里放所有美术的资源,因涉及打包依赖等原因,不建议在上一层节点新增文件夹,如涉及文件夹规范等问题请@张铮.hint", "");
|
|
|
|
|
|
}
|
2025-10-24 11:50:03 +08:00
|
|
|
|
|
2025-10-24 11:11:59 +08:00
|
|
|
|
//创建Art 测试场景
|
|
|
|
|
|
/* 2. 再建 Scenes/Test */
|
2025-10-24 11:50:03 +08:00
|
|
|
|
string sceneDir = $"{artDomainPath}/Scenes";
|
2025-10-24 11:11:59 +08:00
|
|
|
|
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 = "RKCameraRig";
|
|
|
|
|
|
|
|
|
|
|
|
/* 6. 保存场景 */
|
2025-10-24 11:50:03 +08:00
|
|
|
|
string scenePath = Path.Combine("Assets/Art", domain, "Scenes", "TestScene.unity");
|
2025-10-24 11:11:59 +08:00
|
|
|
|
UnityEditor.SceneManagement.EditorSceneManager.SaveScene(newScene, scenePath);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AssetDatabase.SaveAssets();
|
2025-10-24 11:50:03 +08:00
|
|
|
|
AssetDatabase.Refresh();
|
2025-10-24 11:11:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-10-24 11:50:03 +08:00
|
|
|
|
[TitleGroup("预览Art作用域")]
|
2025-10-24 11:11:59 +08:00
|
|
|
|
[ListDrawerSettings(DraggableItems = false, ShowFoldout = false, ShowPaging = false, ShowItemCount = false,
|
2025-10-24 11:50:03 +08:00
|
|
|
|
HideRemoveButton = true, HideAddButton = true)]
|
|
|
|
|
|
public List<CreatArtDomainEntity> domainList;
|
2025-10-24 11:11:59 +08:00
|
|
|
|
|
|
|
|
|
|
protected override void Initialize()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
domainList = GetCreatDomainAll();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取全部作用域
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static string[] GetCreatDomainAllName()
|
|
|
|
|
|
{
|
2025-10-24 11:50:03 +08:00
|
|
|
|
var creatDomainEntities = GetCreatDomainAll();
|
|
|
|
|
|
string[] domains = new string[creatDomainEntities.Count];
|
|
|
|
|
|
for (int i = 0; i < creatDomainEntities.Count; i++)
|
2025-10-24 11:11:59 +08:00
|
|
|
|
{
|
2025-10-24 11:50:03 +08:00
|
|
|
|
domains[i] = creatDomainEntities[i].DomainName;
|
2025-10-24 11:11:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
return domains;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取全部作用域
|
|
|
|
|
|
/// </summary>
|
2025-10-24 11:50:03 +08:00
|
|
|
|
public static List<CreatArtDomainEntity> GetCreatDomainAll()
|
2025-10-24 11:11:59 +08:00
|
|
|
|
{
|
2025-10-24 11:50:03 +08:00
|
|
|
|
string domainPath = $"{Application.dataPath}/Art";
|
2025-10-24 11:11:59 +08:00
|
|
|
|
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>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-24 11:50:03 +08:00
|
|
|
|
List<CreatArtDomainEntity> domainList = new List<CreatArtDomainEntity>();
|
2025-10-24 11:11:59 +08:00
|
|
|
|
foreach (var item in domains)
|
|
|
|
|
|
{
|
2025-10-24 11:50:03 +08:00
|
|
|
|
if (File.Exists($"{domainPath}/{item}/Scenes/TestScene.unity"))
|
2025-10-24 11:11:59 +08:00
|
|
|
|
{
|
2025-10-24 11:50:03 +08:00
|
|
|
|
CreatArtDomainEntity domainEntity = new CreatArtDomainEntity(domainList)
|
2025-10-24 11:11:59 +08:00
|
|
|
|
{
|
|
|
|
|
|
DomainName = item,
|
|
|
|
|
|
domainPath = $"{domainPath}/{item}"
|
|
|
|
|
|
};
|
|
|
|
|
|
domainList.Add(domainEntity);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return domainList;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static void CreatDirectory(string artDomainPath)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!Directory.Exists(artDomainPath))
|
|
|
|
|
|
{
|
|
|
|
|
|
//创建Animation文件夹
|
|
|
|
|
|
Directory.CreateDirectory(artDomainPath);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|