SceneEventOpenDialogLogic.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityGameFramework.Runtime;
  6. public class SceneEventOpenDialogLogic : MonoBehaviour
  7. {
  8. public string taskName = "";
  9. public int npcId;
  10. public int stageIndex;
  11. public bool isNpc = false;
  12. public bool isOnly = true;
  13. /// <summary>
  14. /// 是否任务激活
  15. /// </summary>
  16. public bool isTaskEnable = false;
  17. /// <summary>
  18. /// 对话开启条件 任务卡id
  19. /// </summary>
  20. public int requirementTaskId = 0;
  21. /// <summary>
  22. /// 对话开启条件 步骤id
  23. /// </summary>
  24. public int requirementStepId = 0;
  25. private bool isEntry = false;
  26. Button btnInteractive;
  27. private void Awake()
  28. {
  29. isEntry = false;
  30. }
  31. // Start is called before the first frame update
  32. void Start()
  33. {
  34. SceneEventOpenDialog info = this.gameObject.GetComponent<SceneEventOpenDialog>();
  35. this.taskName = info.taskName;
  36. this.npcId = info.npcId;
  37. this.stageIndex = info.stageIndex;
  38. this.isNpc = info.isNpc;
  39. this.isOnly = info.isOnly;
  40. this.isTaskEnable = info.isTaskEnable;
  41. this.requirementTaskId = info.requirementTaskId;
  42. this.requirementStepId = info.requirementStepId;
  43. if (isTaskEnable)
  44. {
  45. bool isOk = false;
  46. List<TaskCardVo> taskVos = UserProxy.Instance.player.collectTaskCard.GetActivingCards();
  47. foreach (var item in taskVos)
  48. {
  49. if (int.Parse(item.typeId) != requirementTaskId)
  50. {
  51. continue;
  52. }
  53. List<Ins_TaskStepVo> stepVos = item.curSteps;
  54. foreach (var step in stepVos)
  55. {
  56. if (step.typeId == requirementStepId)
  57. {
  58. if (!step.isFinish())
  59. {
  60. isOk = true;
  61. }
  62. }
  63. }
  64. }
  65. if (isOk)
  66. {
  67. this.gameObject.SetActive(true);
  68. }
  69. else
  70. {
  71. this.gameObject.SetActive(false);
  72. }
  73. }
  74. }
  75. public void OnTriggerEnter(Collider collider)
  76. {
  77. if (collider.gameObject.layer != LayerMask.NameToLayer("Player"))
  78. {
  79. return;
  80. }
  81. if(isOnly && isEntry)
  82. {
  83. return;
  84. }
  85. if(!isNpc)
  86. {
  87. EventComponent e = GameEntry.GetComponent<EventComponent>();
  88. e.FireNow(this, new BattleEventOpenDialog(npcId, stageIndex));
  89. this.gameObject.SetActive(false);
  90. }
  91. else
  92. {
  93. BattleCanvas battlePanel = UI_BaseMainWindow.Instance().battleCanvas;
  94. GameObject interactive = battlePanel.transform.Find("Main/Interactive").gameObject;
  95. interactive.SetActive(true);
  96. for (int i=0; i < interactive.transform.childCount; ++i)
  97. {
  98. Transform tsfm = interactive.transform.GetChild(i);
  99. tsfm.gameObject.SetActive(false);
  100. }
  101. GameObject dialog = battlePanel.transform.Find("Main/Interactive/dialog").gameObject;
  102. dialog.SetActive(true);
  103. dialog.transform.Find("Text").GetComponent<Text>().text = taskName;
  104. btnInteractive = dialog.GetComponent<Button>();
  105. EventTriggerListener.Get(btnInteractive.gameObject).onClick = ((_btn) =>
  106. {
  107. OnClickInteractive();
  108. });
  109. }
  110. }
  111. public void OnTriggerExit(Collider collider)
  112. {
  113. if(btnInteractive)
  114. {
  115. btnInteractive.onClick.RemoveAllListeners();
  116. btnInteractive.gameObject.SetActive(false);
  117. }
  118. }
  119. public void EnableCollider()
  120. {
  121. }
  122. public void OnClickInteractive()
  123. {
  124. isEntry = true;
  125. EventComponent e = GameEntry.GetComponent<EventComponent>();
  126. e.FireNow(this, new BattleEventOpenDialog(npcId, stageIndex));
  127. btnInteractive.gameObject.SetActive(false);
  128. btnInteractive.onClick.RemoveAllListeners();
  129. }
  130. }