Last active
August 29, 2015 14:17
-
-
Save yasuyuki-kamata/431983b83304f0fcb025 to your computer and use it in GitHub Desktop.
列挙型でゲームのステートを持ち、その変更を受け取ってConsoleにDebug.Logを出すUniRxのサンプル
This file contains hidden or 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 UniRx; | |
using UnityEngine.UI; | |
public enum GameState { | |
STATE_1, | |
STATE_2, | |
STATE_3 | |
} | |
public class UniRxChangeStateTest : MonoBehaviour | |
{ | |
[SerializeField] | |
private Button button1; | |
[SerializeField] | |
private Button button2; | |
[SerializeField] | |
private Button button3; | |
public ReactiveProperty<GameState> currentState { get; private set; } | |
void Awake() | |
{ | |
currentState = new ReactiveProperty<GameState> (GameState.STATE_1); | |
currentState.Subscribe (state => { | |
Debug.Log("change " + state.ToString("g")); | |
}); | |
button1.OnClickAsObservable () | |
.Subscribe (_ => { | |
Debug.Log("Click Button 1"); | |
currentState.Value = GameState.STATE_1; | |
}); | |
button2.OnClickAsObservable () | |
.Subscribe (_ => { | |
Debug.Log("Click Button 2"); | |
currentState.Value = GameState.STATE_2; | |
}); | |
button3.OnClickAsObservable () | |
.Subscribe (_ => { | |
Debug.Log("Click Button 3"); | |
currentState.Value = GameState.STATE_3; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment