Advertisement
maxkhl

Scene.cs

Jan 7th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.91 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Microsoft.Xna.Framework;
  6.  
  7. namespace Horn_War_II
  8. {
  9.     abstract class Scene : IDisposable
  10.     {
  11.         /// <summary>
  12.         /// Gets the currently used game
  13.         /// </summary>
  14.         public HornWarII Game
  15.         {
  16.             get
  17.             {
  18.                 return SceneManager.Game;
  19.             }
  20.         }
  21.  
  22.         /// <summary>
  23.         /// Will be called by the scene manager during activation of this scene
  24.         /// </summary>
  25.         public abstract void LoadContent();
  26.  
  27.         /// <summary>
  28.         /// Will be called by the scene manager during update loop if this scene is active
  29.         /// </summary>
  30.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  31.         public abstract void Update(GameTime gameTime);
  32.  
  33.         /// <summary>
  34.         /// Will be called by the scene manager during draw loop if this scene is active
  35.         /// </summary>
  36.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  37.         public abstract void Draw(GameTime gameTime);
  38.  
  39.         /// <summary>
  40.         /// Dispose method. Will be called if this scene is released from the scene manager.
  41.         /// !This will automatically remove all components from the game! Override and remove "base.Dispose()" to disable this
  42.         /// </summary>
  43.         public virtual void Dispose()
  44.         {
  45.             //Get a copy of all components
  46.             var components = SceneManager.Game.Components.ToList();
  47.  
  48.             //Undock all components from the game
  49.             SceneManager.Game.Components.Clear();
  50.  
  51.             //Dispose all disposable components
  52.             foreach (var component in components)
  53.                 if (component.GetType().IsAssignableFrom(typeof(IDisposable)))
  54.                     ((IDisposable)component).Dispose();
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement