mirror of
https://github.com/hanzoai/ProjectTinySamples.git
synced 2026-09-24 00:01:34 +00:00
36 lines
1.0 KiB
C#
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);
|
|
}
|
|
}
|
|
} |