Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Last active February 19, 2019 15:20
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/9e224e44521fda271171f2320f495a5e to your computer and use it in GitHub Desktop.
Save tsubaki/9e224e44521fda271171f2320f495a5e to your computer and use it in GitHub Desktop.
GetSingletonのサンプル
using UnityEngine;
using Unity.Entities;
public class DamageSystem : ComponentSystem
{
protected override void OnCreateManager()
{
RequireSingletonForUpdate<Score>(); // Scoreがある場合のみSystemが動作するようにする
}
protected override void OnUpdate()
{
if (Input.GetMouseButtonDown(0))
{
var newValue = GetSingleton<Score>();
newValue.Value += 1;
SetSingleton(newValue);
}
}
}
public class GUISystem : ComponentSystem
{
protected override void OnCreateManager()
{
RequireSingletonForUpdate<Score>(); // Scoreがある場合のみSystemが動作するようにする
}
protected override void OnUpdate()
{
Debug.Log(GetSingleton<Score>().Value);
}
}
using Unity.Entities;
[System.Serializable]
public struct Score : IComponentData
{
public int Value;
}
public class ScoreProxy : ComponentDataProxy<Score> { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment