RoomManager.cs 27 KB

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