Hello,
i have a Project with diffrent scenes and i want to load this with a shortcut.
I wrote a Singleton StateManager which handle the active Scene and switching. When i switche the scenes four or five times it loads fast, but then every change load longer.
I need the same variable on different scenes, this is the reason for the StateManager.
Thanks for Help.
using UnityEngine;
using System.Collections;
public enum GameState
{
Haus = 1,
Auto = 2,
Technik = 3
};
public delegate void OnStateChangeHandler();
public class StateManager : MonoBehaviour
{
static StateManager _instance;
public event OnStateChangeHandler OnStateChange;
public bool isLeapControlling
{
get;
private set;
}
public GameState gameState
{
get;
private set;
}
public void SetGameState(GameState gameState)
{
this.gameState = gameState;
if (OnStateChange != null)
{
OnStateChange();
}
Debug.Log("GameState geändert auf: " + gameState);
}
public void SetLeapState(bool leapState)
{
this.isLeapControlling = leapState;
Debug.Log("LeapStatus: " + isLeapControlling.ToString());
}
protected StateManager()
{
}
static public bool isActive
{
get
{
return _instance != null;
}
}
static public StateManager Instance
{
get
{
if (_instance == null)
{
_instance = Object.FindObjectOfType(typeof(StateManager)) as StateManager;
if (_instance == null)
{
GameObject go = new GameObject("StateManager");
DontDestroyOnLoad(go);
_instance = go.AddComponent<StateManager>();
}
}
return _instance;
}
}
void OnApplicationQuit()
{
_instance = null;
}
}