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