MatchGUI.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. namespace Mirror.Examples.MultipleMatch
  5. {
  6. public class MatchGUI : MonoBehaviour
  7. {
  8. Guid matchId;
  9. [Header("GUI Elements")]
  10. public Image image;
  11. public Toggle toggleButton;
  12. public Text matchName;
  13. public Text playerCount;
  14. [Header("Diagnostics - Do Not Modify")]
  15. public CanvasController canvasController;
  16. public void Awake()
  17. {
  18. canvasController = FindObjectOfType<CanvasController>();
  19. toggleButton.onValueChanged.AddListener(delegate { OnToggleClicked(); });
  20. }
  21. public void OnToggleClicked()
  22. {
  23. canvasController.SelectMatch(toggleButton.isOn ? matchId : Guid.Empty);
  24. image.color = toggleButton.isOn ? new Color(0f, 1f, 0f, 0.5f) : new Color(1f, 1f, 1f, 0.2f);
  25. }
  26. public Guid GetMatchId()
  27. {
  28. return matchId;
  29. }
  30. public void SetMatchInfo(MatchInfo infos)
  31. {
  32. matchId = infos.matchId;
  33. matchName.text = "Match " + infos.matchId.ToString().Substring(0, 8);
  34. playerCount.text = infos.players + " / " + infos.maxPlayers;
  35. }
  36. }
  37. }