98 lines
2.7 KiB
C#
98 lines
2.7 KiB
C#
using UnityEditor;
|
|
using UnityEngine;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using AlicizaX.UI.Editor;
|
|
using AlicizaX.UI.Runtime;
|
|
|
|
public class UIGenerateWindow : EditorWindow
|
|
{
|
|
private GameObject targetObject;
|
|
|
|
private List<string> generateConfigs = new List<string>();
|
|
private int selectIndex = 0;
|
|
|
|
public static GameObject GetTargetObject()
|
|
{
|
|
return GetWindow<UIGenerateWindow>().targetObject;
|
|
}
|
|
|
|
public static void ShowWindow(GameObject target)
|
|
{
|
|
var window = GetWindow<UIGenerateWindow>(false, "UI Config Editor");
|
|
window.Initlize(target);
|
|
window.maxSize = new Vector2(100, 200);
|
|
}
|
|
|
|
private void Initlize(GameObject target)
|
|
{
|
|
targetObject = target;
|
|
generateConfigs = UIGenerateConfiguration.Instance.UIScriptGenerateConfigs.Select(t => t.ConfigName).ToList();
|
|
}
|
|
|
|
private void OnGUI()
|
|
{
|
|
DrawObjectPicker();
|
|
DrawConfig();
|
|
DrawActionButtons();
|
|
}
|
|
|
|
private void DrawObjectPicker()
|
|
{
|
|
GUILayout.Space(10);
|
|
EditorGUILayout.LabelField("UI配置生成工具", EditorStyles.boldLabel);
|
|
GUILayout.Space(5);
|
|
|
|
EditorGUI.BeginDisabledGroup(true);
|
|
EditorGUILayout.ObjectField("目标预制体", targetObject, typeof(GameObject), true);
|
|
EditorGUI.EndDisabledGroup();
|
|
}
|
|
|
|
|
|
private void DrawConfig()
|
|
{
|
|
GUILayout.Space(15);
|
|
var index = EditorGUILayout.Popup("生成配置", selectIndex, generateConfigs.ToArray());
|
|
if (index != selectIndex)
|
|
{
|
|
selectIndex = index;
|
|
}
|
|
}
|
|
|
|
private void DrawActionButtons()
|
|
{
|
|
GUILayout.Space(20);
|
|
EditorGUILayout.BeginHorizontal();
|
|
GUILayout.FlexibleSpace();
|
|
|
|
if (GUILayout.Button("生成配置", GUILayout.ExpandWidth(true), GUILayout.Height(30)))
|
|
{
|
|
GenerateConfig();
|
|
}
|
|
|
|
EditorGUILayout.EndHorizontal();
|
|
}
|
|
|
|
|
|
private void GenerateConfig()
|
|
{
|
|
if (generateConfigs.Count <= 0)
|
|
{
|
|
Debug.LogWarning("生成配置为空!");
|
|
return;
|
|
}
|
|
|
|
string configName = generateConfigs[selectIndex];
|
|
var configData = UIGenerateConfiguration.Instance.UIScriptGenerateConfigs.Find(t => t.ConfigName == configName);
|
|
if (string.IsNullOrEmpty(configData.NameSpace) || string.IsNullOrEmpty(configData.GenerateHolderCodePath) || string.IsNullOrEmpty(configData.UIPrefabPath))
|
|
{
|
|
Debug.LogWarning($"{configName} 的配置项部分为空,请确保所有路径正确后重新生成");
|
|
return;
|
|
}
|
|
|
|
UIScriptGeneratorHelper.GenerateAndAttachScript(targetObject, configName);
|
|
}
|
|
}
|