Files
plugin-library/Assets/00.ARMazTools/Editor/EvoArtFolderCreator.cs
zhangzheng 14322e1d2c 111
2025-11-26 17:22:41 +08:00

137 lines
4.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.IO;
using UnityEditor;
using UnityEngine;
using System.Linq;
using Stary.Evo.Editor;
public class EvoArtFolderCreator : EditorWindow
{
static string[] moduleNames; // 下拉列表
static int selectedIndex; // 当前选中的下标
[MenuItem("Evo/创建Art文件夹")]
static void OpenCreator()
{
var w = GetWindowWithRect<EvoArtFolderCreator>(new Rect(0, 0, 350, 110), true, "创建点位");
w.minSize = w.maxSize = new Vector2(350, 110);
}
void OnEnable()
{
RefreshModuleList();
}
void OnGUI()
{
GUILayout.Space(10);
bool hasModule = moduleNames != null && moduleNames.Length > 0;
if (!hasModule)
EditorGUILayout.HelpBox("未找到 Assets/Modules 目录或目录下无子文件夹!", MessageType.Warning);
else
{
EditorGUILayout.LabelField("选择模块(点位)", EditorStyles.boldLabel);
selectedIndex = EditorGUILayout.Popup(selectedIndex, moduleNames);
}
GUILayout.FlexibleSpace();
// ****** 关键BeginHorizontal 始终闭合 ******
using (new EditorGUILayout.HorizontalScope())
{
GUILayout.FlexibleSpace();
GUI.enabled = hasModule; // 禁用按钮而不是提前 return
if (GUILayout.Button("创建点位", GUILayout.Width(100), GUILayout.Height(25)))
{
CreateFolders(moduleNames[selectedIndex]);
Close();
}
if (GUILayout.Button("标记资源", GUILayout.Width(100), GUILayout.Height(25)))
{
MarkAdressable.AddDomainMark(moduleNames[selectedIndex]);
Close();
}
GUI.enabled = true;
if (GUILayout.Button("取消", GUILayout.Width(100), GUILayout.Height(25)))
Close();
}
}
/// <summary>
/// 重新扫描 Modules 子文件夹
/// </summary>
public static string[] RefreshModuleList()
{
string modulesRoot = Path.Combine(Application.dataPath, "Modules");
if (!Directory.Exists(modulesRoot))
{
moduleNames = new string[0];
}
// 只取一级目录名
moduleNames = Directory.GetDirectories(modulesRoot)
.Select(p => Path.GetFileName(p))
.ToArray();
selectedIndex = 0;
return moduleNames;
}
// 仅替换原来的 CreateFolders 方法即可
public static void CreateFolders(string name)
{
string root = Path.Combine(Application.dataPath, "Art", name);
string sceneDir = Path.Combine(root, "Scenes", "Test"); // Scenes/Test
string[] dirs =
{
"Animation", "Effects", "Fbx", "Font", "Materials",
"Prefabs", "Scenes", "Shader", "Textures"
};
try
{
/* 1. 创建所有基础目录 */
foreach (var dir in dirs)
{
string full = Path.Combine(root, dir);
if (!Directory.Exists(full)) Directory.CreateDirectory(full);
}
/* 2. 再建 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 = "RKCameraRig";
/* 6. 保存场景 */
string scenePath = Path.Combine("Assets/Art", name, "Scenes", "Test", "TestScene.unity");
UnityEditor.SceneManagement.EditorSceneManager.SaveScene(newScene, scenePath);
AssetDatabase.Refresh();
EditorUtility.DisplayDialog("成功", $"已生成完整目录及 TestScene含 RKCameraRig", "确定");
}
}
catch (System.Exception e)
{
EditorUtility.DisplayDialog("错误", "创建失败:\n" + e.Message, "确定");
}
}
}