Created
March 21, 2020 16:14
-
-
Save jeffvella/9acc6681d16e8a5df15a12cd435549af to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public struct MyComponent : IComponentData | |
| { | |
| public Entity Reference; | |
| public int Value; | |
| } | |
| public struct MyElement : IBufferElementData | |
| { | |
| public Entity Reference; | |
| public int Value; | |
| } | |
| public class MySystem : SystemBase | |
| { | |
| protected override void OnUpdate() | |
| { | |
| var ecb = new EntityCommandBuffer(Allocator.Temp); | |
| var entity = ecb.CreateEntity(); | |
| ecb.AddComponent(entity, new MyComponent | |
| { | |
| Reference = entity, | |
| Value = 42, | |
| }); | |
| var buffer = ecb.AddBuffer<MyElement>(entity); | |
| buffer.Add(new MyElement | |
| { | |
| Reference = entity, | |
| Value = 41 | |
| }); | |
| ecb.Playback(EntityManager); | |
| var createdEntity = GetSingletonEntity<MyComponent>(); | |
| var createdComponent = GetSingleton<MyComponent>(); | |
| Assert.AreEqual(createdComponent.Reference, createdEntity); | |
| Assert.AreNotEqual(createdEntity, entity); | |
| Assert.AreEqual(createdComponent.Value, 42); | |
| var createdBuffer = EntityManager.GetBuffer<MyElement>(createdEntity); | |
| Assert.AreEqual(createdBuffer[0].Reference, createdEntity); | |
| Assert.AreEqual(createdBuffer[0].Value, 41); | |
| } | |
| } | |
| [Test] | |
| unsafe public void ECBReferenceTest() | |
| { | |
| World.GetOrCreateSystem<MySystem>().Update(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment