Advertisement
SuperMeatBoy

Group Listening

Apr 4th, 2020
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. public class DeckController : MonoBehaviour {
  2. public GameObject back;
  3. public TextMeshPro cardCounter;
  4. private Contexts _contexts;
  5. private IGroup<GameEntity> _deckGroup;
  6.  
  7. private void Awake() {
  8. _contexts = Contexts.sharedInstance;
  9. _deckGroup = _contexts.game.GetGroup(GameMatcher.AllOf(GameMatcher.Card, GameMatcher.InDeck));
  10. _deckGroup.OnEntityAdded += UpdateCounter;
  11. _deckGroup.OnEntityRemoved += UpdateCounter;
  12. //_deckGroup.OnEntityAdded
  13. }
  14.  
  15. private void UpdateCounter(IGroup<GameEntity> @group, GameEntity entity, int index, IComponent component) {
  16. cardCounter.text = group.count.ToString();
  17. back.SetActive(group.count != 0);
  18. }
  19.  
  20. private void OnDestroy() {
  21. _deckGroup.OnEntityAdded -= UpdateCounter;
  22. _deckGroup.OnEntityRemoved-= UpdateCounter;
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement