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


C# IServiceLocator.?.GetInstance方法代码示例

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


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

示例1: BasicGraphicsScreen

        //--------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="BasicGraphicsScreen"/> class.
        /// </summary>
        /// <param name="services">The services.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="services"/> is <see langword="null"/>.
        /// </exception>
        public BasicGraphicsScreen(IServiceLocator services)
            : base(services?.GetInstance<IGraphicsService>())
        {
            if (services == null)
                throw new ArgumentNullException(nameof(services));

            _meshRenderer = new MeshRenderer();
            _billboardRenderer = new BillboardRenderer(GraphicsService, 2048);

            var contentManager = services.GetInstance<ContentManager>();
            var spriteFont = contentManager.Load<SpriteFont>("DigitalRune.Editor.Game/Fonts/DejaVuSans");
            DebugRenderer = new DebugRenderer(GraphicsService, spriteFont);

            Scene = new Scene();
        }
开发者ID:,项目名称:,代码行数:23,代码来源:

示例2: DebugGraphicsScreen

        //--------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="DebugGraphicsScreen" /> class.
        /// </summary>
        /// <param name="services">The services.</param>
        public DebugGraphicsScreen(IServiceLocator services)
            : base(services?.GetInstance<IGraphicsService>())
        {
            if (services == null)
                throw new ArgumentNullException(nameof(services));

            Coverage = GraphicsScreenCoverage.Partial;
            _spriteBatch = GraphicsService.GetSpriteBatch();
            _whiteTexture = GraphicsService.GetDefaultTexture2DWhite();

            var contentManager = services.GetInstance<ContentManager>();
            var spriteFont = contentManager.Load<SpriteFont>("DigitalRune.Editor.Game/Fonts/DejaVuSans");
            DebugRenderer = new DebugRenderer(GraphicsService, spriteFont);
            _internalDebugRenderer = new DebugRenderer(GraphicsService, spriteFont);

            // To count the update frame rate, we handle the GameLogicUpdating event.
            // (We cannot use GraphicsScreen.OnUpdate because it is only called at the same rate if
            // the graphics screen is registered in the graphics service. If it is not registered,
            // then OnUpdate and OnRender are always called together.)
            var editor = services.GetInstance<IEditorService>();
            _gameExtension = editor.Extensions.OfType<GameExtension>().FirstOrDefault();
            if (_gameExtension != null)
                _gameExtension.GameLogicUpdating += OnGameLogicUpdating;
        }
开发者ID:,项目名称:,代码行数:29,代码来源:


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