-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathGameHelper.cs
More file actions
39 lines (30 loc) · 1018 Bytes
/
Copy pathGameHelper.cs
File metadata and controls
39 lines (30 loc) · 1018 Bytes
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
using System.Reflection;
using Microsoft.Xna.Framework;
namespace MonoGame.Extended.VideoPlayback;
/// <summary>
/// Helper class for <see cref="Game"/>. Internal use only.
/// </summary>
internal static class GameHelper
{
/// <summary>
/// Gets the running <see cref="Game"/> instance. It depends on the property name and lifecycle of <see cref="Game"/>.
/// </summary>
/// <returns>The game instance.</returns>
internal static Game? GetCurrentGame()
{
if (_gameInstanceProperty == null)
{
var t = typeof(Game);
var instanceProp = t.GetProperty("Instance", BindingFlags.Static | BindingFlags.NonPublic);
if (instanceProp == null)
{
return null;
}
_gameInstanceProperty = instanceProp;
}
var prop = _gameInstanceProperty;
var instance = (Game?)prop.GetValue(null);
return instance;
}
private static PropertyInfo? _gameInstanceProperty;
}