This repository has been archived by the owner on Jan 18, 2022. It is now read-only.
/
HybridGdkSystemTestBase.cs
62 lines (51 loc) · 2.56 KB
/
HybridGdkSystemTestBase.cs
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
using System;
using System.Collections.Generic;
using System.Reflection;
using NUnit.Framework;
using Unity.Entities;
namespace Improbable.Gdk.TestUtils
{
public abstract class HybridGdkSystemTestBase
{
private static readonly Type GameObjectArrayInjectionHookType =
typeof(GameObjectEntity).Assembly.GetType("Unity.Entities.GameObjectArrayInjectionHook");
private static readonly Type TransformAccessArrayInjectionHookType =
typeof(GameObjectEntity).Assembly.GetType("Unity.Entities.TransformAccessArrayInjectionHook");
private static readonly Type ComponentArrayInjectionHookType =
typeof(GameObjectEntity).Assembly.GetType("Unity.Entities.ComponentArrayInjectionHook");
private InjectionHook gameobjectArrayInjectionHook;
private InjectionHook transformAccessArrayInjectionHook;
private InjectionHook componentArrayInjectionHook;
[OneTimeSetUp]
public void OneTimeSetUp()
{
// This behaves the same way as Bootstrap.SetupInjectionHooks
// We have to use reflection because these classes are not exposed by default.
gameobjectArrayInjectionHook = (InjectionHook) Activator.CreateInstance(GameObjectArrayInjectionHookType);
transformAccessArrayInjectionHook =
(InjectionHook) Activator.CreateInstance(TransformAccessArrayInjectionHookType);
componentArrayInjectionHook = (InjectionHook) Activator.CreateInstance(ComponentArrayInjectionHookType);
InjectionHookSupport.RegisterHook(gameobjectArrayInjectionHook);
InjectionHookSupport.RegisterHook(transformAccessArrayInjectionHook);
InjectionHookSupport.RegisterHook(componentArrayInjectionHook);
}
[OneTimeTearDown]
public void OneTimeTearDown()
{
InjectionHookSupport.UnregisterHook(gameobjectArrayInjectionHook);
InjectionHookSupport.UnregisterHook(transformAccessArrayInjectionHook);
InjectionHookSupport.UnregisterHook(componentArrayInjectionHook);
}
public static void CleanupAllInjectionHooks()
{
var hooksFieldInfo =
typeof(InjectionHookSupport).GetField("k_Hooks", BindingFlags.Static | BindingFlags.NonPublic);
var staticValue = hooksFieldInfo.GetValue(null);
var hooks = ((List<InjectionHook>) staticValue).ToArray();
foreach (var injectionHook in hooks)
{
InjectionHookSupport.UnregisterHook(injectionHook);
}
}
}
}