initial commit
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class SceneSwitcher : MonoBehaviour
|
||||
{
|
||||
// make singleton
|
||||
public static SceneSwitcher Instance { get; private set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
SetInstance();
|
||||
}
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
SetInstance();
|
||||
}
|
||||
|
||||
private void SetInstance()
|
||||
{
|
||||
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("SceneSwitcher Instance already exists.");
|
||||
}
|
||||
}
|
||||
|
||||
public void SwitchScene(int sceneIndex)
|
||||
{
|
||||
for (var i = 0; i < transform.childCount; i++)
|
||||
{
|
||||
transform.GetChild(i).gameObject.SetActive(i == sceneIndex);
|
||||
}
|
||||
}
|
||||
|
||||
public List<(string name, int index)> GetScenes()
|
||||
{
|
||||
var scenes = new List<(string name, int index)>();
|
||||
for (var i = 0; i < transform.childCount; i++)
|
||||
{
|
||||
var child = transform.GetChild(i);
|
||||
scenes.Add((child.name, i));
|
||||
}
|
||||
return scenes;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user