PunCockpit.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  1. // --------------------------------------------------------------------------------------------------------------------
  2. // <copyright file="PunCockpit.cs" company="Exit Games GmbH">
  3. // Part of: Pun Cockpit Demo
  4. // </copyright>
  5. // <author>developer@exitgames.com</author>
  6. // --------------------------------------------------------------------------------------------------------------------
  7. using System;
  8. using System.Collections;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using UnityEngine;
  12. using UnityEngine.UI;
  13. using Photon.Pun.Demo.Cockpit.Forms;
  14. using Photon.Pun.Demo.Shared;
  15. using Photon.Realtime;
  16. using Hashtable = ExitGames.Client.Photon.Hashtable;
  17. namespace Photon.Pun.Demo.Cockpit
  18. {
  19. /// <summary>
  20. /// UI based work in progress to test out api and act as foundation when dealing with room, friends and player list
  21. /// </summary>
  22. public class PunCockpit : MonoBehaviourPunCallbacks
  23. {
  24. public static PunCockpit Instance;
  25. public static bool Embedded;
  26. public static string EmbeddedGameTitle = "";
  27. public bool debug = false;
  28. public string UserId { get; set; }
  29. public Text Title;
  30. public Text StateText; // set in inspector
  31. public Text UserIdText; // set in inspector
  32. [Header("Demo Integration")]
  33. public CanvasGroup MinimalCanvasGroup;
  34. public CanvasGroup MaximalCanvasGroup;
  35. public GameObject MinimizeButton;
  36. public GameObject MinimalUIEmbeddHelp;
  37. [Header("Connection UI")]
  38. public GameObject ConnectingLabel;
  39. public GameObject ConnectionPanel;
  40. public GameObject AdvancedConnectionPanel;
  41. public Dropdown ConnectAsDropDown;
  42. [Header("Common UI")]
  43. public GameObject InfosPanel;
  44. public GameObject MinimalUiInfosPanel;
  45. [Header("Lobby UI")]
  46. public GameObject LobbyPanel;
  47. public Selectable JoinLobbyButton;
  48. public RoomListView RoomListManager;
  49. public FriendListView FriendListManager;
  50. public GameObject RoomListMatchMakingForm;
  51. [Header("Game UI")]
  52. public GameObject GamePanel;
  53. public PlayerListView PlayerListManager;
  54. public PlayerDetailsController PlayerDetailsManager;
  55. public InputField RoomCustomPropertyInputfield;
  56. [Header("Photon Settings")]
  57. /// <summary>
  58. /// The game version override. This is one way to let the user define the gameversion, and set it properly right after we call connect to override the server settings
  59. /// Check ConnectAndJoinRandom.cs for another example of gameversion overriding
  60. /// </summary>
  61. public string GameVersionOverride = String.Empty;
  62. /// <summary>
  63. /// The reset flag for best cloud ServerSettings.
  64. /// This is one way to let the user define if bestcloud cache should be reseted when connecting.
  65. /// </summary>
  66. public bool ResetBestRegionCodeInPreferences = false;
  67. [Header("Room Options")]
  68. public int MaxPlayers = 4;
  69. public int PlayerTtl = 0;
  70. public int EmptyRoomTtl = 0;
  71. public string Plugins = "";
  72. public bool PublishUserId = true;
  73. public bool IsVisible = true;
  74. public bool IsOpen = true;
  75. //public bool CheckUserOnJoin = false;
  76. public bool CleanupCacheOnLeave = true;
  77. public bool DeleteNullProperties = false;
  78. [Header("Room Options UI")]
  79. public IntInputField PlayerTtlField;
  80. public IntInputField EmptyRoomTtlField;
  81. public IntInputField MaxPlayersField;
  82. public StringInputField PluginsField;
  83. public BoolInputField PublishUserIdField;
  84. public BoolInputField IsVisibleField;
  85. public BoolInputField IsOpenField;
  86. public BoolInputField CleanupCacheOnLeaveField;
  87. // public BoolInputField CheckUserOnJoinField;
  88. public BoolInputField DeleteNullPropertiesField;
  89. [Header("Friends Options")]
  90. public FriendListView.FriendDetail[] FriendsList =
  91. new FriendListView.FriendDetail[]{
  92. new FriendListView.FriendDetail("Joe","Joe"),
  93. new FriendListView.FriendDetail("Jane","Jane"),
  94. new FriendListView.FriendDetail("Bob","Bob")
  95. };
  96. [Header("Modal window")]
  97. public CanvasGroup ModalWindow;
  98. public RegionListView RegionListView;
  99. public Text RegionListLoadingFeedback;
  100. public void Start()
  101. {
  102. Instance = this;
  103. // doc setup
  104. DocLinks.Language = DocLinks.Languages.English;
  105. DocLinks.Product = DocLinks.Products.Pun;
  106. DocLinks.Version = DocLinks.Versions.V2;
  107. //
  108. ModalWindow.gameObject.SetActive (false);
  109. MaximalCanvasGroup.gameObject.SetActive(true);
  110. this.UserIdText.text = "";
  111. this.StateText.text = "";
  112. this.StateText.gameObject.SetActive(true);
  113. this.UserIdText.gameObject.SetActive(true);
  114. this.Title.gameObject.SetActive(true);
  115. this.ConnectingLabel.SetActive(false);
  116. this.LobbyPanel.SetActive(false);
  117. this.GamePanel.SetActive(false);
  118. if (string.IsNullOrEmpty(UserId))
  119. {
  120. UserId = "user" + Environment.TickCount % 99; //made-up username
  121. }
  122. PlayerTtlField.SetValue(this.PlayerTtl);
  123. EmptyRoomTtlField.SetValue(this.EmptyRoomTtl);
  124. MaxPlayersField.SetValue(this.MaxPlayers);
  125. PluginsField.SetValue(this.Plugins);
  126. PublishUserIdField.SetValue(this.PublishUserId);
  127. IsVisibleField.SetValue(this.IsVisible);
  128. IsOpenField.SetValue(this.IsOpen);
  129. CleanupCacheOnLeaveField.SetValue(this.CleanupCacheOnLeave);
  130. //CheckUserOnJoinField.SetValue (this.CheckUserOnJoin);
  131. DeleteNullPropertiesField.SetValue(this.DeleteNullProperties);
  132. // prefill dropdown selection of users
  133. ConnectAsDropDown.ClearOptions();
  134. ConnectAsDropDown.AddOptions(FriendsList.Select(x => x.NickName).ToList());
  135. // check the current network status
  136. if (PhotonNetwork.IsConnected)
  137. {
  138. if (PhotonNetwork.Server == ServerConnection.GameServer)
  139. {
  140. this.OnJoinedRoom ();
  141. }
  142. else if (PhotonNetwork.Server == ServerConnection.MasterServer || PhotonNetwork.Server == ServerConnection.NameServer)
  143. {
  144. if (PhotonNetwork.InLobby)
  145. {
  146. this.OnJoinedLobby ();
  147. }
  148. else
  149. {
  150. this.OnConnectedToMaster ();
  151. }
  152. }
  153. }else
  154. {
  155. this.SwitchToSimpleConnection();
  156. if (!Embedded)
  157. {
  158. MinimizeButton.SetActive(false);
  159. SwitchtoMaximalPanel();
  160. }
  161. else
  162. {
  163. this.Title.text = EmbeddedGameTitle;
  164. SwitchtoMinimalPanel();
  165. }
  166. }
  167. }
  168. public void SwitchtoMinimalPanel()
  169. {
  170. MinimalCanvasGroup.gameObject.SetActive(true);
  171. MaximalCanvasGroup.alpha = 0f;
  172. MaximalCanvasGroup.blocksRaycasts = false;
  173. MaximalCanvasGroup.interactable = false;
  174. }
  175. public void SwitchtoMaximalPanel()
  176. {
  177. MinimalUIEmbeddHelp.SetActive(false);
  178. MinimalCanvasGroup.gameObject.SetActive(false);
  179. MaximalCanvasGroup.alpha = 1f;
  180. MaximalCanvasGroup.blocksRaycasts = true;
  181. MaximalCanvasGroup.interactable = true;
  182. }
  183. public void SwitchToAdvancedConnection()
  184. {
  185. this.ConnectionPanel.gameObject.SetActive(false);
  186. this.AdvancedConnectionPanel.gameObject.SetActive(true);
  187. }
  188. public void SwitchToSimpleConnection()
  189. {
  190. this.ConnectionPanel.gameObject.SetActive(true);
  191. this.AdvancedConnectionPanel.gameObject.SetActive(false);
  192. }
  193. public void ToggleInfosInMinimalPanel()
  194. {
  195. MinimalUiInfosPanel.SetActive(!MinimalUiInfosPanel.activeSelf);
  196. }
  197. public void RequestInfosPanel(GameObject Parent)
  198. {
  199. if (Parent != null)
  200. {
  201. InfosPanel.transform.SetParent(Parent.transform, false);
  202. }
  203. }
  204. public void OnUserIdSubmited(string userId)
  205. {
  206. this.UserId = userId;
  207. this.Connect();
  208. }
  209. public void SetPlayerTtlRoomOption(int value)
  210. {
  211. this.PlayerTtl = value;
  212. if (debug) Debug.Log("PunCockpit:PlayerTtl = " + this.PlayerTtl);
  213. }
  214. public void SetEmptyRoomTtlRoomOption(int value)
  215. {
  216. this.EmptyRoomTtl = value;
  217. if (debug) Debug.Log("PunCockpit:EmptyRoomTtl = " + this.EmptyRoomTtl);
  218. }
  219. public void SetMaxPlayersRoomOption(int value)
  220. {
  221. this.MaxPlayers = value;
  222. if (debug) Debug.Log("PunCockpit:MaxPlayers = " + this.MaxPlayers);
  223. }
  224. public void SetPluginsRoomOption(string value)
  225. {
  226. this.Plugins = value;
  227. if (debug) Debug.Log("PunCockpit:Plugins = " + this.Plugins);
  228. }
  229. public void SetPublishUserId(bool value)
  230. {
  231. this.PublishUserId = value;
  232. if (debug) Debug.Log("PunCockpit:PublishUserId = " + this.PublishUserId);
  233. }
  234. public void SetIsVisible(bool value)
  235. {
  236. this.IsVisible = value;
  237. if (debug) Debug.Log("PunCockpit:IsVisible = " + this.IsVisible);
  238. }
  239. public void SetIsOpen(bool value)
  240. {
  241. this.IsOpen = value;
  242. if (debug) Debug.Log("PunCockpit:IsOpen = " + this.IsOpen);
  243. }
  244. // public void SetCheckUserOnJoin(bool value)
  245. // {
  246. // this.CheckUserOnJoin = value;
  247. // Debug.Log ("CheckUserOnJoin = " + this.CheckUserOnJoin);
  248. // }
  249. public void SetResetBestRegionCodeInPreferences(bool value)
  250. {
  251. this.ResetBestRegionCodeInPreferences = value;
  252. if (debug) Debug.Log("PunCockpit:ResetBestRegionCodeInPreferences = " + this.ResetBestRegionCodeInPreferences);
  253. }
  254. public void SetCleanupCacheOnLeave(bool value)
  255. {
  256. this.CleanupCacheOnLeave = value;
  257. if (debug) Debug.Log("PunCockpit:CleanupCacheOnLeave = " + this.CleanupCacheOnLeave);
  258. }
  259. public void SetDeleteNullProperties(bool value)
  260. {
  261. this.DeleteNullProperties = value;
  262. if (debug) Debug.Log("PunCockpit:DeleteNullProperties = " + this.DeleteNullProperties);
  263. }
  264. LoadBalancingClient _lbc;
  265. bool _regionPingProcessActive;
  266. List<Region> RegionsList;
  267. /// <summary>
  268. /// in progress, not fully working
  269. /// </summary>
  270. public void PingRegions()
  271. {
  272. ModalWindow.gameObject.SetActive (true);
  273. RegionListLoadingFeedback.text = "Connecting to NameServer...";
  274. _regionPingProcessActive = true;
  275. if (debug) Debug.Log("PunCockpit:PingRegions:ConnectToNameServer");
  276. _lbc = new LoadBalancingClient();
  277. _lbc.AddCallbackTarget(this);
  278. _lbc.StateChanged += OnStateChanged;
  279. _lbc.AppId = PhotonNetwork.PhotonServerSettings.AppSettings.AppIdRealtime;
  280. _lbc.ConnectToNameServer ();
  281. }
  282. void Update()
  283. {
  284. if (_lbc!=null) _lbc.Service();
  285. if (RegionsList !=null)
  286. {
  287. if (this.ModalWindow.gameObject.activeInHierarchy) {
  288. if (PunCockpit.Instance.debug) Debug.Log("PunCockpit:OnRegionsPinged");
  289. this.RegionListView.OnRegionListUpdate (RegionsList);
  290. }
  291. _lbc = null;
  292. RegionListLoadingFeedback.text = string.Empty;
  293. RegionsList = null;
  294. }
  295. }
  296. void OnStateChanged(ClientState previousState, ClientState state)
  297. {
  298. if (state == ClientState.ConnectedToNameServer) {
  299. _lbc.StateChanged -= this.OnStateChanged;
  300. if (debug) Debug.Log("PunCockpit:OnStateChanged: ClientState.ConnectedToNameServer. Waiting for OnRegionListReceived callback.");
  301. RegionListLoadingFeedback.text = "Waiting for application Region List...";
  302. }
  303. }
  304. public override void OnRegionListReceived(RegionHandler regionHandler)
  305. {
  306. if (PunCockpit.Instance.debug)
  307. Debug.Log ("PunCockpit:OnRegionListReceived: " + regionHandler);
  308. if (_regionPingProcessActive)
  309. {
  310. RegionListLoadingFeedback.text = "Pinging Regions...";
  311. _regionPingProcessActive = false;
  312. regionHandler.PingMinimumOfRegions (OnRegionsPinged, null);
  313. }
  314. }
  315. private void OnRegionsPinged(RegionHandler regionHandler)
  316. {
  317. RegionsList = regionHandler.EnabledRegions.OrderBy(x=>x.Ping).ToList();
  318. // will check this on Update() to get back to the main thread.
  319. }
  320. public void CloseRegionListView()
  321. {
  322. RegionsList = null;
  323. if (_lbc != null) {
  324. _lbc.Disconnect ();
  325. _lbc = null;
  326. }
  327. _regionPingProcessActive = false;
  328. this.RegionListView.ResetList ();
  329. this.ModalWindow.gameObject.SetActive (false);
  330. }
  331. public void LoadLevel(string level)
  332. {
  333. if (debug) Debug.Log("PunCockpit:LoadLevel(" +level+")");
  334. PhotonNetwork.LoadLevel(level);
  335. }
  336. public void SetRoomCustomProperty(string value)
  337. {
  338. if (debug) Debug.Log("PunCockpit:SetRoomCustomProperty() c0 = " + value);
  339. PhotonNetwork.CurrentRoom.SetCustomProperties(new Hashtable() { { "C0", value } });
  340. }
  341. private string roomNameToEnter;
  342. public void JoinRoom(string roomName)
  343. {
  344. this.RoomListManager.ResetList();
  345. this.LobbyPanel.gameObject.SetActive(false);
  346. this.ConnectingLabel.SetActive(true);
  347. this.roomNameToEnter = roomName;
  348. PhotonNetwork.JoinRoom(roomName);
  349. }
  350. public void CreateRoom()
  351. {
  352. this.CreateRoom(null, null, LobbyType.Default);
  353. }
  354. public void CreateRoom(string roomName, string lobbyName = "MyLobby", LobbyType lobbyType = LobbyType.SqlLobby, string[] expectedUsers = null)
  355. {
  356. if (debug) Debug.Log("PunCockpit:CreateRoom roomName:" + roomName + " lobbyName:" + lobbyName + " lobbyType:" + lobbyType + " expectedUsers:" + (expectedUsers == null ? "null" : expectedUsers.ToStringFull()));
  357. this.RoomListManager.ResetList();
  358. this.LobbyPanel.gameObject.SetActive(false);
  359. this.ConnectingLabel.SetActive(true);
  360. RoomOptions _roomOptions = this.GetRoomOptions();
  361. if (debug) Debug.Log("PunCockpit:Room options <" + _roomOptions + ">");
  362. TypedLobby sqlLobby = new TypedLobby(lobbyName, lobbyType);
  363. bool _result = PhotonNetwork.CreateRoom(roomName, _roomOptions, sqlLobby, expectedUsers);
  364. if (debug) Debug.Log("PunCockpit:CreateRoom() -> " + _result);
  365. }
  366. public void JoinRandomRoom()
  367. {
  368. PhotonNetwork.JoinRandomRoom();
  369. }
  370. public void LeaveRoom()
  371. {
  372. PlayerListManager.ResetList();
  373. this.GamePanel.gameObject.SetActive(false);
  374. this.ConnectingLabel.SetActive(true);
  375. PhotonNetwork.LeaveRoom();
  376. }
  377. public void Connect()
  378. {
  379. this.ConnectionPanel.gameObject.SetActive(false);
  380. this.AdvancedConnectionPanel.gameObject.SetActive(false);
  381. PhotonNetwork.AuthValues = new AuthenticationValues();
  382. PhotonNetwork.AuthValues.UserId = this.UserId;
  383. this.ConnectingLabel.SetActive(true);
  384. PhotonNetwork.ConnectUsingSettings();
  385. //if (GameVersionOverride != string.Empty) {
  386. // PhotonNetwork.GameVersion = "28"; // GameVersionOverride;
  387. // }
  388. }
  389. public void ReConnect()
  390. {
  391. this.ConnectionPanel.gameObject.SetActive(false);
  392. this.AdvancedConnectionPanel.gameObject.SetActive(false);
  393. PhotonNetwork.AuthValues = new AuthenticationValues();
  394. PhotonNetwork.AuthValues.UserId = this.UserId;
  395. this.ConnectingLabel.SetActive(true);
  396. PhotonNetwork.Reconnect();
  397. }
  398. public void ReconnectAndRejoin()
  399. {
  400. this.ConnectionPanel.gameObject.SetActive(false);
  401. this.AdvancedConnectionPanel.gameObject.SetActive(false);
  402. PhotonNetwork.AuthValues = new AuthenticationValues();
  403. PhotonNetwork.AuthValues.UserId = this.UserId;
  404. this.ConnectingLabel.SetActive(true);
  405. PhotonNetwork.ReconnectAndRejoin();
  406. }
  407. public void ConnectToBestCloudServer()
  408. {
  409. PhotonNetwork.NetworkingClient.AppId = PhotonNetwork.PhotonServerSettings.AppSettings.AppIdRealtime;
  410. this.ConnectionPanel.gameObject.SetActive(false);
  411. this.AdvancedConnectionPanel.gameObject.SetActive(false);
  412. PhotonNetwork.AuthValues = new AuthenticationValues();
  413. PhotonNetwork.AuthValues.UserId = this.UserId;
  414. this.ConnectingLabel.SetActive(true);
  415. if (this.ResetBestRegionCodeInPreferences) {
  416. ServerSettings.ResetBestRegionCodeInPreferences ();
  417. }
  418. PhotonNetwork.ConnectToBestCloudServer();
  419. if (GameVersionOverride != string.Empty) {
  420. PhotonNetwork.GameVersion = GameVersionOverride;
  421. }
  422. }
  423. public void ConnectToRegion(string region)
  424. {
  425. if (debug) Debug.Log("PunCockpit:ConnectToRegion(" + region + ")");
  426. PhotonNetwork.NetworkingClient.AppId = PhotonNetwork.PhotonServerSettings.AppSettings.AppIdRealtime;
  427. this.ConnectionPanel.gameObject.SetActive(false);
  428. this.AdvancedConnectionPanel.gameObject.SetActive(false);
  429. PhotonNetwork.AuthValues = new AuthenticationValues();
  430. PhotonNetwork.AuthValues.UserId = this.UserId;
  431. this.ConnectingLabel.SetActive(true);
  432. bool _result = PhotonNetwork.ConnectToRegion(region);
  433. if (GameVersionOverride != string.Empty) {
  434. PhotonNetwork.GameVersion = GameVersionOverride;
  435. }
  436. if (debug) Debug.Log("PunCockpit:ConnectToRegion(" + region + ") ->" + _result);
  437. }
  438. public void ConnectOffline()
  439. {
  440. if (debug) Debug.Log("PunCockpit:ConnectOffline()");
  441. PhotonNetwork.OfflineMode = true;
  442. }
  443. public void JoinLobby()
  444. {
  445. if (debug) Debug.Log("PunCockpit:JoinLobby()");
  446. bool _result = PhotonNetwork.JoinLobby();
  447. if (!_result) {
  448. Debug.LogError ("PunCockpit: Could not joinLobby");
  449. }
  450. }
  451. public void Disconnect()
  452. {
  453. if (debug) Debug.Log("PunCockpit:Disconnect()");
  454. PhotonNetwork.Disconnect();
  455. }
  456. public void OpenDashboard()
  457. {
  458. Application.OpenURL("https://dashboard.photonengine.com");
  459. }
  460. #region CONNECT UI
  461. public void OnDropdownConnectAs(int dropdownIndex)
  462. {
  463. if (debug) Debug.Log("PunCockpit:OnDropdownConnectAs(" + dropdownIndex + ")");
  464. this.UserId = this.FriendsList[dropdownIndex].UserId;
  465. PlayerPrefs.SetString(UserIdUiForm.UserIdPlayerPref, this.UserId);
  466. StartCoroutine(OnDropdownConnectAs_CB());
  467. }
  468. IEnumerator OnDropdownConnectAs_CB()
  469. {
  470. // wait for the dropdown to animate.
  471. yield return new WaitForSeconds(0.2f);
  472. this.Connect();
  473. }
  474. #endregion
  475. #region IN LOBBY UI
  476. public void OnLobbyToolsViewTabChanged(string tabId)
  477. {
  478. // Debug.Log("PunCockpit:OnLobbyToolsViewTabChanged("+tabId+")");
  479. }
  480. #endregion
  481. #region IN ROOM UI
  482. public void OnSelectPlayer()
  483. {
  484. }
  485. #endregion
  486. #region PUN CallBacks
  487. public override void OnConnected()
  488. {
  489. if (debug) Debug.Log("PunCockpit:OnConnected()");
  490. this.ConnectingLabel.SetActive(false);
  491. this.UserIdText.text = "UserId:" + this.UserId + " Nickname:" + PhotonNetwork.NickName;
  492. }
  493. public override void OnDisconnected(DisconnectCause cause)
  494. {
  495. if (debug) Debug.Log("PunCockpit:OnDisconnected("+cause+")");
  496. this.ConnectingLabel.SetActive(false);
  497. this.UserIdText.text = string.Empty;
  498. this.StateText.text = string.Empty;
  499. this.GamePanel.gameObject.SetActive(false);
  500. this.LobbyPanel.gameObject.SetActive(false);
  501. this.ConnectionPanel.gameObject.SetActive(true);
  502. }
  503. public override void OnConnectedToMaster()
  504. {
  505. if (debug) Debug.Log("PunCockpit:OnConnectedToMaster()");
  506. this.StateText.text = "Connected to Master" + (PhotonNetwork.OfflineMode ? " <Color=Red><b>Offline</b></color>" : "");
  507. this.SetUpLobbyGenericUI();
  508. }
  509. public override void OnJoinedLobby()
  510. {
  511. this.StateText.text = "Connected to Lobby";
  512. if (debug) Debug.Log("PunCockpit:OnJoinedLobby()");
  513. this.SetUpLobbyGenericUI();
  514. }
  515. void SetUpLobbyGenericUI()
  516. {
  517. this.ConnectingLabel.gameObject.SetActive(false);
  518. this.AdvancedConnectionPanel.gameObject.SetActive(false);
  519. this.LobbyPanel.gameObject.SetActive(true);
  520. this.RoomListManager.OnJoinedLobbyCallBack();
  521. this.FriendListManager.SetFriendDetails(this.FriendsList);
  522. JoinLobbyButton.interactable = !PhotonNetwork.InLobby && !PhotonNetwork.OfflineMode;
  523. RoomListManager.gameObject.SetActive(!PhotonNetwork.OfflineMode);
  524. FriendListManager.gameObject.SetActive(!PhotonNetwork.OfflineMode);
  525. RoomListMatchMakingForm.SetActive(!PhotonNetwork.InLobby);
  526. }
  527. public override void OnRoomPropertiesUpdate(Hashtable propertiesThatChanged)
  528. {
  529. if (debug) Debug.Log("PunCockpit:OnRoomPropertiesUpdate() " + propertiesThatChanged.ToStringFull());
  530. if (propertiesThatChanged.ContainsKey("C0"))
  531. {
  532. RoomCustomPropertyInputfield.text = propertiesThatChanged["C0"].ToString();
  533. }
  534. }
  535. public override void OnLeftLobby()
  536. {
  537. if (debug) Debug.Log("PunCockpit:OnLeftLobby()");
  538. this.RoomListManager.ResetList();
  539. this.LobbyPanel.gameObject.SetActive(false);
  540. }
  541. public override void OnCreateRoomFailed(short returnCode, string message)
  542. {
  543. if (debug) Debug.Log("PunCockpit:OnCreateRoomFailed(" + returnCode + "," + message + ")");
  544. }
  545. public override void OnJoinRandomFailed(short returnCode, string message)
  546. {
  547. if (debug) Debug.Log("PunCockpit:OnJoinRandomFailed(" + returnCode + "," + message + ")");
  548. }
  549. public override void OnJoinedRoom()
  550. {
  551. this.StateText.text = "Connected to GameServer " + (PhotonNetwork.OfflineMode ? " <Color=Red><b>Offline</b></color>" : "");
  552. if (debug) Debug.Log("PunCockpit:OnJoinedRoom()");
  553. this.ConnectingLabel.gameObject.SetActive(false);
  554. this.PlayerListManager.ResetList();
  555. this.GamePanel.gameObject.SetActive(true);
  556. this.PlayerDetailsManager.SetPlayerTarget(PhotonNetwork.LocalPlayer);
  557. }
  558. public override void OnJoinRoomFailed(short returnCode, string message)
  559. {
  560. switch (returnCode)
  561. {
  562. case ErrorCode.JoinFailedFoundInactiveJoiner:
  563. if (!string.IsNullOrEmpty(this.roomNameToEnter))
  564. {
  565. PhotonNetwork.RejoinRoom(this.roomNameToEnter);
  566. this.roomNameToEnter = null;
  567. }
  568. break;
  569. }
  570. }
  571. public override void OnLeftRoom()
  572. {
  573. if (debug) Debug.Log("PunCockpit:OnLeftRoom()");
  574. this.GamePanel.gameObject.SetActive(false);
  575. if (PhotonNetwork.OfflineMode)
  576. {
  577. this.ConnectingLabel.gameObject.SetActive(false);
  578. this.ConnectionPanel.gameObject.SetActive (true);
  579. }
  580. }
  581. #endregion
  582. RoomOptions GetRoomOptions()
  583. {
  584. RoomOptions _roomOptions = new RoomOptions();
  585. _roomOptions.MaxPlayers = (byte)this.MaxPlayers;
  586. _roomOptions.IsOpen = this.IsOpen;
  587. _roomOptions.IsVisible = this.IsVisible;
  588. _roomOptions.EmptyRoomTtl = this.EmptyRoomTtl;
  589. _roomOptions.PlayerTtl = this.PlayerTtl;
  590. _roomOptions.PublishUserId = this.PublishUserId;
  591. _roomOptions.CleanupCacheOnLeave = this.CleanupCacheOnLeave;
  592. _roomOptions.DeleteNullProperties = this.DeleteNullProperties;
  593. _roomOptions.CustomRoomProperties = new ExitGames.Client.Photon.Hashtable() { { "C0", "Hello" } };
  594. _roomOptions.CustomRoomPropertiesForLobby = new string[] { "C0" };
  595. return _roomOptions;
  596. }
  597. }
  598. }