TH1/Unity/Assets/Scripts/TH1_Logic/Editor/PrefabConfigEditorWindow.cs
2025-08-18 23:16:13 +08:00

114 lines
3.4 KiB
C#

/*
* @Author: 白哉
* @Description: AI 编辑器
* @Date: 2025年04月22日 星期二 15:04:14
* @Modify:
*/
using System.Collections.Generic;
using System.Linq;
using CanvasCoreExpand;
using Logic.AI;
using Logic.PrefabPool;
using NodeCanvas.BehaviourTrees;
using NodeCanvas.Framework;
using NodeCanvas.Tasks.Actions;
using RuntimeData;
using UnityEditor;
using UnityEngine;
using PrefabType = Logic.PrefabPool.PrefabType;
namespace Logic.Editor
{
public class PrefabConfigEditorWindow : EditorWindow
{
// 滑条
private Vector2 _barPosition;
// 背景
private GUIStyle _redBoxStyle;
private GUIStyle _whiteBoxStyle;
private PrefabConfig _asset;
[MenuItem("Tools/预制体编辑器")]
private static void ShowWindow()
{
var window = CreateWindow<PrefabConfigEditorWindow>();
window.titleContent = new GUIContent("预制体编辑器");
window.Show();
window.minSize = new Vector2(500, 600);
}
protected virtual void OnEnable()
{
}
private void OnDisable()
{
}
private void OnGUI()
{
if (_redBoxStyle == null)
{
_redBoxStyle = InspectorUtils.GetHelpBoxStyle();
InspectorUtils.AddBorder(_redBoxStyle, new Color(0.5f, 0.4f, 0.4f, 0.6f));
}
if (_whiteBoxStyle == null)
{
_whiteBoxStyle = InspectorUtils.GetHelpBoxStyle();
InspectorUtils.AddBorder(_whiteBoxStyle, new Color(1f, 1f, 1f, 0.2f));
}
GUI.skin.button.wordWrap = true;
_barPosition = EditorGUILayout.BeginScrollView(_barPosition);
if (!_asset)
{
var path = $"Assets/Resources/DataAssets/PrefabConfig.asset";
_asset = AssetDatabase.LoadAssetAtPath<PrefabConfig>(path);
if (!_asset)
{
_asset = CreateInstance<PrefabConfig>();
AssetDatabase.CreateAsset(_asset, path);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
}
if (InspectorUtils.InspectorButtonWithTextWidth("保存"))
{
EditorUtility.SetDirty(_asset);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
if (_asset.PrefabList.Count != (int)PrefabType.Max)
{
for (int i = 0; i < (int)PrefabType.Max; i++)
{
var item = _asset.GetPrefab((PrefabType)i);
if (item != null) continue;
item = new PrefabItem();
item.Type = (PrefabType)i;
_asset.PrefabList.Add(item);
}
}
_asset.PrefabList = _asset.PrefabList.OrderBy(p => p.Type).ToList();
foreach (var item in _asset.PrefabList)
{
EditorGUILayout.BeginVertical(_whiteBoxStyle);
InspectorUtils.InspectorTextWidthRich($"<b>类型:{item.Type}</b>");
item.Prefab = (GameObject)EditorGUILayout.ObjectField(item.Prefab, typeof(GameObject), false);
EditorGUILayout.EndVertical();
}
EditorGUILayout.EndScrollView();
}
}
}