CurrentRoomIsOpenProperty.cs 1.3 KB

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