AlicizaX/Client/Assets/Scripts/Editor/ToolBar/ResourceModeDropdownField.cs

66 lines
2.1 KiB
C#
Raw Normal View History

2025-03-04 18:40:14 +08:00
using System.Collections.Generic;
using System.Linq;
using AlicizaX.Resource.Runtime;
using Paps.UnityToolbarExtenderUIToolkit;
using UnityEditor;
2025-03-07 18:00:59 +08:00
using UnityEditor.Toolbars;
2025-03-04 18:40:14 +08:00
using UnityEngine;
using UnityEngine.UIElements;
namespace AlicizaX.Editor.Extension
{
[MainToolbarElement("ResourceModeDropdownField", alignment: ToolbarAlign.Right, order: 0)]
2025-03-07 18:00:59 +08:00
public class ResourceModeDropdownField : IMGUIContainer
2025-03-04 18:40:14 +08:00
{
2025-03-07 18:00:59 +08:00
private static GUIContent appConfigBtContent;
2025-03-04 18:40:14 +08:00
private static readonly string[] _resourceModeNames =
{
"Editor",
"Offline",
"Host",
};
public void InitializeElement()
{
2025-03-07 18:00:59 +08:00
appConfigBtContent =
EditorGUIUtility.TrTextContentWithIcon("Res:", "配置App运行时所需DataTable/Config/Procedure",
"Settings");
onGUIHandler = MyGUIMethod;
}
private void MyGUIMethod()
{
GUILayout.BeginHorizontal();
string title = "Res:" + _resourceModeNames[EditorPrefs.GetInt(ResourceComponent.PrefsKey, 0)];
appConfigBtContent.text = title;
if (EditorGUILayout.DropdownButton(appConfigBtContent, FocusType.Passive, EditorStyles.toolbarPopup, GUILayout.MaxWidth(90)))
{
DrawEditorToolDropdownMenus();
}
GUILayout.Space(5);
GUILayout.EndHorizontal();
}
static void DrawEditorToolDropdownMenus()
{
2025-03-04 18:40:14 +08:00
int index = EditorPrefs.GetInt(ResourceComponent.PrefsKey, 0);
2025-03-07 18:00:59 +08:00
GenericMenu popMenu = new GenericMenu();
for (int i = 0; i < _resourceModeNames.Length; i++)
2025-03-04 18:40:14 +08:00
{
2025-03-07 18:00:59 +08:00
var selected = index == i;
var toolAttr = _resourceModeNames[i];
popMenu.AddItem(new GUIContent(toolAttr), selected, menuIdx => { ClickToolsSubmenu((int)menuIdx); }, i);
}
popMenu.ShowAsContext();
}
static void ClickToolsSubmenu(int menuIdx)
{
EditorPrefs.SetInt(ResourceComponent.PrefsKey, menuIdx);
2025-03-04 18:40:14 +08:00
}
}
}