Enter Play Mode Option의 단점은 싱글톤이 존재하거나 Event가 제대로 등록이 안된다는 등의 문제가 있습니다.
하지만, 그런 요소가 존재하지 않고 빠르게 무언가를 테스트 할 때에는 Enter Play Mode Option은 엄청나게 개발 속도를 단축시켜주는 기능입니다.
아래는 토글 방식으로 Enter Play Mode Option을 끄고 켤 수 있는 스크립트입니다.
using UnityEditor;
using UnityEngine;
using UnityToolbarExtender;
[InitializeOnLoad]
public class EditorPlayModeSettingsToggle
{
private static bool enterPlayModeOptionsEnabled;
private static EnterPlayModeOptions enterPlayModeOptions;
private const string EnterPlayModeOptionsEnabledPrefKey = "EnterPlayModeOptionsEnabled";
private const string EnterPlayModeOptionsPrefKey = "EnterPlayModeOptions";
static EditorPlayModeSettingsToggle()
{
enterPlayModeOptionsEnabled = EditorPrefs.GetBool(EnterPlayModeOptionsEnabledPrefKey, EditorSettings.enterPlayModeOptionsEnabled);
enterPlayModeOptions = (EnterPlayModeOptions)EditorPrefs.GetInt(EnterPlayModeOptionsPrefKey, (int)EditorSettings.enterPlayModeOptions);
ToolbarExtender.LeftToolbarGUI.Add(ShowToggle);
}
private static void ShowToggle()
{
EditorGUI.BeginChangeCheck();
GUILayout.BeginHorizontal();
GUIStyle toggleStyle = new GUIStyle(GUI.skin.toggle);
toggleStyle.normal.textColor = toggleStyle.onNormal.textColor = enterPlayModeOptionsEnabled ? Color.red : Color.green;
toggleStyle.hover.textColor = toggleStyle.onHover.textColor = enterPlayModeOptionsEnabled ? Color.red : Color.green;
toggleStyle.active.textColor = toggleStyle.onActive.textColor = enterPlayModeOptionsEnabled ? Color.red : Color.green;
toggleStyle.focused.textColor = toggleStyle.onFocused.textColor = enterPlayModeOptionsEnabled ? Color.red : Color.green;
enterPlayModeOptionsEnabled = GUILayout.Toggle(enterPlayModeOptionsEnabled, "Play Mode Options Enable", toggleStyle);
GUILayout.EndHorizontal();
if (EditorGUI.EndChangeCheck())
{
EditorSettings.enterPlayModeOptionsEnabled = enterPlayModeOptionsEnabled;
EditorPrefs.SetBool(EnterPlayModeOptionsEnabledPrefKey, enterPlayModeOptionsEnabled);
EditorSettings.enterPlayModeOptions = enterPlayModeOptions;
EditorPrefs.SetInt(EnterPlayModeOptionsPrefKey, (int)enterPlayModeOptions);
}
}
}