示例#1
0
        private void StrideUIThread()
        {
            gameForm = new EmbeddedGameForm {
                TopLevel = false, Visible = false
            };
            windowHandle = gameForm.Handle;

            initializationSignal.Set();

            PreviewGame = new PreviewGame(AssetBuilderService.EffectCompiler);
            var context = new GameContextWinforms(gameForm)
            {
                InitializeDatabase = false
            };

            // Wait for shaders to be loaded
            AssetBuilderService.WaitForShaders();

            // TODO: For now we stop if there is an exception
            // Ideally, we should try to recreate the game.
            if (!DisablePreview)
            {
                PreviewGame.GraphicsDeviceManager.DeviceCreated += GraphicsDeviceManagerDeviceCreated;
                PreviewGame.Run(context);
                PreviewGame.Dispose();
            }
        }
示例#2
0
        /// <summary>
        /// Initializes the preview of an asset. This method will invoke the protected virtual method <see cref="Initialize()"/>.
        /// </summary>
        /// <param name="asset">The view model of the asset to preview.</param>
        /// <param name="builder">The preview builder that is initializing this preview.</param>
        /// <returns>A task returning an object that is the view associated to the preview.</returns>
        public async Task <object> Initialize(AssetViewModel asset, IPreviewBuilder builder)
        {
            IsRunning      = true;
            AssetViewModel = asset;
            AssetItem      = asset.AssetItem;
            Builder        = builder;
            Game           = builder.PreviewGame;

            // Copy ColorSpace to Game
            // TODO: Move this code this method and find a better pluggable way to do this.

            var gameSettings = AssetItem.Package.GetGameSettingsAssetOrDefault();

            Game.GraphicsDeviceManager.PreferredColorSpace = DetermineColorSpace();
            Game.GraphicsDeviceManager.ApplyChanges();

            RenderingMode = gameSettings.GetOrCreate <EditorSettings>().RenderingMode;

            await Initialize();

            PreviewViewModel = await ProvideViewModel();

            previewView = await ProvideView();

            FinalizeInitialization();
            return(previewView);
        }