SceneEventOpenBoxLogic.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityGameFramework.Runtime;
  6. public class SceneEventOpenBoxLogic : MonoBehaviour
  7. {
  8. public int index;
  9. public int[] dropIDs;
  10. public bool isLock = false;
  11. public bool isOpen = false;
  12. public bool isDamnation = false;
  13. public int enableSpawner = 0;
  14. /// <summary>
  15. /// 是否追踪 小地图箭头引导
  16. /// </summary>
  17. public bool isTrack = false;
  18. Button btnInteractive;
  19. private YLBattle.ZoneSpawnerLogic zoneSpawner = null;
  20. private void Awake()
  21. {
  22. }
  23. // Start is called before the first frame update
  24. void Start()
  25. {
  26. SceneEventOpenBox info = this.gameObject.GetComponent<SceneEventOpenBox>();
  27. this.index = info.index;
  28. this.dropIDs = info.dropID;
  29. this.isLock = info.isLock;
  30. this.isOpen = info.isOpen;
  31. this.isDamnation = info.isDamnation;
  32. this.isTrack = info.isTrack;
  33. this.enableSpawner = info.enableSpawner;
  34. SceneCmptManager.Instance.AddTreasureBox(this.gameObject);
  35. if (isDamnation)
  36. {
  37. Animator anim = this.GetComponent<Animator>();
  38. anim.Play("curse", 0, 0);
  39. }
  40. if (isTrack)
  41. {
  42. SceneCmptManager.Instance.AddTrackBox(this.gameObject);
  43. }
  44. // 通过网络数据刷新关卡数据
  45. if(MapTcpProxy.Instance.Peer.MapData.cmptMgr != null)
  46. {
  47. Dictionary<int, NetData.Info_Map_Cmpt_TreasureBox> tbList = MapTcpProxy.Instance.Peer.MapData.cmptMgr._allTreasureBox;
  48. if(tbList.ContainsKey(this.index))
  49. {
  50. this.dropIDs = tbList[this.index].dropID;
  51. this.isLock = tbList[this.index].isLock;
  52. this.isOpen = tbList[this.index].isOpen;
  53. this.isDamnation = tbList[this.index].isDamnation;
  54. this.isTrack = tbList[this.index].isTrack;
  55. this.enableSpawner = tbList[this.index].enableSpawner;
  56. }
  57. }
  58. if (isOpen)
  59. {
  60. Animator anim = this.GetComponent<Animator>();
  61. if (anim)
  62. {
  63. anim.Play("open");
  64. }
  65. isTrack = false;
  66. }
  67. }
  68. public void Update()
  69. {
  70. if (isDamnation)
  71. {
  72. if(!zoneSpawner)
  73. {
  74. zoneSpawner = YLBattle.SpawnerSystem.Instance.GetSpawnerByIndex(enableSpawner);
  75. return;
  76. }
  77. if (zoneSpawner.IsCleanComplete())
  78. {
  79. Animator anim = this.GetComponent<Animator>();
  80. anim.Play("relieve");
  81. isDamnation = false;
  82. }
  83. }
  84. }
  85. public void OnEnable()
  86. {
  87. if (isDamnation && !isOpen)
  88. {
  89. Animator anim = this.GetComponent<Animator>();
  90. anim.Play("curse", 0, 0);
  91. }
  92. if (isOpen)
  93. {
  94. Animator anim = this.GetComponent<Animator>();
  95. if (anim)
  96. {
  97. anim.Play("open");
  98. }
  99. isTrack = false;
  100. }
  101. }
  102. public void OnTriggerEnter(Collider collider)
  103. {
  104. if(isOpen)
  105. {
  106. return;
  107. }
  108. if(collider.gameObject.layer != LayerMask.NameToLayer("Player"))
  109. {
  110. return;
  111. }
  112. UI_BaseMainWindow.Instance().ShowInteractiveIcon(UI_BaseMainWindow.InteractiveType.Storage, (_btn) =>
  113. {
  114. OnClickInteractive();
  115. });
  116. }
  117. public void OnTriggerExit(Collider collider)
  118. {
  119. if (isOpen)
  120. {
  121. return;
  122. }
  123. if (collider.gameObject.layer != LayerMask.NameToLayer("Player"))
  124. {
  125. return;
  126. }
  127. UI_BaseMainWindow.Instance().HideInteractive();
  128. }
  129. public void EnableCollider()
  130. {
  131. }
  132. public void OnClickInteractive()
  133. {
  134. if (!isLock && !isOpen)
  135. {
  136. if(!isDamnation)
  137. {
  138. Animator anim = this.GetComponent<Animator>();
  139. if (anim)
  140. {
  141. anim.Play("open");
  142. }
  143. EventComponent e = GameEntry.GetComponent<EventComponent>();
  144. foreach (var dropID in dropIDs)
  145. {
  146. e.FireNow(this, new BattleEventOpenBoxEvt(dropID));
  147. DropManager.Instance.DropItems(dropID, this.transform.position);
  148. }
  149. btnInteractive.gameObject.SetActive(false);
  150. btnInteractive.onClick.RemoveAllListeners();
  151. isOpen = true;
  152. isTrack = false;
  153. SceneCmptManager.Instance.OpenTreasureBox(this.gameObject);
  154. BattleCanvas.Instance.mapCmpt.RemoveArrow(this.gameObject);
  155. }
  156. // 激活孵化器
  157. if(isDamnation)
  158. {
  159. if(enableSpawner != 0)
  160. {
  161. YLBattle.SpawnerSystem.Instance.EnableSpawnerByIndex(enableSpawner);
  162. zoneSpawner = YLBattle.SpawnerSystem.Instance.GetSpawnerByIndex(enableSpawner);
  163. }
  164. }
  165. // 去除对话泡泡框
  166. SceneBubbleWindow bubble = this.gameObject.GetComponent<SceneBubbleWindow>();
  167. if (bubble)
  168. {
  169. bubble.Hide();
  170. bubble.enabled = false;
  171. }
  172. // 地图怪物同步
  173. MapTcpProxy.Instance.Peer.MapData.cmptMgr.ResetData();
  174. MapTcpProxy.Instance.Peer.ReportDataChange(MapTcpProxy.Instance.Peer.MapData.cmptMgr);
  175. }
  176. }
  177. /// <summary>
  178. /// 掉落 掉率计算
  179. /// </summary>
  180. bool DropItemCompute(float val)
  181. {
  182. int pVal = (int)(val * 100);
  183. //System.Random
  184. return false;
  185. }
  186. }