RoomManager.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using Photon.Pun;
  6. using Photon.Realtime;
  7. using UnityEngine.SceneManagement;
  8. using System;
  9. using System.Linq;
  10. using Hashtable = ExitGames.Client.Photon.Hashtable;
  11. using UnityEngine.Events;
  12. public class RoomManager : MonoBehaviourPunCallbacks
  13. {
  14. [SerializeField] bool _isReady = false;
  15. int playerCount { get; set; }
  16. bool endSetUp { get; set; }
  17. [Header("準備完了ボタンテキスト")]
  18. public Text ReadyButtonText;
  19. [Header("準備完了ボタン")]
  20. public Button ReadyButton;
  21. [Header("プレイヤー情報プレハブ")]
  22. public GameObject PlayerElementPrefab;//部屋情報Prefab
  23. [Header("プレイヤー情報プレハブの親")]
  24. public GameObject PlayerParent;//ScrolViewのcontentオブジェクト
  25. [Header("読み込み中オブジェクト")]
  26. public LoadingObject loadingObject;
  27. [Header("切断時読み込み中オブジェクト")]
  28. public LoadingObject disconnectLoadingObject;
  29. [Header("ルームIDテキスト")]
  30. public Text RoomIDText;
  31. [Header("デッキ情報パネル")]
  32. public DeckInfoPanel deckInfoPanel;
  33. [Header("無効なデッキ表示")]
  34. public GameObject InvalidDeckObject;
  35. [Header("デッキ無表示")]
  36. public GameObject NoDeckSetObject;
  37. [SerializeField] List<FirstPlayerIndexIdToggle> _firstPlayerIndexIdToggles = new();
  38. [SerializeField] GameObject _switchFirstPlayerToggleCover;
  39. public GameObject Parent;
  40. void Awake()
  41. {
  42. foreach (FirstPlayerIndexIdToggle firstPlayerIndexIdToggle in _firstPlayerIndexIdToggles)
  43. {
  44. firstPlayerIndexIdToggle.OnClickAction = OnClickFirstPlayerIndexIDButton;
  45. }
  46. }
  47. #region Open Room Screen
  48. #region Open Room Screen
  49. public void SetUpRoom()
  50. {
  51. ContinuousController.instance.StartCoroutine(SetUpRoomCoroutine());
  52. }
  53. public IEnumerator SetUpRoomCoroutine()
  54. {
  55. Opening.instance.OffYesNoObjects();
  56. Opening.instance.deck.trialDraw.Close();
  57. Opening.instance.deck.deckListPanel.Close();
  58. ContinuousController.instance.isAI = false;
  59. ContinuousController.instance.isRandomMatch = false;
  60. yield return ContinuousController.instance.StartCoroutine(loadingObject.StartLoading("Now Loading"));
  61. endSetUp = false;
  62. Parent.SetActive(true);
  63. if (!PhotonNetwork.InRoom)
  64. {
  65. yield return ContinuousController.instance.StartCoroutine(CreateRoomCoroutine());
  66. }
  67. yield return ContinuousController.instance.StartCoroutine(ShowRoomInfo());
  68. yield return ContinuousController.instance.StartCoroutine(Init(false));
  69. SetDeckInfoPanel();
  70. CheckReadyButton();
  71. yield return ContinuousController.instance.StartCoroutine(loadingObject.EndLoading());
  72. endSetUp = true;
  73. }
  74. #endregion
  75. #region Process to create a room
  76. bool CreateRoomFailed = false;
  77. public IEnumerator CreateRoomCoroutine()
  78. {
  79. CreateRoomFailed = false;
  80. if (!PhotonNetwork.IsConnected)
  81. {
  82. yield return ContinuousController.instance.StartCoroutine(PhotonUtility.ConnectToMasterServerCoroutine());
  83. }
  84. yield return new WaitWhile(() => !PhotonNetwork.IsConnectedAndReady);
  85. if (!PhotonNetwork.InLobby)
  86. {
  87. PhotonNetwork.JoinLobby();
  88. }
  89. yield return new WaitWhile(() => !PhotonNetwork.InLobby);
  90. while (true)
  91. {
  92. //Setting up the room to be created
  93. RoomOptions roomOptions = new RoomOptions();
  94. roomOptions.IsVisible = true; //Make the room visible in the lobby
  95. roomOptions.IsOpen = true; //Allow other players to enter the room
  96. roomOptions.PublishUserId = true;
  97. roomOptions.MaxPlayers = 2;
  98. //Stores the creator's name to display the room creator in the room's custom properties
  99. roomOptions.CustomRoomProperties = new Hashtable()
  100. {
  101. { "RoomCreator",PhotonNetwork.NickName },
  102. { "UseBanlist", ContinuousController.instance.useBanlist }
  103. };
  104. //Display custom property information in the lobby
  105. roomOptions.CustomRoomPropertiesForLobby = new string[]
  106. {
  107. "RoomCreator",
  108. "UseBanlist"
  109. };
  110. string RoomName = StringUtils.GeneratePassword_Num(5);
  111. //Create Room
  112. PhotonNetwork.CreateRoom(RoomName + "-" + ContinuousController.instance.useBanlist, roomOptions, null);
  113. while (true)
  114. {
  115. if (CreateRoomFailed || PhotonNetwork.InRoom)
  116. {
  117. break;
  118. }
  119. yield return null;
  120. }
  121. //Room Creation Success
  122. if (!CreateRoomFailed && PhotonNetwork.InRoom)
  123. {
  124. yield break;
  125. }
  126. }
  127. }
  128. public override void OnCreateRoomFailed(short returnCode, string message)
  129. {
  130. CreateRoomFailed = true;
  131. }
  132. #endregion
  133. #region Initialized when room screen is opened
  134. public IEnumerator Init(bool OnUnload)
  135. {
  136. Opening.instance.battle.selectBattleDeck.Off();
  137. DoneStartBattle = false;
  138. _isReady = false;
  139. playerCount = 0;//PhotonNetwork.CurrentRoom.PlayerCount;
  140. DestroyChildObject();//Delete PlayerElement
  141. GetPlayers();
  142. if (!OnUnload)
  143. {
  144. if (ContinuousController.instance.LastBattleDeckData != null
  145. && ContinuousController.instance.DeckDatas.Contains(ContinuousController.instance.LastBattleDeckData)
  146. && ContinuousController.instance.LastBattleDeckData.IsValidDeckData())
  147. {
  148. ContinuousController.instance.BattleDeckData = ContinuousController.instance.LastBattleDeckData;
  149. }
  150. else
  151. {
  152. ContinuousController.instance.BattleDeckData = FirstValidDeckData();
  153. }
  154. yield return ContinuousController.instance.StartCoroutine(PhotonUtility.SignUpBattleDeckData());
  155. //yield return ContinuousController.instance.StartCoroutine(SignUpBattleDeck(FirstValidDeckData()));
  156. SetReadyProperty(PhotonNetwork.LocalPlayer, _isReady);
  157. }
  158. else
  159. {
  160. yield return ContinuousController.instance.StartCoroutine(PhotonUtility.SignUpBattleDeckData());
  161. }
  162. }
  163. #region The first proper deck in the deck list
  164. DeckData FirstValidDeckData()
  165. {
  166. if (ContinuousController.instance.DeckDatas != null)
  167. {
  168. foreach (DeckData deckData in ContinuousController.instance.DeckDatas)
  169. {
  170. if (deckData != null)
  171. {
  172. if (deckData.IsValidDeckData())
  173. {
  174. return deckData;
  175. }
  176. }
  177. }
  178. }
  179. return null;
  180. }
  181. #endregion
  182. #endregion
  183. #region Room information is acquired and reflected in the UIs
  184. public IEnumerator ShowRoomInfo()
  185. {
  186. yield return new WaitWhile(() => !PhotonNetwork.IsConnectedAndReady);
  187. yield return new WaitWhile(() => !PhotonNetwork.InRoom);
  188. #region RoomName
  189. string RoomName = PhotonNetwork.CurrentRoom.Name;
  190. RoomIDText.text = RoomName.Substring(0,5);
  191. #endregion
  192. }
  193. #endregion
  194. #endregion
  195. #region Register Battle Deck
  196. public IEnumerator SignUpBattleDeck(DeckData deckData)
  197. {
  198. ContinuousController.instance.BattleDeckData = deckData;
  199. bool IsSignUpDeckData()
  200. {
  201. if (deckData != null)
  202. {
  203. if (ContinuousController.instance.DeckDatas != null)
  204. {
  205. if (ContinuousController.instance.DeckDatas.Contains(deckData))
  206. {
  207. if (deckData.IsValidDeckData())
  208. {
  209. return true;
  210. }
  211. }
  212. }
  213. }
  214. return false;
  215. }
  216. if (IsSignUpDeckData())
  217. {
  218. #region Save deck data to custom properties
  219. yield return ContinuousController.instance.StartCoroutine(PhotonUtility.SignUpBattleDeckData());
  220. #endregion
  221. }
  222. else
  223. {
  224. #region Remove custom properties from deck data
  225. yield return ContinuousController.instance.StartCoroutine(PhotonUtility.DeleteBattleDeckData());
  226. #endregion
  227. }
  228. }
  229. #endregion
  230. #region Close the room screen
  231. public void CloseRoom()
  232. {
  233. ContinuousController.instance.StartCoroutine(CloseRoomCoroutine());
  234. }
  235. public IEnumerator CloseRoomCoroutine()
  236. {
  237. Opening.instance.battle.selectBattleDeck.OnCloseSelectBattleDeckAction = null;
  238. Opening.instance.battle.selectBattleDeck.Off();
  239. yield return ContinuousController.instance.StartCoroutine(disconnectLoadingObject.StartLoading("Now Loading"));
  240. Off();
  241. _isReady = false;
  242. endSetUp = false;
  243. SetReadyProperty(PhotonNetwork.LocalPlayer, _isReady);
  244. #region Leave Room
  245. if (PhotonNetwork.InRoom)
  246. {
  247. PhotonNetwork.LeaveRoom();
  248. }
  249. yield return new WaitWhile(() => PhotonNetwork.InRoom);
  250. #endregion
  251. if (!Opening.instance.battle.selectBattleMode.selectBattleModeWindow.gameObject.activeSelf)
  252. {
  253. Opening.instance.battle.selectBattleMode.SetUpSelectBattleMode();
  254. Opening.instance.battle.selectBattleMode.StartSelectRoomMatch();
  255. }
  256. yield return new WaitForSeconds(0.1f);
  257. yield return ContinuousController.instance.StartCoroutine(disconnectLoadingObject.EndLoading());
  258. }
  259. public void Off()
  260. {
  261. Parent.SetActive(false);
  262. }
  263. #endregion
  264. #region Key of the property indicating readiness
  265. public static string ReadyKey()
  266. {
  267. if (PhotonNetwork.InRoom)
  268. {
  269. return "IsReady" + PhotonNetwork.CurrentRoom.Name;
  270. }
  271. return "IsReady";// + PhotonNetwork.CurrentRoom.Name;
  272. }
  273. #endregion
  274. #region Processing when the Ready button is pressed
  275. public void OnClickGetReadyButton()
  276. {
  277. _isReady = !_isReady;
  278. SetReadyProperty(PhotonNetwork.LocalPlayer, _isReady);
  279. CheckReadyButton();
  280. photonView.RPC("DestroyChildObject", RpcTarget.All);
  281. photonView.RPC("GetPlayers", RpcTarget.All);
  282. if (_isReady)
  283. {
  284. Opening.instance.PlayDecisionSE();
  285. }
  286. else
  287. {
  288. Opening.instance.PlayCancelSE();
  289. }
  290. }
  291. #endregion
  292. #region Set properties to indicate readiness
  293. void SetReadyProperty(Photon.Realtime.Player player, bool _isReady)
  294. {
  295. Hashtable PlayerProp = player.CustomProperties;
  296. object value;
  297. if (PlayerProp.TryGetValue(ReadyKey(), out value))
  298. {
  299. PlayerProp[ReadyKey()] = _isReady;
  300. }
  301. else
  302. {
  303. PlayerProp.Add(ReadyKey(), _isReady);
  304. }
  305. player.SetCustomProperties(PlayerProp);
  306. }
  307. #endregion
  308. #region All players in the room are determined to be ready.
  309. public bool AllPlayerIsReady()
  310. {
  311. foreach (var p in PhotonNetwork.PlayerList)
  312. {
  313. object value;
  314. if (p.CustomProperties.TryGetValue(ReadyKey(), out value))
  315. {
  316. if (!(bool)value)
  317. {
  318. return false;
  319. }
  320. }
  321. else
  322. {
  323. return false;
  324. }
  325. }
  326. return true;
  327. }
  328. #endregion
  329. #region Monitor the number of players and standby status → If OK, start battle
  330. bool DoneStartBattle;
  331. public void CheckPlayerState()
  332. {
  333. if (PhotonNetwork.InRoom && endSetUp)
  334. {
  335. if (PhotonNetwork.CurrentRoom.PlayerCount == PhotonNetwork.CurrentRoom.MaxPlayers && AllPlayerIsReady())
  336. {
  337. if (PhotonNetwork.IsMasterClient && !DoneStartBattle)
  338. {
  339. DoneStartBattle = true;
  340. if (PhotonNetwork.IsMasterClient)
  341. {
  342. Hashtable RoomProp = PhotonNetwork.CurrentRoom.CustomProperties;
  343. // 0: MasterClient, -1: Random, 1: non-MasterClient
  344. int firstPlayerIndexID = -1;
  345. int firstPlayerId = -1;
  346. if (RoomProp.TryGetValue(DataBase.FirstPlayerIndexIdKey, out object value))
  347. {
  348. if (value is int)
  349. {
  350. firstPlayerIndexID = (int)value;
  351. }
  352. }
  353. if (firstPlayerIndexID == 0)
  354. {
  355. firstPlayerId = PhotonNetwork.MasterClient.ActorNumber;
  356. }
  357. else if (firstPlayerIndexID == 1)
  358. {
  359. Photon.Realtime.Player nonMasterPlayer = PhotonNetwork.PlayerList.ToList().Find(player => !player.IsMasterClient);
  360. if (nonMasterPlayer != null)
  361. {
  362. firstPlayerId = nonMasterPlayer.ActorNumber;
  363. }
  364. }
  365. if (RoomProp.TryGetValue(DataBase.FirstPlayerKey, out value))
  366. {
  367. RoomProp[DataBase.FirstPlayerKey] = firstPlayerId;
  368. }
  369. else
  370. {
  371. RoomProp.Add(DataBase.FirstPlayerKey, firstPlayerId);
  372. }
  373. PhotonNetwork.CurrentRoom.SetCustomProperties(RoomProp);
  374. }
  375. photonView.RPC("GoToBattleScene", RpcTarget.All);
  376. }
  377. }
  378. else if (playerCount != PhotonNetwork.CurrentRoom.PlayerCount)
  379. {
  380. playerCount = PhotonNetwork.CurrentRoom.PlayerCount;
  381. DestroyChildObject();//PlayerElementを削除
  382. GetPlayers();
  383. }
  384. }
  385. }
  386. #endregion
  387. #region Start of battle
  388. [PunRPC]
  389. public void GoToBattleScene()
  390. {
  391. StartCoroutine(GoToBattleSceneCoroutine());
  392. }
  393. IEnumerator GoToBattleSceneCoroutine()
  394. {
  395. yield return ContinuousController.instance.StartCoroutine(Opening.instance.LoadingObject_Unload.StartLoading("Now Loading"));
  396. object value;
  397. DoneStartBattle = true;
  398. Hashtable PlayerProp = PhotonNetwork.LocalPlayer.CustomProperties;
  399. List<DictionaryEntry> dictionaryEntries = new List<DictionaryEntry>();
  400. foreach (DictionaryEntry dictionaryEntry in PlayerProp)
  401. {
  402. dictionaryEntries.Add(dictionaryEntry);
  403. }
  404. foreach (DictionaryEntry dictionaryEntry in dictionaryEntries)
  405. {
  406. if (dictionaryEntry.Key.ToString().Contains("PhotonWaitController"))
  407. {
  408. if (PlayerProp.TryGetValue(dictionaryEntry.Key.ToString(), out value))
  409. {
  410. PlayerProp.Remove(dictionaryEntry.Key.ToString());
  411. }
  412. }
  413. }
  414. if (PlayerProp.TryGetValue("isBattle", out value))
  415. {
  416. PlayerProp["isBattle"] = true;
  417. }
  418. else
  419. {
  420. PlayerProp.Add("isBattle", true);
  421. }
  422. if (PlayerProp.TryGetValue(ReadyKey(), out value))
  423. {
  424. PlayerProp[ReadyKey()] = false;
  425. }
  426. else
  427. {
  428. PlayerProp.Add(ReadyKey(), false);
  429. }
  430. PlayerProp[ContinuousController.DeckDataPropertyKey] = ContinuousController.instance.BattleDeckData.GetThisDeckCode();
  431. PhotonNetwork.LocalPlayer.SetCustomProperties(PlayerProp);
  432. yield return new WaitForSeconds(0.1f);
  433. //Opening.instance.MainCamera.gameObject.SetActive(false);
  434. foreach (Camera camera in Opening.instance.openingCameras)
  435. {
  436. camera.gameObject.SetActive(false);
  437. }
  438. ContinuousController.instance.StartCoroutine(Opening.instance.OpeningBGM.FadeOut(0.5f));
  439. yield return new WaitForSeconds(1f);
  440. SceneManager.LoadSceneAsync("BattleScene", LoadSceneMode.Additive);
  441. yield return ContinuousController.instance.StartCoroutine(Opening.instance.LoadingObject_Unload.EndLoading());
  442. }
  443. #endregion
  444. #region Create PlayerElement corresponding to the information of players in the room
  445. [PunRPC]
  446. public void GetPlayers()
  447. {
  448. if (PhotonNetwork.PlayerList == null || PhotonNetwork.CurrentRoom.PlayerCount == 0)
  449. {
  450. return;
  451. }
  452. for (int i = 0; i < PhotonNetwork.CurrentRoom.PlayerCount; i++)
  453. {
  454. GameObject PlayerElement = Instantiate(PlayerElementPrefab, PlayerParent.transform);
  455. object value;
  456. string PlayerName = "Player";
  457. #region Get player name from custom property
  458. if (PhotonNetwork.PlayerList[i] == PhotonNetwork.LocalPlayer)
  459. {
  460. PlayerName = "You";
  461. }
  462. else
  463. {
  464. PlayerName = "Opponent";
  465. }
  466. Hashtable hash = PhotonNetwork.PlayerList[i].CustomProperties;
  467. if (hash.TryGetValue(ContinuousController.PlayerNameKey, out value))
  468. {
  469. PlayerName = (string)value;
  470. }
  471. #endregion
  472. if (PhotonNetwork.PlayerList[i].CustomProperties.TryGetValue(ReadyKey(), out value))
  473. {
  474. PlayerElement.GetComponent<CPlayerElement>().SetPlayerInfo(PlayerName, (bool)value);
  475. }
  476. else
  477. {
  478. PlayerElement.GetComponent<CPlayerElement>().SetPlayerInfo(PlayerName, false);
  479. }
  480. }
  481. }
  482. #endregion
  483. #region Delete PlayerElement displayed
  484. [PunRPC]
  485. public void DestroyChildObject()
  486. {
  487. for (int i = 0; i < PlayerParent.transform.childCount; ++i)
  488. {
  489. Destroy(PlayerParent.transform.GetChild(i).gameObject);
  490. }
  491. }
  492. #endregion
  493. #region Check the Ready button
  494. public void CheckReadyButton()
  495. {
  496. bool oldIsReady = _isReady;
  497. if (CanReady())
  498. {
  499. ReadyButton.interactable = true;
  500. if (_isReady)
  501. {
  502. ReadyButtonText.text = LocalizeUtility.GetLocalizedString(
  503. EngMessage: "Cancel",
  504. JpnMessage: "キャンセル"
  505. );
  506. }
  507. else
  508. {
  509. ReadyButtonText.text = LocalizeUtility.GetLocalizedString(
  510. EngMessage: "Finish Preparation",
  511. JpnMessage: "準備完了する"
  512. );
  513. }
  514. }
  515. else
  516. {
  517. ReadyButton.interactable = false;
  518. ReadyButtonText.text = "Finish Preparation";
  519. _isReady = false;
  520. SetReadyProperty(PhotonNetwork.LocalPlayer, _isReady);
  521. if (oldIsReady)
  522. {
  523. photonView.RPC("DestroyChildObject", RpcTarget.All);
  524. photonView.RPC("GetPlayers", RpcTarget.All);
  525. }
  526. }
  527. }
  528. bool CanReady()
  529. {
  530. if (!DoneStartBattle && !Opening.instance.battle.selectBattleDeck.gameObject.activeSelf)
  531. {
  532. if (ContinuousController.instance.BattleDeckData != null && ContinuousController.instance.DeckDatas != null)
  533. {
  534. //if (ContinuousController.instance.DeckDatas.Contains(ContinuousController.instance.BattleDeckData))
  535. {
  536. if (ContinuousController.instance.BattleDeckData.IsValidDeckData())
  537. {
  538. return true;
  539. }
  540. }
  541. }
  542. }
  543. return false;
  544. }
  545. #endregion
  546. #region Battle deck selection begins
  547. bool _oldIsReady = false;
  548. public void OnClickSelectBattleDeckButton()
  549. {
  550. int defaulSelectDeckIndex = 0;
  551. if (ContinuousController.instance.BattleDeckData != null)
  552. {
  553. defaulSelectDeckIndex = ContinuousController.instance.DeckDatas.IndexOf(ContinuousController.instance.BattleDeckData);
  554. }
  555. Opening.instance.battle.selectBattleDeck.SetUpSelectBattleDeck(
  556. () =>
  557. {
  558. Opening.instance.battle.selectBattleDeck.OnCloseSelectBattleDeckAction = null;
  559. ContinuousController.instance.StartCoroutine(OnEndCoroutine());
  560. IEnumerator OnEndCoroutine()
  561. {
  562. yield return ContinuousController.instance.StartCoroutine(Opening.instance.battle.selectBattleDeck.OnClickSelectButton_RoomMatchCoroutine());
  563. yield return ContinuousController.instance.StartCoroutine(EndSelectBattleDeckCoroutine());
  564. }
  565. },
  566. defaulSelectDeckIndex);
  567. Opening.instance.battle.selectBattleDeck.OnCloseSelectBattleDeckAction = () => ContinuousController.instance.StartCoroutine(EndSelectBattleDeckCoroutine());
  568. _oldIsReady = _isReady;
  569. _isReady = false;
  570. SetReadyProperty(PhotonNetwork.LocalPlayer, _isReady);
  571. photonView.RPC("DestroyChildObject", RpcTarget.All);
  572. photonView.RPC("GetPlayers", RpcTarget.All);
  573. }
  574. #endregion
  575. #region End of battle deck selection
  576. IEnumerator EndSelectBattleDeckCoroutine()
  577. {
  578. //if (this.gameObject.activeSelf)
  579. {
  580. //yield return ContinuousController.instance.StartCoroutine(SignUpBattleDeck(ContinuousController.instance.BattleDeckData));
  581. yield return new WaitWhile(() => Opening.instance.battle.selectBattleDeck.gameObject.activeSelf);
  582. yield return new WaitForSeconds(Time.deltaTime);
  583. ContinuousController.instance.BattleDeckData = Opening.instance.battle.selectBattleDeck.deckInfoPanel.ShowingDeckData;
  584. yield return ContinuousController.instance.StartCoroutine(PhotonUtility.SignUpBattleDeckData());
  585. yield return new WaitForSeconds(Time.deltaTime);
  586. SetDeckInfoPanel();
  587. _isReady = _oldIsReady;
  588. if (!CanReady())
  589. {
  590. _isReady = false;
  591. }
  592. CheckReadyButton();
  593. SetReadyProperty(PhotonNetwork.LocalPlayer, _isReady);
  594. #region プレイヤーの準備完了状態がプロパティにセットされるまで待機
  595. while (true)
  596. {
  597. Hashtable _hash = PhotonNetwork.LocalPlayer.CustomProperties;
  598. if (_hash.TryGetValue(ReadyKey(), out object value))
  599. {
  600. if ((bool)value == _isReady)
  601. {
  602. break;
  603. }
  604. }
  605. yield return null;
  606. }
  607. #endregion
  608. photonView.RPC("DestroyChildObject", RpcTarget.All);
  609. photonView.RPC("GetPlayers", RpcTarget.All);
  610. }
  611. }
  612. #endregion
  613. #region Display deck information panel
  614. public async void SetDeckInfoPanel()
  615. {
  616. if (ContinuousController.instance.BattleDeckData == null)
  617. {
  618. await deckInfoPanel.SetUpDeckInfoPanel(DeckData.EmptyDeckData());
  619. NoDeckSetObject.SetActive(true);
  620. InvalidDeckObject.SetActive(false);
  621. }
  622. else
  623. {
  624. await deckInfoPanel.SetUpDeckInfoPanel(ContinuousController.instance.BattleDeckData);
  625. NoDeckSetObject.SetActive(ContinuousController.instance.BattleDeckData.AllDeckCards().Count == 0);
  626. InvalidDeckObject.SetActive(!ContinuousController.instance.BattleDeckData.IsValidDeckData());
  627. }
  628. }
  629. #endregion
  630. #region Processing when the Copy Room ID button is pressed
  631. public void OnClickCopyRoomIDButton()
  632. {
  633. if (PhotonNetwork.InRoom)
  634. {
  635. #region クリップボードにデッキコードをコピー
  636. GUIUtility.systemCopyBuffer = PhotonNetwork.CurrentRoom.Name.Substring(0, 5);
  637. #endregion
  638. List<UnityAction> Commands = new List<UnityAction>()
  639. {
  640. null
  641. };
  642. List<string> CommandTexts = new List<string>()
  643. {
  644. "OK"
  645. };
  646. Opening.instance.SetUpActiveYesNoObject(
  647. Commands,
  648. CommandTexts,
  649. LocalizeUtility.GetLocalizedString(
  650. EngMessage: "Room ID copied!",
  651. JpnMessage: "ルームIDをクリップボードにコピーしました!"
  652. ),
  653. false);
  654. }
  655. }
  656. #endregion
  657. public void Update()
  658. {
  659. if (GManager.instance == null)
  660. {
  661. if (endSetUp && !DoneStartBattle)
  662. {
  663. CheckReadyButton();
  664. CheckPlayerState();
  665. }
  666. }
  667. if (PhotonNetwork.IsConnectedAndReady)
  668. {
  669. if (PhotonNetwork.InRoom)
  670. {
  671. if (PhotonNetwork.LocalPlayer != null)
  672. {
  673. _switchFirstPlayerToggleCover.SetActive(!PhotonNetwork.LocalPlayer.IsMasterClient);
  674. Hashtable RoomProp = PhotonNetwork.CurrentRoom.CustomProperties;
  675. // 0: MasterClient, -1: Random, 1: non-MasterClient
  676. int firstPlayerIndexID = -1;
  677. if (RoomProp.TryGetValue(DataBase.FirstPlayerIndexIdKey, out object value))
  678. {
  679. if (value is int)
  680. {
  681. firstPlayerIndexID = (int)value;
  682. }
  683. }
  684. foreach (FirstPlayerIndexIdToggle firstPlayerIndexIdToggle in _firstPlayerIndexIdToggles)
  685. {
  686. firstPlayerIndexIdToggle.Toggle.isOn = firstPlayerIndexIdToggle.FirstPlayerIndexID == firstPlayerIndexID;
  687. }
  688. }
  689. }
  690. }
  691. }
  692. public void OnClickFirstPlayerIndexIDButton(int firstPlayerIndexID)
  693. {
  694. if (!PhotonNetwork.IsConnectedAndReady) return;
  695. if (!PhotonNetwork.InRoom) return;
  696. if (PhotonNetwork.LocalPlayer == null) return;
  697. if (!PhotonNetwork.LocalPlayer.IsMasterClient) return;
  698. Hashtable RoomProp = PhotonNetwork.CurrentRoom.CustomProperties;
  699. if (RoomProp.TryGetValue(DataBase.FirstPlayerIndexIdKey, out object value))
  700. {
  701. RoomProp[DataBase.FirstPlayerIndexIdKey] = firstPlayerIndexID;
  702. }
  703. else
  704. {
  705. RoomProp.Add(DataBase.FirstPlayerIndexIdKey, firstPlayerIndexID);
  706. }
  707. PhotonNetwork.CurrentRoom.SetCustomProperties(RoomProp);
  708. }
  709. }