45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
using UnityEditor;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
namespace Escape_Room_Engine.Engine.Scripts.Editor
|
|
{
|
|
public class EngineEditor : EditorWindow
|
|
{
|
|
private Button _generateRoomButton;
|
|
|
|
[MenuItem("Window/Engine/Engine Editor")]
|
|
public static void ShowEditor()
|
|
{
|
|
var window = GetWindow<EngineEditor>();
|
|
window.titleContent = new GUIContent("Engine Editor");
|
|
}
|
|
|
|
public void CreateGUI()
|
|
{
|
|
_generateRoomButton = new Button(GenerateRoom);
|
|
|
|
rootVisualElement.Add(_generateRoomButton);
|
|
|
|
EditorApplication.playModeStateChanged += _ => UpdateUI();
|
|
UpdateUI();
|
|
}
|
|
|
|
private void GenerateRoom()
|
|
{
|
|
if (EditorApplication.isPlaying)
|
|
{
|
|
Debug.Log("Generating new room...");
|
|
Engine.DefaultEngine.DisposeOldestRoom();
|
|
Engine.DefaultEngine.GenerateRoom();
|
|
UpdateUI();
|
|
}
|
|
}
|
|
|
|
private void UpdateUI()
|
|
{
|
|
_generateRoomButton.SetEnabled(EditorApplication.isPlaying);
|
|
_generateRoomButton.text = Engine.DefaultEngine.NumberOfRooms == 0 ? "Generate Room" : "Regenerate Room";
|
|
}
|
|
}
|
|
} |