public static State Reducer(State state, Action action) { bool hasChanged = false; string nextStateName = Name.Reducer(state.Name, action); if (nextStateName != state.Name) { hasChanged = true; } int nextStatePlayerCount = PlayerCount.Reducer(state.PlayerCount, action); if (nextStatePlayerCount != state.PlayerCount) { hasChanged = true; } bool nextStatePlaying = Playing.Reducer(state.Playing, action); if (nextStatePlaying != state.Playing) { hasChanged = true; } bool nextStatePlayingErrored = PlayingErrored.Reducer(state.PlayingErrored, action); if (nextStatePlayingErrored != state.PlayingErrored) { hasChanged = true; } bool nextStatePlayingRequested = PlayingRequested.Reducer(state.PlayingRequested, action); if (nextStatePlayingRequested != state.PlayingRequested) { hasChanged = true; } return(hasChanged ? new State(nextStateName, nextStatePlayerCount, nextStatePlaying, nextStatePlayingErrored, nextStatePlayingRequested) : state); }
void Start() { _text = this.GetComponent <Text>(); _text.enabled = _playerCount == 1; _subscription = Provider.Store.Subscribe(state => { int nextPlayerCount = PlayerCount.Get(state); if (nextPlayerCount == _playerCount) { return; } _playerCount = nextPlayerCount; _text.enabled = _playerCount == 1; }); }