Last active
February 19, 2019 15:20
-
-
Save tsubaki/9e224e44521fda271171f2320f495a5e to your computer and use it in GitHub Desktop.
GetSingletonのサンプル
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; | |
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); | |
} | |
} |
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 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