private void InitializeConsole(IContainer container) { // NOTE DebugConsole is based on some adapted solution found in Internet var consoleGameObject = new GameObject("_DebugConsole_"); _console = consoleGameObject.AddComponent <DebugConsole>(); container.RegisterInstance(_console); // that is not nice, but we need to use commands registered in DI with their dependencies _console.SetContainer(container); _trace = new DebugConsoleTrace(_console); _console.IsOpen = true; UnityMainThreadDispatcher.RegisterUnhandledExceptionCallback(ex => _trace.Error("FATAL", ex, "Unhandled exception")); }
void OnEnable() { Assert.raiseExceptions = true; Centre = new GeoCoordinate(CentreLatitude, CentreLongitude); Scheduler.MainThread = UnityMainThreadScheduler.MainThread; m_container = new Container(); m_messageBus = new MessageBus(); m_trace = new UnityTrace(); UnityMainThreadDispatcher.RegisterUnhandledExceptionCallback( ex => m_trace.Error("Fatal", ex, "Unhandled exception")); m_container.RegisterInstance(this); m_container.RegisterInstance(new MapGenTileExporter(this)); m_container.RegisterInstance <ITrace>(m_trace); m_container.RegisterInstance <IPathResolver>(new PathResolver()); m_container.RegisterInstance(m_messageBus); m_container.Register(Component.For <IFileSystemService>().Use <FileSystemService>().Singleton()); Config = ConfigBuilder.GetDefault() .SetTileSettings(TileSize, 40) .SetRenderOptions( RenderMode.Scene, new Rectangle2d(0, 0, TileSize, TileSize)) .Build(); m_gameRunner = new GameRunner(m_container, Config); m_gameRunner.RegisterPlugin <MapGenBootstrapper>("mapgen", this); m_gameRunner.Bootstrap(); Observable.Start( () => { m_tileController = GetService <ITileController>(); m_gameRunner.RunGame(Centre); IsInitialized = true; }, Scheduler.ThreadPool); }