private void Initialize() { // Setup main thread scheduler Scheduler.MainThread = new UnityMainThreadScheduler(); // Create and register DebugConsole inside Container var container = new Container(); // Create message bus class which is way to listen for ASM events _messageBus = new MessageBus(); // Console is way to debug/investigate app behavior on real devices when // regular debugger is not applicable InitializeConsole(container); // Attach address locator which provides the way to get current address AttachAddressLocator(); // ASM should be started from non-UI thread Scheduler.ThreadPool.Schedule(() => { try { // NOTE These services should be registered inside container before GameRunner is constructed. // Trace implementation container.RegisterInstance(_trace); // Path resolver which knows about current platform container.RegisterInstance <IPathResolver>(new WinPathResolver()); // Message bus container.RegisterInstance(_messageBus); // Create ASM entry point with settings provided and register custom plugin which adds // custom logic or replaces default one var gameRunner = new GameRunner(container, @"Config/settings.json") .RegisterPlugin <DemoBootstrapper>("demo", _messageBus, _trace); // Store position observer which will listen for character movements _positionObserver = gameRunner; // Run ASM logic gameRunner.RunGame(StartPosition); _isInitialized = true; } catch (Exception ex) { _console.LogMessage(new ConsoleMessage("Error running game:" + ex, RecordType.Error, Color.red)); throw; } }); }
void SpawnCar() { try { var spawnPoint = GlobalAccess.GetRandomGarage(); var car = Instantiate(HovercarPfs.PickOne(), spawnPoint.transform.position, spawnPoint.transform.rotation); car.transform.SetParent(traffic); spawnElapsed = SpawnTimer; car.GetComponent <AICoordinator>().TakeOff(spawnPoint); } catch (Exception e) { DebugConsole.LogMessage(e.Message); } }