CountOfRoomsProperty.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // --------------------------------------------------------------------------------------------------------------------
  2. // <copyright file="CountOfRoomsProperty.cs" company="Exit Games GmbH">
  3. // Part of: Pun Cockpit
  4. // </copyright>
  5. // <author>developer@exitgames.com</author>
  6. // --------------------------------------------------------------------------------------------------------------------
  7. using UnityEngine.UI;
  8. using Photon.Realtime;
  9. namespace Photon.Pun.Demo.Cockpit
  10. {
  11. /// <summary>
  12. /// PhotonNetwork.CountOfRooms UIs property.
  13. /// </summary>
  14. public class CountOfRoomsProperty : PropertyListenerBase
  15. {
  16. public Text Text;
  17. int _cache = -1;
  18. void Update()
  19. {
  20. if (PhotonNetwork.NetworkingClient.Server == ServerConnection.MasterServer)
  21. {
  22. if (PhotonNetwork.CountOfRooms != _cache)
  23. {
  24. _cache = PhotonNetwork.CountOfRooms;
  25. Text.text = _cache.ToString();
  26. this.OnValueChanged();
  27. }
  28. }
  29. else
  30. {
  31. if (_cache != -1)
  32. {
  33. _cache = -1;
  34. Text.text = "n/a";
  35. }
  36. }
  37. }
  38. }
  39. }