CountOfPlayersProperty.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // --------------------------------------------------------------------------------------------------------------------
  2. // <copyright file="CountOfPlayersProperty.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.CountOfPlayers UI property.
  13. /// </summary>
  14. public class CountOfPlayersProperty : 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.CountOfPlayers != _cache)
  23. {
  24. _cache = PhotonNetwork.CountOfPlayers;
  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. }