当前位置: 首页>>代码示例>>C#>>正文


C# ServiceProvider.AddService方法代码示例

本文整理汇总了C#中ServiceProvider.AddService方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceProvider.AddService方法的具体用法?C# ServiceProvider.AddService怎么用?C# ServiceProvider.AddService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ServiceProvider的用法示例。


在下文中一共展示了ServiceProvider.AddService方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WarpSceneRenderer

		public WarpSceneRenderer(Scene scene, int width, int height)
		{
			_scene = scene;
			_width = width;
			_height = height;
			_aspectRatio = width / (float)height;

			_device = GraphicsDevice.New(DriverType.Warp, DeviceCreationFlags.None, FeatureLevel.Level_10_1);

			var serviceProvider = new ServiceProvider();
			serviceProvider.AddService<IGraphicsDeviceService>(new GraphicsDeviceService(_device));

			_contentManager = new ContentManager(serviceProvider);
			_contentManager.Resolvers.Add(new ContentResolver());

			var viewport = new Viewport(0, 0, _width, _height);
			_device.SetViewports(viewport);

			const MSAALevel msaaLevel = MSAALevel.None;
			_depthStencilTexture = DepthStencilBuffer.New(_device, _width, _height, msaaLevel, DepthFormat.Depth24Stencil8);
			_renderTexture = RenderTarget2D.New(_device, _width, _height, msaaLevel, PixelFormat.R8G8B8A8.UNorm);

			Options = new RenderOptions();

			_effect = new BasicEffect(_device);
			_effect.EnableDefaultLighting();

			_inputLayout = VertexInputLayout.New(0, typeof(VertexPositionNormalTexture));
			_device.SetVertexInputLayout(_inputLayout);

			_meshes = new List<WarpMesh>();
			foreach (Mesh mesh in _scene.Meshes)
			{
				if (!mesh.Positions.Any())
					continue;

				var warpMesh = new WarpMesh(_device, mesh);
				_meshes.Add(warpMesh);

				warpMesh.Initialize(_contentManager);
			}
		}
开发者ID:modulexcite,项目名称:dotwarp,代码行数:42,代码来源:WarpSceneRenderer.cs

示例2: LoadTextures

        private void LoadTextures()
        {
            bool exportTexturesToFiles = false;
            Form graphicsDeviceForm = new Form();
            graphicsDeviceForm.Size = new Size(256, 256);

            PresentationParameters presentationParameters = new PresentationParameters();
            presentationParameters.IsFullScreen = false;
            presentationParameters.DeviceWindowHandle = graphicsDeviceForm.Handle;

            // We don't need an advanced adaptor. One that can support DirectX 9
            // is prefectly fine for exporting the textures.
            var adaptorQuery =
                from adaptor in GraphicsAdapter.Adapters
                where adaptor.IsProfileSupported(GraphicsProfile.Reach)
                select adaptor;

            GraphicsAdapter adapter = adaptorQuery.FirstOrDefault();

            // Fallback to the default.
            if (adapter == null) {
                adapter = GraphicsAdapter.DefaultAdapter;
            }

            GraphicsDevice graphicsDevice = new GraphicsDevice(adapter, GraphicsProfile.Reach, presentationParameters);

            ServiceProvider serviceProvider = new ServiceProvider();
            serviceProvider.AddService(typeof(IGraphicsDeviceService), new GraphicsDeviceService(graphicsDevice));

            ContentManager content = new ContentManager(serviceProvider, Path.Combine(options.TerrariaDirectory, "Content"));

            for (int i = 0; i < World.NumTiles; i++) {
                textures.tileTexture[i] = ConvertTextureToImage(content.Load<Texture2D>(@"Images\tiles_" + i));

                if (exportTexturesToFiles) {
                    textures.tileTexture[i].Save("Tile" + i + ".png", ImageFormat.Png);
                }
            }

            for (int i = 1; i < 14; i++) {
                textures.wallTexture[i] = ConvertTextureToImage(content.Load<Texture2D>(@"Images\Wall_" + i));

                if (exportTexturesToFiles) {
                    textures.wallTexture[i].Save("Wall" + i + ".png", ImageFormat.Png);
                }
            }

            for (int i = 0; i < 7; i++) {
                textures.backgroundTexture[i] = ConvertTextureToImage(content.Load<Texture2D>(@"Images\Background_" + i));

                if (exportTexturesToFiles) {
                    textures.backgroundTexture[i].Save("Background" + i + ".png", ImageFormat.Png);
                }
            }

            for (int i = 0; i < 44; i++) {
                textures.npcTexture[i] = ConvertTextureToImage(content.Load<Texture2D>(@"Images\NPC_" + i));

                if (exportTexturesToFiles) {
                    textures.npcTexture[i].Save("Npc" + i + ".png", ImageFormat.Png);
                }
            }

            for (int i = 0; i < 4; i++) {
                textures.cloudTexture[i] = ConvertTextureToImage(content.Load<Texture2D>(@"Images\Cloud_" + i));

                if (exportTexturesToFiles) {
                    textures.cloudTexture[i].Save("Cloud" + i + ".png", ImageFormat.Png);
                }
            }

            for (int i = 0; i < 2; i++) {
                textures.liquidTexture[i] = ConvertTextureToImage(content.Load<Texture2D>(@"Images\Liquid_" + i));

                if (exportTexturesToFiles) {
                    textures.liquidTexture[i].Save("Liquid" + i + ".png", ImageFormat.Png);
                }
            }

            for (int i = 0; i < 3; i++) {
                textures.treeTopTexture[i] = ConvertTextureToImage(content.Load<Texture2D>(@"Images\Tree_Tops_" + i));

                if (exportTexturesToFiles) {
                    textures.treeTopTexture[i].Save("TreeTop" + i + ".png", ImageFormat.Png);
                }
            }

            for (int i = 0; i < 3; i++) {
                textures.treeBranchTexture[i] = ConvertTextureToImage(content.Load<Texture2D>(@"Images\Tree_Branches_" + i));

                if (exportTexturesToFiles) {
                    textures.treeBranchTexture[i].Save("TreeBranch" + i + ".png", ImageFormat.Png);
                }
            }

            textures.sunTexture = ConvertTextureToImage(content.Load<Texture2D>(@"Images\Sun"));

            if (exportTexturesToFiles) {
                textures.sunTexture.Save("SunTexture.png", ImageFormat.Png);
            }
//.........这里部分代码省略.........
开发者ID:winfredwan,项目名称:Terraria-Map-Generator,代码行数:101,代码来源:MapGenerator.cs


注:本文中的ServiceProvider.AddService方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。