90 lines
1.9 KiB
C#
90 lines
1.9 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Obvious.Soap;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
namespace ShiningGames.Tools
|
|
{
|
|
public class GameplayLoader : MonoBehaviour
|
|
{
|
|
private const string GameplayScenePath = "Assets/Scenes/Gameplay.unity";
|
|
|
|
[SerializeField]
|
|
private Vector3Variable startPosition;
|
|
|
|
[SerializeField]
|
|
private GameObjectVariable gameScene;
|
|
|
|
[SerializeField]
|
|
private Transform gameSceneRoot;
|
|
|
|
[SerializeField]
|
|
private List<string> _AdditiveScenesLoad;
|
|
|
|
[SerializeField]
|
|
private GameObject _GameplayPostLoads;
|
|
|
|
private void OnValidate()
|
|
{
|
|
if (!(_GameplayPostLoads == null))
|
|
{
|
|
_GameplayPostLoads.gameObject.SetActive(value: false);
|
|
}
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
SceneManager.sceneLoaded += SceneManagerOnsceneLoaded;
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
LoadScenes();
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
SceneManager.sceneLoaded -= SceneManagerOnsceneLoaded;
|
|
}
|
|
|
|
private void SceneManagerOnsceneLoaded(Scene arg0, LoadSceneMode arg1)
|
|
{
|
|
if (arg0.name == "Gameplay")
|
|
{
|
|
if (_GameplayPostLoads == null)
|
|
{
|
|
Debug.LogError("GameplayPostLoads not set");
|
|
}
|
|
else
|
|
{
|
|
_GameplayPostLoads.SetActive(value: true);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void LoadScenes()
|
|
{
|
|
gameScene.Value = gameSceneRoot.gameObject;
|
|
startPosition.Value = base.transform.position;
|
|
if (SceneManager.GetSceneByName("Gameplay").isLoaded)
|
|
{
|
|
Debug.LogError("Gameplay Scene already loaded");
|
|
SceneManagerOnsceneLoaded(SceneManager.GetSceneByName("Gameplay"), LoadSceneMode.Additive);
|
|
}
|
|
else
|
|
{
|
|
SceneManager.LoadScene("Gameplay", LoadSceneMode.Additive);
|
|
}
|
|
if (_AdditiveScenesLoad == null || _AdditiveScenesLoad.Count <= 0)
|
|
{
|
|
return;
|
|
}
|
|
foreach (string item in _AdditiveScenesLoad)
|
|
{
|
|
SceneManager.LoadScene(item.Split("/").Last().Replace(".unity", ""), LoadSceneMode.Additive);
|
|
}
|
|
}
|
|
}
|
|
}
|