forked from MonoGame/MonoGame.Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScene.cs
More file actions
106 lines (91 loc) · 2.84 KB
/
Scene.cs
File metadata and controls
106 lines (91 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
namespace MonoGameLibrary.Scenes;
public abstract class Scene : IDisposable
{
/// <summary>
/// Gets the ContentManager used for loading scene-specific assets.
/// </summary>
/// <remarks>
/// Assets loaded through this ContentManager will be automatically unloaded when this scene ends.
/// </remarks>
protected ContentManager Content { get; }
/// <summary>
/// Gets a value that indicates if the scene has been disposed of.
/// </summary>
public bool IsDisposed { get; private set; }
/// <summary>
/// Creates a new scene instance.
/// </summary>
public Scene()
{
// Create a content manager for the scene
Content = new ContentManager(Core.Content.ServiceProvider);
// Set the root directory for content to the same as the root directory
// for the game's content.
Content.RootDirectory = Core.Content.RootDirectory;
}
// Finalizer, called when object is cleaned up by garbage collector.
~Scene() => Dispose(false);
/// <summary>
/// Initializes the scene.
/// </summary>
/// <remarks>
/// When overriding this in a derived class, ensure that base.Initialize()
/// still called as this is when LoadContent is called.
/// </remarks>
public virtual void Initialize()
{
LoadContent();
}
/// <summary>
/// Override to provide logic to load content for the scene.
/// </summary>
public virtual void LoadContent() { }
/// <summary>
/// Unloads scene-specific content.
/// </summary>
public virtual void UnloadContent()
{
Content.Unload();
}
/// <summary>
/// Updates this scene.
/// </summary>
/// <param name="gameTime">A snapshot of the timing values for the current frame.</param>
public virtual void Update(GameTime gameTime) { }
/// <summary>
/// Draws this scene.
/// </summary>
/// <param name="gameTime">A snapshot of the timing values for the current frame.</param>
public virtual void Draw(GameTime gameTime) { }
/// <summary>
/// Disposes of this scene.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary>
/// Disposes of this scene.
/// </summary>
/// <param name="disposing">'
/// Indicates whether managed resources should be disposed. This value is only true when called from the main
/// Dispose method. When called from the finalizer, this will be false.
/// </param>
protected virtual void Dispose(bool disposing)
{
if (IsDisposed)
{
return;
}
if (disposing)
{
UnloadContent();
Content.Dispose();
}
IsDisposed = true;
}
}