コード例 #1
0
        public void InitializeFramework(ConfigBuilder configBuilder, Action <CompositionRoot> initAction)
        {
            IsInitialized = false;

            // Need to dispose all previously used components as we're going to create new ones.
            if (_container != null)
            {
                _container.Dispose();
            }

            // create default container which should not be exposed outside to avoid Service Locator pattern.
            _container = new Container();

            // create trace to log important messages
            _trace = new DebugConsoleTrace();

            // UtyMap requires some files/directories to be precreated.
            InstallationApi.EnsureFileHierarchy(_trace);

            // Setup RX configuration.
            UnityScheduler.SetDefaultForUnity();

            // subscribe to unhandled exceptions in RX
            MainThreadDispatcher.RegisterUnhandledExceptionCallback(ex =>
                                                                    _trace.Error(FatalCategoryName, ex, "Unhandled exception"));

            try
            {
                var config = configBuilder
                             .SetStringIndex("Index/")
                             .SetSpatialIndex("Index/")
                             .Build();

                // create entry point for utymap functionallity
                _compositionRoot = new CompositionRoot(_container, config)
                                   .RegisterAction((c, _) => c.RegisterInstance <ITrace>(_trace))
                                   .RegisterAction((c, _) => c.Register(Component.For <IPathResolver>().Use <DemoPathResolver>()))
                                   .RegisterAction((c, _) => c.Register(Component.For <IModelBuilder>().Use <DemoModelBuilder>()))
                                   .RegisterAction((c, _) => c.Register(Component.For <INetworkService>().Use <DemoNetworkService>()))
                                   .RegisterAction((c, _) => c.Register(Component.For <CustomizationService>().Use <CustomizationService>()))
                                   .RegisterAction((c, _) => c.Register(Component.For <Stylesheet>().Use <Stylesheet>(@"MapCss/default/default.mapcss")));

                // this is the way to insert custom extensions from outside. You may need to do it for
                // some scenes.
                initAction(_compositionRoot);

                // setup object graph
                _compositionRoot.Setup();

                IsInitialized = true;
            }
            catch (Exception ex)
            {
                _trace.Error(FatalCategoryName, ex, "Cannot setup object graph.");
                throw;
            }
        }
コード例 #2
0
ファイル: ApplicationManager.cs プロジェクト: 5l1v3r1/demo-2
        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();
            }
コード例 #3
0
        void Start()
        {
            _startCoordinate = PositionConfiguration.StartPosition;
            _geoCoder        = ApplicationManager.Instance.GetService <IGeocoder>();

            _trace = ApplicationManager.Instance.GetService <ITrace>() as DebugConsoleTrace;
            if (_trace != null)
            {
                _trace.SetUIText(StatusText);
            }

            if (AddressText != null)
            {
                StartCoroutine(RequestAddress());
            }
        }