/* * @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(); 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(path); if (!_asset) { _asset = CreateInstance(); 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($"类型:{item.Type}"); item.Prefab = (GameObject)EditorGUILayout.ObjectField(item.Prefab, typeof(GameObject), false); EditorGUILayout.EndVertical(); } EditorGUILayout.EndScrollView(); } } }