RoomManager.cs 27 KB

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