AlicizaX/Client/Assets/Editor/ToolbarExtender/Custom/EditorResourceMode.cs
2025-02-06 17:59:35 +08:00

52 lines
1.6 KiB
C#

using AlicizaX.Resource.Runtime;
using UnityEditor;
using UnityEngine;
using UnityToolbarExtender;
namespace TEngine.Editor
{
[InitializeOnLoad]
public class EditorResourceMode
{
static EditorResourceMode()
{
ToolbarExtender.RightToolbarGUI.Add(OnToolbarGUI);
_playModeIndex = EditorPrefs.GetInt(ResourceComponent.PrefsKey, 0);
}
private const string ButtonStyleName = "Tab middle";
static GUIStyle _buttonGuiStyle;
private static readonly string[] _resourceModeNames =
{
"编辑器模式 ",
"沙盒模式",
"真机模式",
};
private static int _playModeIndex = 0;
public static int PlayModeIndex => _playModeIndex;
static void OnToolbarGUI()
{
EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode);
{
// 资源模式
int selectedIndex = EditorGUILayout.Popup(_playModeIndex, _resourceModeNames, ToolbarStyles.ToolBarButtonGuiStyle);
// ReSharper disable once RedundantCheckBeforeAssignment
if (selectedIndex != _playModeIndex)
{
Debug.Log($"更改编辑器资源运行模式 : {_resourceModeNames[selectedIndex]}");
_playModeIndex = selectedIndex;
EditorPrefs.SetInt(ResourceComponent.PrefsKey, selectedIndex);
}
GUILayout.FlexibleSpace();
GUILayout.Space(400);
}
EditorGUI.EndDisabledGroup();
}
}
}