public GameObject GetGame(HackGame gameType) { var prefab = Resources.Load(gameType.prefabPath()) as GameObject; var gameObject = Instantiate(prefab) as GameObject; return(gameObject); }
public static string prefabPath(this HackGame gameType) { var result = "Games/"; switch (gameType) { case HackGame.round_ball: result += "RBGame"; break; case HackGame.puzzle: result += "PuzzleGame"; break; case HackGame.monkey: result += "MonkeyGame"; break; case HackGame.globe: result += "GlobeGame"; break; case HackGame.disk: result += "DiskGame"; break; default: Assert.IsTrue(false, "prefab path for hack game '" + gameType.ToString() + "' is not defined"); break; } return(result); }
// private ILogger logger = Debug.logger; // List<ProjectScenes> scenesStack = new List<ProjectScenes>(); // List<SceneState> statesStack = new List<SceneState>(); // public void RunScene (ProjectScenes scene, SceneState state = null) { // var sceneToLoad = scene.sceneIndex(); // var currentSceneState = (GameObject.Find("SceneCallbacks") as GameObject).GetComponent<ICallableScene>().GetState(); // var curScene = SceneManager.GetActiveScene().name; // UnityEngine.Events.UnityAction<Scene, Scene> loadCallback = null; // loadCallback = (Scene prev, Scene cur) => { // logger.Log("SceneManagement", "activeSceneChanged callback " + curScene + " -> " + sceneToLoad.ToString(), this); // logger.Log("SceneManagement", "prev: " + prev.name, this); // logger.Log("SceneManagement", "cur: " + cur.name, this); // var newSceneCallable = GameObject.Find("SceneCallbacks").GetComponent<ICallableScene>(); // newSceneCallable.SetState(state == null ? null : state); // SceneManager.activeSceneChanged -= loadCallback; // }; // SceneManager.activeSceneChanged += loadCallback; // scenesStack.Add((ProjectScenes)SceneManager.GetActiveScene().buildIndex); // statesStack.Add(currentSceneState); // SceneManager.LoadScene(scene.sceneIndex()); // } // public void ReturnScene () { // var sceneToLoad = scenesStack[scenesStack.Count-1]; scenesStack.RemoveAt(scenesStack.Count - 1); // var stateToLoad = statesStack[statesStack.Count-1]; statesStack.RemoveAt(statesStack.Count - 1); // var currentSceneState = (GameObject.Find("SceneCallbacks") as GameObject).GetComponent<ICallableScene>().GetState(); // var curScene = SceneManager.GetActiveScene().name; // UnityEngine.Events.UnityAction<Scene, Scene> loadCallback = null; // loadCallback = (Scene prev, Scene cur) => { // logger.Log("SceneManagement", "activeSceneChanged callback " + curScene + " -> " + sceneToLoad.ToString()); // logger.Log("SceneManagement", "prev: " + prev.name, this); // logger.Log("SceneManagement", "cur: " + cur.name, this); // var newSceneCallable = GameObject.Find("SceneCallbacks").GetComponent<ICallableScene>(); // newSceneCallable.SetState(stateToLoad); // newSceneCallable.ReturnFromSceneWithState(currentSceneState); // SceneManager.activeSceneChanged -= loadCallback; // }; // SceneManager.activeSceneChanged += loadCallback; // SceneManager.LoadScene(sceneToLoad.sceneIndex()); // } public void LoadGame(HackGame game, SceneState state = null) { var currentSceneState = (GameObject.Find("SceneCallbacks") as GameObject).GetComponent <ICallableScene>().GetState(); var currentScene = SceneManager.GetActiveScene(); var gameObject = GameProvider.Instance.GetGame(game);//Instantiate(lazorsGame) as GameObject; var newSceneCallable = gameObject.GetComponent <ICallableScene>(); newSceneCallable.SetState(state); //SceneManager.SetActiveScene(currentScene); }