PuzzleGame/PuzzleGameProject/Assets/Scenes/Templates/NewDungeonTemplatePipeline.cs
2025-03-05 15:54:40 +01:00

47 lines
No EOL
1.5 KiB
C#

#if UNITY_EDITOR
using DungeonGenerator;
using UnityEditor;
using UnityEditor.SceneTemplate;
using UnityEngine;
using UnityEngine.SceneManagement;
public class NewDungeonTemplatePipeline : ISceneTemplatePipeline
{
public virtual bool IsValidTemplateForInstantiation(SceneTemplateAsset sceneTemplateAsset)
{
return true;
}
public virtual void BeforeTemplateInstantiation(SceneTemplateAsset sceneTemplateAsset, bool isAdditive, string sceneName)
{
}
public virtual void AfterTemplateInstantiation(SceneTemplateAsset sceneTemplateAsset, Scene scene, bool isAdditive, string sceneName)
{
Debug.Log("Scene Template Instantiated: " + sceneName);
// Load a prefab from the Resources folder
GameObject roomsParent = Resources.Load<GameObject>("RoomsParent");
if (roomsParent != null)
{
// Instantiate the prefab inside the scene
GameObject instantiatedRoomsParent = Object.Instantiate(roomsParent);
SceneManager.MoveGameObjectToScene(instantiatedRoomsParent, scene); // Ensure it's part of the scene
DungeonMapLoader mapLoader = new DungeonMapLoader();
string dungeonMapPath = EditorUtility.OpenFilePanel("Select Dungeon", "Assets", "json");
mapLoader.AddDungeonRoomsToGameObject(instantiatedRoomsParent, dungeonMapPath);
Debug.Log("Dungeon loaded from file.");
}
else
{
Debug.LogError("DungeonPrefab not found in Resources!");
}
}
}
#endif