Last active
March 18, 2019 11:14
-
-
Save tsubaki/e833d0e41d7f8117309d7310a2e23d7b to your computer and use it in GitHub Desktop.
ECSのForEach使用例
This file contains 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
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