ServerSettings.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // ----------------------------------------------------------------------------
  2. // <copyright file="ServerSettings.cs" company="Exit Games GmbH">
  3. // PhotonNetwork Framework for Unity - Copyright (C) 2018 Exit Games GmbH
  4. // </copyright>
  5. // <summary>
  6. // ScriptableObject defining a server setup. An instance is created as <b>PhotonServerSettings</b>.
  7. // </summary>
  8. // <author>developer@exitgames.com</author>
  9. // ----------------------------------------------------------------------------
  10. namespace Photon.Pun
  11. {
  12. using System;
  13. using System.Collections.Generic;
  14. using ExitGames.Client.Photon;
  15. using Photon.Realtime;
  16. using UnityEngine;
  17. /// <summary>
  18. /// Collection of connection-relevant settings, used internally by PhotonNetwork.ConnectUsingSettings.
  19. /// </summary>
  20. /// <remarks>
  21. /// Includes the AppSettings class from the Realtime APIs plus some other, PUN-relevant, settings.</remarks>
  22. [Serializable]
  23. [HelpURL("https://doc.photonengine.com/en-us/pun/v2/getting-started/initial-setup")]
  24. public class ServerSettings : ScriptableObject
  25. {
  26. [Tooltip("Core Photon Server/Cloud settings.")]
  27. public AppSettings AppSettings;
  28. /// <summary>Region that will be used by the Editor and Development Builds. This ensures all users will be in the same region for testing.</summary>
  29. [Tooltip("Developer build override for Best Region.")]
  30. public string DevRegion;
  31. [Tooltip("Log output by PUN.")]
  32. public PunLogLevel PunLogging = PunLogLevel.ErrorsOnly;
  33. [Tooltip("Logs additional info for debugging.")]
  34. public bool EnableSupportLogger;
  35. [Tooltip("Enables apps to keep the connection without focus.")]
  36. public bool RunInBackground = true;
  37. [Tooltip("Simulates an online connection.\nPUN can be used as usual.")]
  38. public bool StartInOfflineMode;
  39. [Tooltip("RPC name list.\nUsed as shortcut when sending calls.")]
  40. public List<string> RpcList = new List<string>(); // set by scripts and or via Inspector
  41. #if UNITY_EDITOR
  42. public bool DisableAutoOpenWizard;
  43. public bool ShowSettings;
  44. public bool DevRegionSetOnce;
  45. #endif
  46. /// <summary>Sets appid and region code in the AppSettings. Used in Editor.</summary>
  47. public void UseCloud(string cloudAppid, string code = "")
  48. {
  49. this.AppSettings.AppIdRealtime = cloudAppid;
  50. this.AppSettings.Server = null;
  51. this.AppSettings.FixedRegion = string.IsNullOrEmpty(code) ? null : code;
  52. }
  53. /// <summary>Checks if a string is a Guid by attempting to create one.</summary>
  54. /// <param name="val">The potential guid to check.</param>
  55. /// <returns>True if new Guid(val) did not fail.</returns>
  56. public static bool IsAppId(string val)
  57. {
  58. try
  59. {
  60. new Guid(val);
  61. }
  62. catch
  63. {
  64. return false;
  65. }
  66. return true;
  67. }
  68. /// <summary>Gets the "best region summary" from the preferences.</summary>
  69. /// <value>The best region code in preferences.</value>
  70. public static string BestRegionSummaryInPreferences
  71. {
  72. get { return PhotonNetwork.BestRegionSummaryInPreferences; }
  73. }
  74. /// <summary>Sets the "best region summary" in the preferences to null. On next start, the client will ping all available.</summary>
  75. public static void ResetBestRegionCodeInPreferences()
  76. {
  77. PhotonNetwork.BestRegionSummaryInPreferences = null;
  78. }
  79. /// <summary>String summary of the AppSettings.</summary>
  80. public override string ToString()
  81. {
  82. return "ServerSettings: " + this.AppSettings.ToStringFull();
  83. }
  84. }
  85. }