73 lines
2.2 KiB
C#
73 lines
2.2 KiB
C#
using UnityEditor;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
namespace Escape_Room_Engine.Engine.Scripts.Editor
|
|
{
|
|
public class EngineEditor : EditorWindow
|
|
{
|
|
private bool _registeredUpdateEvent;
|
|
private Button _passToNextRoomButton, _skipCurrentRoomButton;
|
|
|
|
[MenuItem("Window/Engine Editor")]
|
|
public static void ShowEditor()
|
|
{
|
|
var window = GetWindow<EngineEditor>();
|
|
window.titleContent = new GUIContent("Engine Editor");
|
|
}
|
|
|
|
public void CreateGUI()
|
|
{
|
|
_passToNextRoomButton = new Button(PassToNextRoom)
|
|
{
|
|
text = "Pass To Next Room"
|
|
};
|
|
rootVisualElement.Add(_passToNextRoomButton);
|
|
_skipCurrentRoomButton = new Button(SkipCurrentRoom)
|
|
{
|
|
text = "Skip Current Room"
|
|
};
|
|
rootVisualElement.Add(_skipCurrentRoomButton);
|
|
|
|
EditorApplication.playModeStateChanged += _ => UpdateUI();
|
|
UpdateUI();
|
|
}
|
|
|
|
private void PassToNextRoom()
|
|
{
|
|
if (EditorApplication.isPlaying)
|
|
{
|
|
Engine.DefaultEngine.HidePreviousRoom();
|
|
UpdateUI();
|
|
}
|
|
}
|
|
|
|
private void SkipCurrentRoom()
|
|
{
|
|
if (EditorApplication.isPlaying)
|
|
{
|
|
Engine.DefaultEngine.CurrentRoom.Match(some: room => room.SkipRoom());
|
|
UpdateUI();
|
|
}
|
|
}
|
|
|
|
private void UpdateUI()
|
|
{
|
|
if (EditorApplication.isPlaying)
|
|
{
|
|
if (!_registeredUpdateEvent)
|
|
{
|
|
Engine.DefaultEngine.UpdateUIEvent += UpdateUI;
|
|
_registeredUpdateEvent = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_registeredUpdateEvent = false;
|
|
}
|
|
|
|
_passToNextRoomButton.SetEnabled(EditorApplication.isPlaying && Engine.DefaultEngine.NumberOfRooms > 1);
|
|
_skipCurrentRoomButton.SetEnabled(EditorApplication.isPlaying && Engine.DefaultEngine.NumberOfRooms > 0);
|
|
}
|
|
}
|
|
} |