forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoCreateComponentSystemTests.cs
More file actions
100 lines (89 loc) · 3.15 KB
/
Copy pathAutoCreateComponentSystemTests.cs
File metadata and controls
100 lines (89 loc) · 3.15 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
using System;
using NUnit.Framework;
using UnityEngine.LowLevel;
namespace Unity.Entities.Tests
{
class AutoCreateSystemsTests
{
World m_World;
World m_PreviousWorld;
PlayerLoopSystem m_PreviousPlayerLoop;
[OneTimeSetUp]
public void Setup()
{
m_PreviousWorld = World.DefaultGameObjectInjectionWorld;
DefaultWorldInitialization.Initialize("TestWorld", false);
m_World = World.DefaultGameObjectInjectionWorld;
m_PreviousPlayerLoop = PlayerLoop.GetCurrentPlayerLoop();
}
[OneTimeTearDown]
public void TearDown()
{
PlayerLoop.SetPlayerLoop(m_PreviousPlayerLoop);
World.DefaultGameObjectInjectionWorld = m_PreviousWorld;
m_World?.Dispose();
}
[Test]
public void Systems_WithoutDisableAutoCreation_AreAutoCreated()
{
Assert.IsNotNull(m_World.GetExistingSystemManaged<SystemShouldBeCreated>(), $"{nameof(SystemShouldBeCreated)} was not automatically created");
}
[Test]
public void Systems_WithDisableAutoCreation_AreNotCreated()
{
Assert.IsNull(m_World.GetExistingSystemManaged<SystemShouldNotBeCreated>(), $"{nameof(SystemShouldNotBeCreated)} was created even though it was marked with [{nameof(DisableAutoCreationAttribute)}].");
}
[Test]
public void ISystems_WithoutDisableAutoCreation_AreAutoCreated()
{
#if UNITY_EDITOR
Assert.DoesNotThrow(() => m_World.GetExistingSystem<ISystemShouldBeCreated>(), $"{nameof(ISystemShouldBeCreated)} was not automatically created");
#else
Assert.IsTrue(m_World.GetExistingSystem<ISystemShouldBeCreated>() != default, $"{nameof(ISystemShouldBeCreated)} was not automatically created");
#endif
}
[Test]
public void ISystems_WithDisableAutoCreation_AreNotCreated()
{
Assert.IsTrue(m_World.GetExistingSystem<ISystemShouldNotBeCreated>() == default, $"{nameof(ISystemShouldNotBeCreated)} was created even though it was marked with [{nameof(DisableAutoCreationAttribute)}].");
}
partial class SystemShouldBeCreated : SystemBase
{
protected override void OnUpdate()
{
}
}
[DisableAutoCreation]
partial class SystemShouldNotBeCreated : SystemBase
{
protected override void OnUpdate()
{
}
}
partial struct ISystemShouldBeCreated : ISystem
{
public void OnCreate(ref SystemState state)
{
}
public void OnDestroy(ref SystemState state)
{
}
public void OnUpdate(ref SystemState state)
{
}
}
[DisableAutoCreation]
partial struct ISystemShouldNotBeCreated : ISystem
{
public void OnCreate(ref SystemState state)
{
}
public void OnDestroy(ref SystemState state)
{
}
public void OnUpdate(ref SystemState state)
{
}
}
}
}