Files
plugin-library/Assets/00.BuildOriginality/Editor/ArtBuild/ArtServerManageWindow.cs
2025-11-04 16:26:50 +08:00

344 lines
12 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Sirenix.OdinInspector;
using Sirenix.OdinInspector.Editor;
using UnityEditor;
using UnityEngine;
using UnityEngine.Serialization;
namespace Stary.Evo.Editor
{
public class ArtServerManageWindow : OdinEditorWindow
{
[MenuItem("Evo/Art/服务器数据管理工具", false, 2)]
static void Init()
{
// Get existing open window or if none, make a new one:
ArtServerManageWindow window = (ArtServerManageWindow)EditorWindow.GetWindow(typeof(ArtServerManageWindow));
window.Show();
}
[EnumToggleButtons, HideLabel] [OnValueChanged("SetUseTypeData")]
public UseType useType = UseType.Member;
private string _titleGroupName;
[TitleGroup("@ _titleGroupName")] public string productName;
[TitleGroup("@ _titleGroupName")]
[Button("@ _titleGroupName", ButtonSizes.Large)]
public void CreatDomain()
{
if (useType == UseType.Member)
{
CreatMemberFiled();
}
else if (useType == UseType.Project)
{
CreatArtFiled();
}
}
/// <summary>
/// 创建项目目录
/// </summary>
private void CreatArtFiled()
{
if (string.IsNullOrEmpty(productName))
{
EditorUtility.DisplayDialog("错误!", "请输入将要创建Art的编号", "确定");
return;
}
string artDomainPath = $"{Application.dataPath}/Art/{productName}";
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 = "RKCameraRigTest";
/* 6. 保存场景 */
string scenePath = Path.Combine("Assets/Art", productName, "Scenes", "TestScene.unity");
UnityEditor.SceneManagement.EditorSceneManager.SaveScene(newScene, scenePath);
}
/// <summary>
/// 创建成员目录
/// </summary>
private void CreatMemberFiled()
{
if (string.IsNullOrEmpty(productName))
{
EditorUtility.DisplayDialog("错误!", "请输入将要创建成员的编号", "确定");
return;
}
//检测成员是否存在
bool isExit = false;
foreach (var domainEntity in domainMemberList)
{
if (domainEntity.DomainName == productName)
{
isExit = true;
break;
}
}
if (isExit)
{
EditorUtility.DisplayDialog("错误!", "当前成员已在服务器中存在,无需重复创建", "确定");
return;
}
string memberDomainPath = $"{Application.dataPath}/Member/{productName}";
if (!Directory.Exists(memberDomainPath))
{
Directory.CreateDirectory(memberDomainPath);
//创建Config文件夹
CreatDirectory(memberDomainPath + "/Config");
//创建Scenes文件夹
CreatDirectory(memberDomainPath + "/Scenes");
File.WriteAllTextAsync(
$"{memberDomainPath}/这里是成员打包目录,因涉及打包依赖等原因,不建议在上一层节点新增文件夹,如涉及文件夹规范等问题请@张铮.hint", "");
}
//创建Art 测试场景配置文件
string configDir = $"{memberDomainPath}/Config";
//模块配置资源
ArtSceneData artSceneData = CreateInstance<ArtSceneData>();
AssetDatabase.CreateAsset(artSceneData, $"Assets/Member/{productName}/Config/ArtSceneData.asset");
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
[ShowIf("IsMember")]
[ListDrawerSettings(DraggableItems = false, ShowFoldout = false, ShowPaging = false, ShowItemCount = false,
HideRemoveButton = true, HideAddButton = true)]
public List<CreatMemberServerDomainEntity> domainMemberList;
[ShowIf("IsProject")]
[ListDrawerSettings(DraggableItems = false, ShowFoldout = false, ShowPaging = false, ShowItemCount = false,
HideRemoveButton = true, HideAddButton = true)]
public List<CreatArtDomainEntity> artList;
protected override async void Initialize()
{
base.Initialize();
SetUseTypeData();
if (domainMemberList != null)
{
domainMemberList.Clear();
}
domainMemberList = new List<CreatMemberServerDomainEntity>();
var resDmainResponse = await ArtLoadAssetServer.GetServerDomainAll();
foreach (var response in resDmainResponse)
{
string domainPath = $"{Application.dataPath}/Member/{response.DomainName}";
var domainEntity = new CreatMemberServerDomainEntity(domainMemberList);
domainEntity.SetDomainData(response.DomainName, domainPath, response, ArtLoadAssetServer.ip);
domainMemberList.Add(domainEntity);
}
artList = GetCreatDomainAll();
}
private static void CreatDirectory(string artDomainPath)
{
if (!Directory.Exists(artDomainPath))
{
Directory.CreateDirectory(artDomainPath);
}
}
public void CreateDomainDirectory(string domain)
{
string artDomainPath = "";
if (useType == UseType.Member)
{
artDomainPath = $"{Application.dataPath}/Member/{domain}";
}
else if (useType == UseType.Project)
{
artDomainPath = $"{Application.dataPath}/Art/{domain}";
}
if (!Directory.Exists(artDomainPath))
{
EditorUtility.DisplayDialog("提示", $"不存在此Domain:{domain},无法创建", "确定");
return;
}
if (useType == UseType.Member)
{
//创建Config文件夹
CreatDirectory(artDomainPath + "/Config");
//创建Scenes文件夹
CreatDirectory(artDomainPath + "/Scenes");
//创建/Scenes/Test文件夹
CreatDirectory(artDomainPath + "/Scenes/Test");
}
else if (useType == UseType.Project)
{
//创建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");
}
AssetDatabase.Refresh();
}
/// <summary>
/// 获取全部作用域
/// </summary>
private 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 (Directory.Exists($"{domainPath}/{item}"))
{
CreatArtDomainEntity domainEntity = new CreatArtDomainEntity(domainList)
{
DomainName = item,
domainPath = $"{domainPath}/{item}"
};
domainList.Add(domainEntity);
}
}
return domainList;
}
private void SetUseTypeData()
{
if (useType == UseType.Member)
{
_titleGroupName = "创建成员";
}
else if (useType == UseType.Project)
{
_titleGroupName = "创建项目Art";
}
}
private bool IsMember()
{
return useType == UseType.Member;
}
private bool IsProject()
{
return useType == UseType.Project;
}
/// <summary>
/// 使用类型
/// </summary>
public enum UseType
{
/// <summary>
/// 成员使用
/// </summary>
Member,
/// <summary>
/// 项目使用
/// </summary>
Project
}
}
}