SelectDNACondition.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Photon.Pun;
  5. using System;
  6. public class SelectDNACondition : MonoBehaviourPunCallbacks
  7. {
  8. public void SetUp
  9. (Player SelectPlayer,
  10. CardSource targetDNA,
  11. Func<int, IEnumerator> SelectDNACoroutine)
  12. {
  13. _selectPlayer = SelectPlayer;
  14. _targetDNA = targetDNA;
  15. _selectDNACoroutine = SelectDNACoroutine;
  16. _notDoSync = false;
  17. }
  18. Player _selectPlayer = null;
  19. CardSource _targetDNA = null;
  20. Func<int, IEnumerator> _selectDNACoroutine = null;
  21. List<int> _candidates = new List<int>();
  22. public int _selectedCount = 0;
  23. public bool _endSelect = false;
  24. bool _notDoSync = false;
  25. public void ResetSelectDNAConditionClass()
  26. {
  27. _selectedCount = 0;
  28. _endSelect = false;
  29. }
  30. public IEnumerator Activate()
  31. {
  32. if (!_notDoSync)
  33. {
  34. //yield return GManager.instance.photonWaitController.StartWait("SelectDNACondition");
  35. }
  36. if(_targetDNA.jogressCondition.Count > 1)
  37. {
  38. if (_targetDNA.jogressCondition.Count == 1)
  39. {
  40. SetDNACondition(0);
  41. }
  42. else
  43. {
  44. List<SelectionElement<int>> selectionElements = new List<SelectionElement<int>>();
  45. for (int i = 0; i < _targetDNA.jogressCondition.Count; i++)
  46. {
  47. string message = $"";
  48. for (int e = 0; e < _targetDNA.jogressCondition[i].elements.Length; e++)
  49. {
  50. message += $"{_targetDNA.jogressCondition[i].elements[e].SelectMessage}";
  51. if (e < _targetDNA.jogressCondition[i].elements.Length - 1)
  52. message += " + ";
  53. }
  54. selectionElements.Add(new(message: $"{message}", value: i, spriteIndex: 0));
  55. }
  56. string selectPlayerMessage = "Which DNA do you want?";
  57. string notSelectPlayerMessage = "The opponent is choosing from which DNA to do.";
  58. GManager.instance.userSelectionManager.SetIntSelection(selectionElements: selectionElements, selectPlayer: _targetDNA.Owner, selectPlayerMessage: selectPlayerMessage, notSelectPlayerMessage: notSelectPlayerMessage);
  59. yield return ContinuousController.instance.StartCoroutine(GManager.instance.userSelectionManager.WaitForEndSelect());
  60. GManager.instance.photonView.RPC("SetDNACondition", RpcTarget.All, GManager.instance.userSelectionManager.SelectedIntValue);
  61. }
  62. }
  63. yield return new WaitWhile(() => !_endSelect);
  64. _endSelect = false;
  65. GManager.instance.commandText.CloseCommandText();
  66. yield return new WaitWhile(() => GManager.instance.commandText.gameObject.activeSelf);
  67. if (_selectDNACoroutine != null)
  68. {
  69. yield return ContinuousController.instance.StartCoroutine(_selectDNACoroutine(_selectedCount));
  70. }
  71. }
  72. [PunRPC]
  73. public void SetDNACondition(int selectedCount)
  74. {
  75. _selectedCount = selectedCount;
  76. _endSelect = true;
  77. }
  78. }