CurrentRoomExpectedUsersProperty.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // --------------------------------------------------------------------------------------------------------------------
  2. // <copyright file="CurrentRoomExpectedUsersProperty.cs" company="Exit Games GmbH">
  3. // Part of: Pun Cockpit
  4. // </copyright>
  5. // <author>developer@exitgames.com</author>
  6. // --------------------------------------------------------------------------------------------------------------------
  7. using System.Linq;
  8. using UnityEngine.UI;
  9. namespace Photon.Pun.Demo.Cockpit
  10. {
  11. /// <summary>
  12. /// PhotonNetwork.CurrentRoom.ExpectedUsers UI property.
  13. /// </summary>
  14. public class CurrentRoomExpectedUsersProperty : PropertyListenerBase
  15. {
  16. public Text Text;
  17. string[] _cache = null;
  18. void Update()
  19. {
  20. if (PhotonNetwork.CurrentRoom == null || PhotonNetwork.CurrentRoom.ExpectedUsers == null)
  21. {
  22. if (_cache != null)
  23. {
  24. _cache = null;
  25. Text.text = "n/a";
  26. }
  27. return;
  28. }
  29. if (_cache == null || (PhotonNetwork.CurrentRoom.ExpectedUsers != null && !PhotonNetwork.CurrentRoom.ExpectedUsers.SequenceEqual(_cache)))
  30. {
  31. Text.text = string.Join("\n", PhotonNetwork.CurrentRoom.ExpectedUsers);
  32. this.OnValueChanged();
  33. return;
  34. }
  35. if (PhotonNetwork.CurrentRoom.ExpectedUsers == null && _cache != null)
  36. {
  37. Text.text = string.Join("\n", PhotonNetwork.CurrentRoom.ExpectedUsers);
  38. this.OnValueChanged();
  39. return;
  40. }
  41. }
  42. }
  43. }