public void InitializeFramework(ConfigBuilder configBuilder, Action <IContainer, IMessageBus, ITrace, GameRunner> bootInitAction) { // Setup main thread scheduler Scheduler.MainThread = UnityMainThreadScheduler.MainThread; // Create and register DebugConsole inside Container _container = new Container(); // Create message bus class which is way to listen for ASM events _messageBus = new MessageBus(); // Create trace to log important messages _trace = new DebugConsoleTrace(); // Subscribe to unhandled exceptions in RX UnityMainThreadDispatcher.RegisterUnhandledExceptionCallback(ex => _trace.Error(FatalCategoryName, ex, "Unhandled exception")); // Console is way to debug/investigate app behavior on real devices when // regular debugger is not applicable CreateConsole(true); try { // NOTE These services should be registered inside container before GameRunner is constructed. // Trace implementation _container.RegisterInstance <ITrace>(_trace); // Path resolver which knows about current platform _container.RegisterInstance <IPathResolver>(new PathResolver()); // Message bus _container.RegisterInstance(_messageBus); // File system service _container.Register(Component.For <IFileSystemService>() #if UNITY_WEBPLAYER .Use <WebFileSystemService>().Singleton()); #else .Use <FileSystemService>().Singleton()); #endif // Build config with default settings var config = configBuilder #if UNITY_WEBPLAYER .SetSandbox(true) #endif .Build(); // Create ASM entry point with settings provided, register custom plugin(-s) which add(-s) // custom logic or replaces default one. Then run bootstrapping process which populates container // with defined implementations. _gameRunner = new GameRunner(_container, config); // provide the way to insert different custom extensions for different scenes bootInitAction(_container, _messageBus, _trace, _gameRunner); // run bootstrappering _gameRunner.Bootstrap(); }
/// <summary> Registers model builder type. </summary> public CustomizationService RegisterBuilder(string name, Type modelBuilderType) { Guard.IsAssignableFrom(typeof(IModelBuilder), modelBuilderType); _container.Register(Component .For <IModelBuilder>() .Use(modelBuilderType) .Named(name) .Singleton()); return(this); }
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); }
public void SetUp() { TestHelper.DisableMultiThreading(); _container = new Container(); var gameRunner = TestHelper.GetGameRunner(_container); _container.Register(Component .For <ITerrainBuilder>() .Use <TestTerrainBuilder>() .Singleton()); gameRunner.RunGame(TestHelper.BerlinTestFilePoint); _terrainBuilder = _container.Resolve <ITerrainBuilder>() as TestTerrainBuilder; _objectPool = _container.Resolve <IObjectPool>(); _stylesheet = _container.Resolve <IStylesheetProvider>().Get(); Assert.IsNotNull(_terrainBuilder); Assert.IsNotNull(_objectPool); Assert.IsNotNull(_stylesheet); }