120 lines
3.8 KiB
C#
120 lines
3.8 KiB
C#
using UnityEditor;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
namespace EscapeRoomEngine.Engine.Runtime.Editor
|
|
{
|
|
#if UNITY_EDITOR
|
|
/// <summary>
|
|
/// An <see cref="EditorWindow"/> used to test the <see cref="Engine"/>.
|
|
/// </summary>
|
|
public class EngineEditor : EditorWindow
|
|
{
|
|
private bool _registeredUpdateEvent;
|
|
|
|
private Button
|
|
_passToNextRoomButton,
|
|
_skipCurrentRoomButton,
|
|
_skipAndPassButton,
|
|
_cameraUpButton,
|
|
_cameraDownButton;
|
|
|
|
[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);
|
|
_skipAndPassButton = new Button(SkipAndPass)
|
|
{
|
|
text = "Skip Current And Pass To Next Room"
|
|
};
|
|
rootVisualElement.Add(_skipAndPassButton);
|
|
_cameraUpButton = new Button(CameraUp)
|
|
{
|
|
text = "Camera ↑"
|
|
};
|
|
rootVisualElement.Add(_cameraUpButton);
|
|
_cameraDownButton = new Button(CameraDown)
|
|
{
|
|
text = "Camera ↓"
|
|
};
|
|
rootVisualElement.Add(_cameraDownButton);
|
|
|
|
EditorApplication.playModeStateChanged += _ => UpdateUI();
|
|
UpdateUI();
|
|
}
|
|
|
|
private void PassToNextRoom()
|
|
{
|
|
if (Engine.Instance && EditorApplication.isPlaying)
|
|
{
|
|
Engine.Instance.CurrentRoom.Match(some: room => room.EnterRoom());
|
|
UpdateUI();
|
|
}
|
|
}
|
|
|
|
private void SkipCurrentRoom()
|
|
{
|
|
if (Engine.Instance && EditorApplication.isPlaying)
|
|
{
|
|
Engine.Instance.CurrentRoom.Match(some: room => room.SkipRoom());
|
|
UpdateUI();
|
|
}
|
|
}
|
|
|
|
private void SkipAndPass()
|
|
{
|
|
if (Engine.Instance && EditorApplication.isPlaying)
|
|
{
|
|
Engine.Instance.CurrentRoom.Match(some: room => room.SkipRoom());
|
|
Engine.Instance.CurrentRoom.Match(some: room => room.EnterRoom());
|
|
UpdateUI();
|
|
}
|
|
}
|
|
|
|
private void CameraUp()
|
|
{
|
|
SceneView.lastActiveSceneView.pivot += new Vector3(0, 400, 0);
|
|
}
|
|
|
|
private void CameraDown()
|
|
{
|
|
SceneView.lastActiveSceneView.pivot += new Vector3(0, -400, 0);
|
|
}
|
|
|
|
private void UpdateUI()
|
|
{
|
|
if (Engine.Instance && EditorApplication.isPlaying)
|
|
{
|
|
if (!_registeredUpdateEvent)
|
|
{
|
|
Engine.Instance.UpdateUIEvent += UpdateUI;
|
|
_registeredUpdateEvent = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_registeredUpdateEvent = false;
|
|
}
|
|
|
|
_passToNextRoomButton.SetEnabled(EditorApplication.isPlaying && Engine.Instance && Engine.Instance.NumberOfRooms > 1);
|
|
_skipCurrentRoomButton.SetEnabled(EditorApplication.isPlaying && Engine.Instance && Engine.Instance.NumberOfRooms > 0);
|
|
_skipAndPassButton.SetEnabled(EditorApplication.isPlaying && Engine.Instance && Engine.Instance.NumberOfRooms > 0);
|
|
}
|
|
}
|
|
#endif
|
|
} |