GruppeC/frontend/SmartLectureRoom/Assets/SmartRoom/Editor/SmartRoomSceneSetup.cs

50 lines
1.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System.IO;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
namespace SmartRoom.EditorTools
{
/// <summary>
/// Legt beim ersten Öffnen des Projekts die Szene "Assets/Scenes/SmartRoom.unity" an und öffnet sie.
/// Menü: Smart Room → Szene öffnen / neu erstellen.
/// </summary>
[InitializeOnLoad]
static class SmartRoomSceneSetup
{
const string ScenePath = "Assets/Scenes/SmartRoom.unity";
static SmartRoomSceneSetup()
{
if (SessionState.GetBool("SmartRoom.SetupChecked", false)) return;
SessionState.SetBool("SmartRoom.SetupChecked", true);
EditorApplication.delayCall += () =>
{
if (EditorApplication.isPlayingOrWillChangePlaymode) return;
if (!File.Exists(ScenePath)) CreateScene();
};
}
[MenuItem("Smart Room/Szene öffnen")]
static void OpenScene()
{
if (!File.Exists(ScenePath)) { CreateScene(); return; }
if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
EditorSceneManager.OpenScene(ScenePath);
}
[MenuItem("Smart Room/Szene neu erstellen")]
static void CreateScene()
{
if (!EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo()) return;
var scene = EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects, NewSceneMode.Single);
new GameObject("SmartRoom").AddComponent<SmartRoomApp>();
Directory.CreateDirectory(Path.GetDirectoryName(ScenePath));
EditorSceneManager.SaveScene(scene, ScenePath);
EditorBuildSettings.scenes = new[] { new EditorBuildSettingsScene(ScenePath, true) };
AssetDatabase.Refresh();
Debug.Log("[Smart Room] Szene erstellt: " + ScenePath + " – Play drücken, um den Raum zu simulieren.");
}
}
}