RoomManager.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  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. private static WaitForSeconds _waitForSeconds1 = new WaitForSeconds(1f);
  15. private static WaitForSeconds _waitForSeconds0_1 = new WaitForSeconds(0.1f);
  16. [SerializeField] bool _isReady = false;
  17. int playerCount { get; set; }
  18. bool endSetUp { get; set; }
  19. [Header("準備完了ボタンテキスト")]
  20. public Text ReadyButtonText;
  21. [Header("準備完了ボタン")]
  22. public Button ReadyButton;
  23. [Header("プレイヤー情報プレハブ")]
  24. public GameObject PlayerElementPrefab;//部屋情報Prefab
  25. [Header("プレイヤー情報プレハブの親")]
  26. public GameObject PlayerParent;//ScrolViewのcontentオブジェクト
  27. [Header("読み込み中オブジェクト")]
  28. public LoadingObject loadingObject;
  29. [Header("切断時読み込み中オブジェクト")]
  30. public LoadingObject disconnectLoadingObject;
  31. [Header("ルームIDテキスト")]
  32. public Text RoomIDText;
  33. [Header("デッキ情報パネル")]
  34. public DeckInfoPanel deckInfoPanel;
  35. [Header("無効なデッキ表示")]
  36. public GameObject InvalidDeckObject;
  37. [Header("デッキ無表示")]
  38. public GameObject NoDeckSetObject;
  39. [SerializeField] List<FirstPlayerIndexIdToggle> _firstPlayerIndexIdToggles = new();
  40. [SerializeField] GameObject _switchFirstPlayerToggleCover;
  41. public GameObject Parent;
  42. void Awake()
  43. {
  44. foreach (FirstPlayerIndexIdToggle firstPlayerIndexIdToggle in _firstPlayerIndexIdToggles)
  45. {
  46. firstPlayerIndexIdToggle.OnClickAction = OnClickFirstPlayerIndexIDButton;
  47. }
  48. }
  49. #region Open Room Screen
  50. #region Open Room Screen
  51. public void SetUpRoom()
  52. {
  53. ContinuousController.instance.StartCoroutine(SetUpRoomCoroutine());
  54. }
  55. public IEnumerator SetUpRoomCoroutine()
  56. {
  57. Opening.instance.OffYesNoObjects();
  58. Opening.instance.deck.trialDraw.Close();
  59. Opening.instance.deck.deckListPanel.Close();
  60. ContinuousController.instance.isAI = false;
  61. ContinuousController.instance.isRandomMatch = false;
  62. yield return ContinuousController.instance.StartCoroutine(loadingObject.StartLoading("Now Loading"));
  63. endSetUp = false;
  64. Parent.SetActive(true);
  65. if (!PhotonNetwork.InRoom)
  66. {
  67. yield return ContinuousController.instance.StartCoroutine(CreateRoomCoroutine());
  68. }
  69. yield return ContinuousController.instance.StartCoroutine(ShowRoomInfo());
  70. yield return ContinuousController.instance.StartCoroutine(Init(false));
  71. SetDeckInfoPanel();
  72. CheckReadyButton();
  73. yield return ContinuousController.instance.StartCoroutine(loadingObject.EndLoading());
  74. endSetUp = true;
  75. }
  76. #endregion
  77. #region Process to create a room
  78. bool CreateRoomFailed = false;
  79. public IEnumerator CreateRoomCoroutine()
  80. {
  81. CreateRoomFailed = false;
  82. if (!PhotonNetwork.IsConnected)
  83. {
  84. yield return ContinuousController.instance.StartCoroutine(PhotonUtility.ConnectToMasterServerCoroutine());
  85. }
  86. yield return new WaitWhile(() => !PhotonNetwork.IsConnectedAndReady);
  87. if (!PhotonNetwork.InLobby)
  88. {
  89. PhotonNetwork.JoinLobby();
  90. }
  91. yield return new WaitWhile(() => !PhotonNetwork.InLobby);
  92. while (true)
  93. {
  94. //Setting up the room to be created
  95. RoomOptions roomOptions = new RoomOptions
  96. {
  97. IsVisible = true, //Make the room visible in the lobby
  98. IsOpen = true, //Allow other players to enter the room
  99. PublishUserId = true,
  100. MaxPlayers = 2,
  101. //Stores the creator's name to display the room creator in the room's custom properties
  102. CustomRoomProperties = new Hashtable()
  103. {
  104. { "RoomCreator",PhotonNetwork.NickName },
  105. { "UseBanlist", ContinuousController.instance.useBanlist }
  106. },
  107. //Display custom property information in the lobby
  108. CustomRoomPropertiesForLobby = new string[]
  109. {
  110. "RoomCreator",
  111. "UseBanlist"
  112. }
  113. };
  114. string RoomName = StringUtils.GeneratePassword_Num(5);
  115. //Create Room
  116. PhotonNetwork.CreateRoom(RoomName + "-" + ContinuousController.instance.useBanlist, roomOptions, null);
  117. while (true)
  118. {
  119. if (CreateRoomFailed || PhotonNetwork.InRoom)
  120. {
  121. break;
  122. }
  123. yield return null;
  124. }
  125. //Room Creation Success
  126. if (!CreateRoomFailed && PhotonNetwork.InRoom)
  127. {
  128. yield break;
  129. }
  130. }
  131. }
  132. public override void OnCreateRoomFailed(short returnCode, string message)
  133. {
  134. CreateRoomFailed = true;
  135. }
  136. #endregion
  137. #region Initialized when room screen is opened
  138. public IEnumerator Init(bool OnUnload)
  139. {
  140. Opening.instance.battle.selectBattleDeck.Off();
  141. DoneStartBattle = false;
  142. _isReady = false;
  143. playerCount = 0;//PhotonNetwork.CurrentRoom.PlayerCount;
  144. DestroyChildObject();//Delete PlayerElement
  145. GetPlayers();
  146. if (!OnUnload)
  147. {
  148. if (ContinuousController.instance.LastBattleDeckData != null
  149. && ContinuousController.instance.DeckDatas.Contains(ContinuousController.instance.LastBattleDeckData)
  150. && ContinuousController.instance.LastBattleDeckData.IsValidDeckData())
  151. {
  152. ContinuousController.instance.BattleDeckData = ContinuousController.instance.LastBattleDeckData;
  153. }
  154. else
  155. {
  156. ContinuousController.instance.BattleDeckData = FirstValidDeckData();
  157. }
  158. yield return ContinuousController.instance.StartCoroutine(PhotonUtility.SignUpBattleDeckData());
  159. //yield return ContinuousController.instance.StartCoroutine(SignUpBattleDeck(FirstValidDeckData()));
  160. SetReadyProperty(PhotonNetwork.LocalPlayer, _isReady);
  161. }
  162. else
  163. {
  164. yield return ContinuousController.instance.StartCoroutine(PhotonUtility.SignUpBattleDeckData());
  165. }
  166. }
  167. #region The first proper deck in the deck list
  168. DeckData FirstValidDeckData()
  169. {
  170. if (ContinuousController.instance.DeckDatas != null)
  171. {
  172. foreach (DeckData deckData in ContinuousController.instance.DeckDatas)
  173. {
  174. if (deckData != null)
  175. {
  176. if (deckData.IsValidDeckData())
  177. {
  178. return deckData;
  179. }
  180. }
  181. }
  182. }
  183. return null;
  184. }
  185. #endregion
  186. #endregion
  187. #region Room information is acquired and reflected in the UIs
  188. public IEnumerator ShowRoomInfo()
  189. {
  190. yield return new WaitWhile(() => !PhotonNetwork.IsConnectedAndReady);
  191. yield return new WaitWhile(() => !PhotonNetwork.InRoom);
  192. #region RoomName
  193. string RoomName = PhotonNetwork.CurrentRoom.Name;
  194. RoomIDText.text = RoomName[..5];
  195. #endregion
  196. }
  197. #endregion
  198. #endregion
  199. #region Register Battle Deck
  200. public IEnumerator SignUpBattleDeck(DeckData deckData)
  201. {
  202. ContinuousController.instance.BattleDeckData = deckData;
  203. bool IsSignUpDeckData()
  204. {
  205. if (deckData != null)
  206. {
  207. if (ContinuousController.instance.DeckDatas != null)
  208. {
  209. if (ContinuousController.instance.DeckDatas.Contains(deckData))
  210. {
  211. if (deckData.IsValidDeckData())
  212. {
  213. return true;
  214. }
  215. }
  216. }
  217. }
  218. return false;
  219. }
  220. if (IsSignUpDeckData())
  221. {
  222. #region Save deck data to custom properties
  223. yield return ContinuousController.instance.StartCoroutine(PhotonUtility.SignUpBattleDeckData());
  224. #endregion
  225. }
  226. else
  227. {
  228. #region Remove custom properties from deck data
  229. yield return ContinuousController.instance.StartCoroutine(PhotonUtility.DeleteBattleDeckData());
  230. #endregion
  231. }
  232. }
  233. #endregion
  234. #region Close the room screen
  235. public void CloseRoom()
  236. {
  237. ContinuousController.instance.StartCoroutine(CloseRoomCoroutine());
  238. }
  239. public IEnumerator CloseRoomCoroutine()
  240. {
  241. Opening.instance.battle.selectBattleDeck.OnCloseSelectBattleDeckAction = null;
  242. Opening.instance.battle.selectBattleDeck.Off();
  243. yield return ContinuousController.instance.StartCoroutine(disconnectLoadingObject.StartLoading("Now Loading"));
  244. Off();
  245. _isReady = false;
  246. endSetUp = false;
  247. SetReadyProperty(PhotonNetwork.LocalPlayer, _isReady);
  248. #region Leave Room
  249. if (PhotonNetwork.InRoom)
  250. {
  251. PhotonNetwork.LeaveRoom();
  252. }
  253. yield return new WaitWhile(() => PhotonNetwork.InRoom);
  254. #endregion
  255. if (!Opening.instance.battle.selectBattleMode.selectBattleModeWindow.gameObject.activeSelf)
  256. {
  257. Opening.instance.battle.selectBattleMode.SetUpSelectBattleMode();
  258. Opening.instance.battle.selectBattleMode.StartSelectRoomMatch();
  259. }
  260. yield return _waitForSeconds0_1;
  261. yield return ContinuousController.instance.StartCoroutine(disconnectLoadingObject.EndLoading());
  262. }
  263. public void Off()
  264. {
  265. Parent.SetActive(false);
  266. }
  267. #endregion
  268. #region Key of the property indicating readiness
  269. public static string ReadyKey()
  270. {
  271. if (PhotonNetwork.InRoom)
  272. {
  273. return "IsReady" + PhotonNetwork.CurrentRoom.Name;
  274. }
  275. return "IsReady";// + PhotonNetwork.CurrentRoom.Name;
  276. }
  277. #endregion
  278. #region Processing when the Ready button is pressed
  279. public void OnClickGetReadyButton()
  280. {
  281. _isReady = !_isReady;
  282. SetReadyProperty(PhotonNetwork.LocalPlayer, _isReady);
  283. CheckReadyButton();
  284. photonView.RPC("DestroyChildObject", RpcTarget.All);
  285. photonView.RPC("GetPlayers", RpcTarget.All);
  286. if (_isReady)
  287. {
  288. Opening.instance.PlayDecisionSE();
  289. }
  290. else
  291. {
  292. Opening.instance.PlayCancelSE();
  293. }
  294. }
  295. #endregion
  296. #region Set properties to indicate readiness
  297. void SetReadyProperty(Photon.Realtime.Player player, bool _isReady)
  298. {
  299. Hashtable PlayerProp = player.CustomProperties;
  300. if (PlayerProp.TryGetValue(ReadyKey(), out object _))
  301. {
  302. PlayerProp[ReadyKey()] = _isReady;
  303. }
  304. else
  305. {
  306. PlayerProp.Add(ReadyKey(), _isReady);
  307. }
  308. player.SetCustomProperties(PlayerProp);
  309. }
  310. #endregion
  311. #region All players in the room are determined to be ready.
  312. public bool AllPlayerIsReady()
  313. {
  314. foreach (var p in PhotonNetwork.PlayerList)
  315. {
  316. if (p.CustomProperties.TryGetValue(ReadyKey(), out object value))
  317. {
  318. if (!(bool)value)
  319. {
  320. return false;
  321. }
  322. }
  323. else
  324. {
  325. return false;
  326. }
  327. }
  328. return true;
  329. }
  330. #endregion
  331. #region Monitor the number of players and standby status → If OK, start battle
  332. bool DoneStartBattle;
  333. public void CheckPlayerState()
  334. {
  335. if (PhotonNetwork.InRoom && endSetUp)
  336. {
  337. if (PhotonNetwork.CurrentRoom.PlayerCount == PhotonNetwork.CurrentRoom.MaxPlayers && AllPlayerIsReady())
  338. {
  339. if (PhotonNetwork.IsMasterClient && !DoneStartBattle)
  340. {
  341. DoneStartBattle = true;
  342. if (PhotonNetwork.IsMasterClient)
  343. {
  344. Hashtable RoomProp = PhotonNetwork.CurrentRoom.CustomProperties;
  345. // 0: MasterClient, -1: Random, 1: non-MasterClient
  346. int firstPlayerIndexID = -1;
  347. int firstPlayerId = -1;
  348. if (RoomProp.TryGetValue(DataBase.FirstPlayerIndexIdKey, out object value))
  349. {
  350. if (value is int)
  351. {
  352. firstPlayerIndexID = (int)value;
  353. }
  354. }
  355. if (firstPlayerIndexID == 0)
  356. {
  357. firstPlayerId = PhotonNetwork.MasterClient.ActorNumber;
  358. }
  359. else if (firstPlayerIndexID == 1)
  360. {
  361. Photon.Realtime.Player nonMasterPlayer = PhotonNetwork.PlayerList.ToList().Find(player => !player.IsMasterClient);
  362. if (nonMasterPlayer != null)
  363. {
  364. firstPlayerId = nonMasterPlayer.ActorNumber;
  365. }
  366. }
  367. if (RoomProp.TryGetValue(DataBase.FirstPlayerKey, out value))
  368. {
  369. RoomProp[DataBase.FirstPlayerKey] = firstPlayerId;
  370. }
  371. else
  372. {
  373. RoomProp.Add(DataBase.FirstPlayerKey, firstPlayerId);
  374. }
  375. PhotonNetwork.CurrentRoom.SetCustomProperties(RoomProp);
  376. }
  377. photonView.RPC("GoToBattleScene", RpcTarget.All);
  378. }
  379. }
  380. else if (playerCount != PhotonNetwork.CurrentRoom.PlayerCount)
  381. {
  382. playerCount = PhotonNetwork.CurrentRoom.PlayerCount;
  383. DestroyChildObject();//PlayerElementを削除
  384. GetPlayers();
  385. }
  386. }
  387. }
  388. #endregion
  389. #region Start of battle
  390. [PunRPC]
  391. public void GoToBattleScene()
  392. {
  393. StartCoroutine(GoToBattleSceneCoroutine());
  394. }
  395. IEnumerator GoToBattleSceneCoroutine()
  396. {
  397. yield return ContinuousController.instance.StartCoroutine(Opening.instance.LoadingObject_Unload.StartLoading("Now Loading"));
  398. DoneStartBattle = true;
  399. Hashtable PlayerProp = PhotonNetwork.LocalPlayer.CustomProperties;
  400. List<DictionaryEntry> dictionaryEntries = new List<DictionaryEntry>();
  401. foreach (DictionaryEntry dictionaryEntry in PlayerProp)
  402. {
  403. dictionaryEntries.Add(dictionaryEntry);
  404. }
  405. foreach (DictionaryEntry dictionaryEntry in dictionaryEntries)
  406. {
  407. if (dictionaryEntry.Key.ToString().Contains("PhotonWaitController"))
  408. {
  409. if (PlayerProp.TryGetValue(dictionaryEntry.Key.ToString(), out _))
  410. {
  411. PlayerProp.Remove(dictionaryEntry.Key.ToString());
  412. }
  413. }
  414. }
  415. if (PlayerProp.TryGetValue("isBattle", out _))
  416. {
  417. PlayerProp["isBattle"] = true;
  418. }
  419. else
  420. {
  421. PlayerProp.Add("isBattle", true);
  422. }
  423. if (PlayerProp.TryGetValue(ReadyKey(), out _))
  424. {
  425. PlayerProp[ReadyKey()] = false;
  426. }
  427. else
  428. {
  429. PlayerProp.Add(ReadyKey(), false);
  430. }
  431. PlayerProp[ContinuousController.DeckDataPropertyKey] = ContinuousController.instance.BattleDeckData.GetThisDeckCode();
  432. PhotonNetwork.LocalPlayer.SetCustomProperties(PlayerProp);
  433. yield return _waitForSeconds0_1;
  434. //Opening.instance.MainCamera.gameObject.SetActive(false);
  435. foreach (Camera camera in Opening.instance.openingCameras)
  436. {
  437. camera.gameObject.SetActive(false);
  438. }
  439. ContinuousController.instance.StartCoroutine(Opening.instance.OpeningBGM.FadeOut(0.5f));
  440. yield return _waitForSeconds1;
  441. SceneManager.LoadSceneAsync("BattleScene", LoadSceneMode.Additive);
  442. yield return ContinuousController.instance.StartCoroutine(Opening.instance.LoadingObject_Unload.EndLoading());
  443. }
  444. #endregion
  445. #region Create PlayerElement corresponding to the information of players in the room
  446. [PunRPC]
  447. public void GetPlayers()
  448. {
  449. if (PhotonNetwork.PlayerList == null || PhotonNetwork.CurrentRoom.PlayerCount == 0)
  450. {
  451. return;
  452. }
  453. for (int i = 0; i < PhotonNetwork.CurrentRoom.PlayerCount; i++)
  454. {
  455. GameObject PlayerElement = Instantiate(PlayerElementPrefab, PlayerParent.transform);
  456. string PlayerName;
  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 object 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[..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 _))
  700. {
  701. RoomProp[DataBase.FirstPlayerIndexIdKey] = firstPlayerIndexID;
  702. }
  703. else
  704. {
  705. RoomProp.Add(DataBase.FirstPlayerIndexIdKey, firstPlayerIndexID);
  706. }
  707. PhotonNetwork.CurrentRoom.SetCustomProperties(RoomProp);
  708. }
  709. }