FriendItem.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // --------------------------------------------------------------------------------------------------------------------
  2. // <copyright company="Exit Games GmbH"/>
  3. // <summary>Demo code for Photon Chat in Unity.</summary>
  4. // <author>developer@exitgames.com</author>
  5. // --------------------------------------------------------------------------------------------------------------------
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8. namespace Photon.Chat.Demo
  9. {
  10. /// <summary>
  11. /// Friend UI item used to represent the friend status as well as message.
  12. /// It aims at showing how to share health for a friend that plays on a different room than you for example.
  13. /// But of course the message can be anything and a lot more complex.
  14. /// </summary>
  15. public class FriendItem : MonoBehaviour
  16. {
  17. [HideInInspector]
  18. public string FriendId
  19. {
  20. set { this.NameLabel.text = value; }
  21. get { return this.NameLabel.text; }
  22. }
  23. public Text NameLabel;
  24. public Text StatusLabel;
  25. public Text Health;
  26. public void Awake()
  27. {
  28. this.Health.text = string.Empty;
  29. }
  30. public void OnFriendStatusUpdate(int status, bool gotMessage, object message)
  31. {
  32. string _status;
  33. switch (status)
  34. {
  35. case 1:
  36. _status = "Invisible";
  37. break;
  38. case 2:
  39. _status = "Online";
  40. break;
  41. case 3:
  42. _status = "Away";
  43. break;
  44. case 4:
  45. _status = "Do not disturb";
  46. break;
  47. case 5:
  48. _status = "Looking For Game/Group";
  49. break;
  50. case 6:
  51. _status = "Playing";
  52. break;
  53. default:
  54. _status = "Offline";
  55. break;
  56. }
  57. this.StatusLabel.text = _status;
  58. if (gotMessage)
  59. {
  60. string _health = string.Empty;
  61. if (message != null)
  62. {
  63. string[] _messages = message as string[];
  64. if (_messages != null && _messages.Length >= 2)
  65. {
  66. _health = (string)_messages[1] + "%";
  67. }
  68. }
  69. this.Health.text = _health;
  70. }
  71. }
  72. }
  73. }