Last active
May 19, 2018 06:09
-
-
Save kuma360/8131f3627a22b9457dadbc049f8edcfe to your computer and use it in GitHub Desktop.
単一のEntityを動かすだけ。最小構成のECS
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
////Unity2018.2.0b4 [EntityComponentSystem(ECS) ver0.0.12-preview1] | |
using UnityEngine; | |
using Unity.Entities; | |
//IComponentDataを継承した構造体がECSの部品として使える。 | |
struct DATA : IComponentData | |
{ | |
public int val; | |
} | |
//ComponentSystemを継承したクラスは、Unity内部から自動的に呼び出される | |
class DATA_SYSTEM : ComponentSystem | |
{ | |
//ComponentSystemの中で扱うデータを定義する。 | |
struct GROUP | |
{ | |
public ComponentDataArray<DATA> _data; | |
} | |
//[Inject]の記述によって、EntityManagerが持っている「実体のデータ群」から、適切なデータを埋め込んでくれる。 | |
//「実体のデータ群」は、下記GAME_OBJECTクラスの中で自分で用意する。 | |
[Inject] GROUP group; | |
//毎フレーム呼ばれる | |
protected override void OnUpdate() | |
{ | |
for (int I = 0; I < group._data.Length; ++I) | |
{ | |
var P = group._data[I]; | |
P.val += 1; | |
group._data[I] = P; | |
} | |
} | |
} | |
class ECS_SCRIPT : MonoBehaviour | |
{ | |
private void Start() | |
{ | |
var EM = World.Active.GetOrCreateManager<EntityManager>(); | |
//Entityを一個だけ作る。 | |
EM.CreateEntity(typeof(DATA)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment