DebugManager.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //-----------------------------------------------------------------------------
  2. // DebugManager.cs
  3. //
  4. // Microsoft XNA Community Game Platform
  5. // Copyright (C) Microsoft Corporation. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. using Microsoft.Xna.Framework;
  8. using Microsoft.Xna.Framework.Graphics;
  9. using Microsoft.Xna.Framework.Content;
  10. namespace PerformanceMeasuring.GameDebugTools
  11. {
  12. /// <summary>
  13. /// DebugManager class that holds graphics resources for debug
  14. /// </summary>
  15. public class DebugManager : DrawableGameComponent
  16. {
  17. // the name of the font to load
  18. private string debugFont;
  19. /// <summary>
  20. /// Gets a sprite batch for debug.
  21. /// </summary>
  22. public SpriteBatch SpriteBatch { get; private set; }
  23. /// <summary>
  24. /// Gets white texture.
  25. /// </summary>
  26. public Texture2D WhiteTexture { get; private set; }
  27. /// <summary>
  28. /// Gets SpriteFont for debug.
  29. /// </summary>
  30. public SpriteFont DebugFont { get; private set; }
  31. public DebugManager(Game game, string debugFont)
  32. : base(game)
  33. {
  34. // Added as a Service.
  35. Game.Services.AddService(typeof(DebugManager), this);
  36. this.debugFont = debugFont;
  37. // This component doesn't need be call neither update nor draw.
  38. this.Enabled = false;
  39. this.Visible = false;
  40. }
  41. protected override void LoadContent()
  42. {
  43. // Load debug content.
  44. SpriteBatch = new SpriteBatch(GraphicsDevice);
  45. DebugFont = Game.Content.Load<SpriteFont>(debugFont);
  46. // Create white texture.
  47. WhiteTexture = new Texture2D(GraphicsDevice, 1, 1);
  48. Color[] whitePixels = new Color[] { Color.White };
  49. WhiteTexture.SetData<Color>(whitePixels);
  50. base.LoadContent();
  51. }
  52. }
  53. }