Files
ProjectTinySamples/TinyGems/Assets/Scripts/Runtime/CenterObjectSystem.cs
T
AbdulandGitHub a2441db455 Update tiny samples to 0.29 preview (#14)
* Update tiny samples to 0.29 preview

* Add project settings
2020-08-25 21:23:11 -07:00

36 lines
1.0 KiB
C#

using Unity.Collections;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
namespace Unity.TinyGems
{
[UpdateAfter(typeof(HudSystem))]
public class CenterObjectSystem : SystemBase
{
protected override void OnCreate()
{
RequireSingletonForUpdate<CellManager>();
}
protected override void OnUpdate()
{
var cmdBuffer = new EntityCommandBuffer(Allocator.Temp);
var cellMan = GetSingleton<CellManager>();
Entities
.WithAll<CenterObjectTag>()
.ForEach((
ref Translation translation,
in Entity entity) =>
{
var x = cellMan.MaxCol * 0.5f;
var y = cellMan.MaxRow * 0.5f;
translation.Value = new float3(x, y, translation.Value.z);
cmdBuffer.RemoveComponent<CenterObjectTag>(entity);
}).Run();
cmdBuffer.Playback(EntityManager);
}
}
}