62 lines
1.9 KiB
C#
62 lines
1.9 KiB
C#
using AibisDream.Framework;
|
|
using AibisDream.Kit;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
namespace AibisDream.SystemEditor
|
|
{
|
|
[CustomEditor(typeof(SystemHasData), true)]
|
|
public class SystemHasDataEditor : Editor
|
|
{
|
|
private int _selectedIndex;
|
|
private string _inputText = "";
|
|
private string[] _options;
|
|
|
|
public override void OnInspectorGUI()
|
|
{
|
|
// 获取目标对象
|
|
SystemHasData example = (SystemHasData)target;
|
|
_options ??= GetDataKeysByPath(example.GetConfigPath());
|
|
|
|
// 绘制默认的 Inspector
|
|
DrawDefaultInspector();
|
|
|
|
GUILayout.Label("数据加载与保存");
|
|
// 绘制下拉选择和输入框
|
|
EditorGUILayout.BeginHorizontal();
|
|
int newIndex = EditorGUILayout.Popup(_selectedIndex, _options);
|
|
_inputText = EditorGUILayout.TextField(_inputText);
|
|
EditorGUILayout.EndHorizontal();
|
|
|
|
if (newIndex != _selectedIndex)
|
|
{
|
|
_selectedIndex = newIndex;
|
|
_inputText = _options[newIndex];
|
|
}
|
|
|
|
// 保存按钮
|
|
if (GUILayout.Button("保存"))
|
|
{
|
|
Undo.RecordObject(example, "Save Input Value");
|
|
example.CurDataKey = _inputText;
|
|
example.SaveLevel();
|
|
Debug.Log("Saved: " + _inputText);
|
|
}
|
|
|
|
// 加载按钮
|
|
if (GUILayout.Button("加载"))
|
|
{
|
|
example.CurDataKey = _inputText;
|
|
_selectedIndex = System.Array.IndexOf(_options, _inputText);
|
|
if (_selectedIndex < 0) _selectedIndex = 0;
|
|
example.LoadLevel();
|
|
Debug.Log("Loaded: " + _inputText);
|
|
}
|
|
}
|
|
|
|
private static string[] GetDataKeysByPath(string path)
|
|
{
|
|
return ConfigUtil.Instance.GetFileNames(path);
|
|
}
|
|
}
|
|
} |