Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Last active March 18, 2019 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsubaki/e833d0e41d7f8117309d7310a2e23d7b to your computer and use it in GitHub Desktop.
Save tsubaki/e833d0e41d7f8117309d7310a2e23d7b to your computer and use it in GitHub Desktop.
ECSのForEach使用例
using UnityEngine;
using Unity.Entities;
using Unity.Transforms;
using Unity.Mathematics;
public class SampleSystem : ComponentSystem
{
protected override void OnUpdate()
{
// 要素を操作する場合(通常のECS)
Entities.ForEach( (ref Translation pos) =>{
float3 offset = new float3(0, math.cos(Time.timeSinceLevelLoad) * 0.1f, 0) ;
pos.Value += offset;
});
// Componentを取得する場合
Entities.ForEach((Transform transform, ref Translation pos) => {
// do something
});
// ISharedComponentDataを使用する場合
Entities.ForEach((GameData data, ref Translation pos) =>
{
// do something
});
}
struct GameData : ISharedComponentData { }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment