ChatAppIdCheckerUI.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. #if PHOTON_UNITY_NETWORKING
  9. using Photon.Pun;
  10. #endif
  11. namespace Photon.Chat.Demo
  12. {
  13. /// <summary>
  14. /// This is used in the Editor Splash to properly inform the developer about the chat AppId requirement.
  15. /// </summary>
  16. [ExecuteInEditMode]
  17. public class ChatAppIdCheckerUI : MonoBehaviour
  18. {
  19. public Text Description;
  20. public bool WizardOpenedOnce; // avoid opening the wizard again and again
  21. // TODO: maybe this can run on Start(), not on Update()?!
  22. public void Update()
  23. {
  24. bool showWarning = false;
  25. string descriptionText = string.Empty;
  26. #if PHOTON_UNITY_NETWORKING
  27. showWarning = string.IsNullOrEmpty(PhotonNetwork.PhotonServerSettings.AppSettings.AppIdChat);
  28. if (showWarning)
  29. {
  30. descriptionText = "<Color=Red>WARNING:</Color>\nPlease setup a Chat AppId in the PhotonServerSettings file.";
  31. }
  32. #else
  33. ChatGui cGui = FindObjectOfType<ChatGui>(); // TODO: this could be a serialized reference instead of finding this each time
  34. showWarning = cGui == null || string.IsNullOrEmpty(cGui.chatAppSettings.AppIdChat);
  35. if (showWarning)
  36. {
  37. descriptionText = "<Color=Red>Please setup the Chat AppId.\nOpen the setup panel: Window, Photon Chat, Setup.</Color>";
  38. #if UNITY_EDITOR
  39. if (!WizardOpenedOnce)
  40. {
  41. WizardOpenedOnce = true;
  42. UnityEditor.EditorApplication.ExecuteMenuItem("Window/Photon Chat/Setup");
  43. }
  44. #endif
  45. }
  46. #endif
  47. this.Description.text = descriptionText;
  48. }
  49. }
  50. }