您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
55 行
1.9 KiB
55 行
1.9 KiB
using System;
|
|
using NUnit.Framework;
|
|
|
|
namespace Unity.Entities.Tests
|
|
{
|
|
class SingletonTests : ECSTestsFixture
|
|
{
|
|
[Test]
|
|
public void GetSetSingleton()
|
|
{
|
|
var entity = m_Manager.CreateEntity(typeof(EcsTestData));
|
|
|
|
EmptySystem.SetSingleton(new EcsTestData(10));
|
|
Assert.AreEqual(10, EmptySystem.GetSingleton<EcsTestData>().value);
|
|
}
|
|
|
|
[Test]
|
|
public void GetSetSingletonZeroThrows()
|
|
{
|
|
Assert.Throws<InvalidOperationException>(() => EmptySystem.SetSingleton(new EcsTestData()));
|
|
Assert.Throws<InvalidOperationException>(() => EmptySystem.GetSingleton<EcsTestData>());
|
|
}
|
|
|
|
[Test]
|
|
public void GetSetSingletonMultipleThrows()
|
|
{
|
|
m_Manager.CreateEntity(typeof(EcsTestData));
|
|
m_Manager.CreateEntity(typeof(EcsTestData));
|
|
|
|
Assert.Throws<InvalidOperationException>(() => EmptySystem.SetSingleton(new EcsTestData()));
|
|
Assert.Throws<InvalidOperationException>(() => EmptySystem.GetSingleton<EcsTestData>());
|
|
}
|
|
|
|
[Test]
|
|
[StandaloneFixme] // EmptySystem.ShouldRunSystem is always true in ZeroPlayer
|
|
public void RequireSingletonWorks()
|
|
{
|
|
EmptySystem.RequireSingletonForUpdate<EcsTestData>();
|
|
EmptySystem.GetEntityQuery(typeof(EcsTestData2));
|
|
|
|
m_Manager.CreateEntity(typeof(EcsTestData2));
|
|
Assert.IsFalse(EmptySystem.ShouldRunSystem());
|
|
m_Manager.CreateEntity(typeof(EcsTestData));
|
|
Assert.IsTrue(EmptySystem.ShouldRunSystem());
|
|
}
|
|
|
|
[Test]
|
|
public void HasSingletonWorks()
|
|
{
|
|
Assert.IsFalse(EmptySystem.HasSingleton<EcsTestData>());
|
|
m_Manager.CreateEntity(typeof(EcsTestData));
|
|
Assert.IsTrue(EmptySystem.HasSingleton<EcsTestData>());
|
|
}
|
|
}
|
|
}
|