RoomManager.cs 26 KB

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