Esempio n. 1
0
		private IEnumerator LoadConfiguration()
		{
			config = Resource.Find<Configuration>();
			Log.mode = config.mode;

			Log.Info("AppEngine loaded setting: " + config.setting.title + " [v" + config.setting.version + "]");

			StartCoroutine(LoadScene(config.setting.loader.name, true, delegate(Scene scene)
			{
				loader = scene;
			}));

			yield return new WaitUntil(delegate
			{
				return loader.isLoaded;
			});

			Log.Info("Initializing application  ...");

			//TODO: setup resources

			states = new Dictionary<string,AppState>();
			foreach(Core.State state in config.setting.states)
			{
				StartCoroutine(LoadScene(state.name, false, delegate(Scene scene)
				{
					StateController controller = scene.FindComponentInRoot<StateController>();
					if(controller == null)
					{
						Log.Fatal("Loaded state but does not contain a StateController: " + state.name);
					}
					else
					{
						AppState appState = new AppState(scene, controller, state);
						states[appState.name] = appState;
						Log.Info("Loaded state: " + state.name);
					}
				}));

				yield return new WaitUntil(delegate
				{
					return states.ContainsKey(state.name);
				});
			}

			Log.Info("Complete; setting boot state ...");
			SetState(config.setting.bootState);
		}
Esempio n. 2
0
		public void SetState(string stateName)
		{
			loader.ToggleGameObjects(false);

			if(states.ContainsKey(stateName))
			{
				if(activeState != null)
				{
					activeState.scene.ToggleGameObjects(false);
				}

				activeState = states[stateName];
				activeState.scene.ToggleGameObjects(true);
				SceneManager.SetActiveScene(activeState.scene);

				Log.Info("Setting state: " + activeState.name);
			}
			else
			{
				Log.Error("Unable to find state to activate: " + stateName);
			}
		}