SceneEventMapSwitchLogic.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityGameFramework.Runtime;
  6. using UnityEngine.AI;
  7. /// <summary>
  8. /// 场景 传送点
  9. /// </summary>
  10. public class SceneEventMapSwitchLogic : MonoBehaviour
  11. {
  12. public SceneEventMapSwitch info;
  13. /// <summary>
  14. /// 延迟传送时间
  15. /// </summary>
  16. public float delayTime;
  17. Collider player;
  18. /// <summary>
  19. /// 传送节点列表
  20. /// </summary>
  21. static Dictionary<int, SceneEventMapSwitchLogic> teleportList = new Dictionary<int, SceneEventMapSwitchLogic>();
  22. /// <summary>
  23. /// 间隔事件
  24. /// </summary>
  25. static float intervalTime = 2f;
  26. /// <summary>
  27. /// 如果刚刚传送过来 第一次进入事件忽略
  28. /// </summary>
  29. bool isTeleport = true;
  30. private void Awake()
  31. {
  32. SceneCmptManager.Instance.AddMapSwitchCmpt(this.gameObject);
  33. info = this.gameObject.GetComponent<SceneEventMapSwitch>();
  34. if (!teleportList.ContainsKey(info.switchIndex))
  35. {
  36. teleportList.Add(info.switchIndex, this);
  37. }
  38. else
  39. {
  40. teleportList[info.switchIndex] = this;
  41. }
  42. }
  43. // Start is called before the first frame update
  44. void Start()
  45. {
  46. AddFunctionIcon();
  47. }
  48. public void OnTriggerEnter(Collider collider)
  49. {
  50. if (collider.gameObject.layer != LayerMask.NameToLayer("Player"))
  51. {
  52. return;
  53. }
  54. if(!isTeleport)
  55. {
  56. return;
  57. }
  58. if(info.isDuplicate)
  59. {
  60. Invoke("SetInteractiveBtn", delayTime);
  61. }
  62. else
  63. {
  64. Invoke("TeleportPoint",delayTime);
  65. }
  66. }
  67. public void OnTriggerExit(Collider collider)
  68. {
  69. if (collider.gameObject.layer != LayerMask.NameToLayer("Player"))
  70. {
  71. return;
  72. }
  73. isTeleport = true;
  74. if (info.isDuplicate)
  75. {
  76. UI_BaseMainWindow.Instance().HideInteractive();
  77. }
  78. }
  79. public void SetInteractiveBtn()
  80. {
  81. BattleCanvas battlePanel = UI_BaseMainWindow.Instance().battleCanvas;
  82. GameObject interactiveObj = battlePanel.transform.Find("Main/Interactive").gameObject;
  83. interactiveObj.SetActive(true);
  84. GameObject interactiveBtnObj = battlePanel.transform.Find("Main/Interactive/collect").gameObject;
  85. UI_BaseMainWindow.Instance().ShowInteractiveIcon(UI_BaseMainWindow.InteractiveType.Teleport, (_btn) =>
  86. {
  87. OpenDuplicateWindow();
  88. });
  89. }
  90. public void SetTeleportClose()
  91. {
  92. isTeleport = false;
  93. }
  94. public void EnableCollider()
  95. {
  96. }
  97. public void OpenDuplicateWindow()
  98. {
  99. isTeleport = false;
  100. UI_DuplicateWindow.gateIdType = info.NextMapId;
  101. UI_DuplicateWindow.appointFloor = info.appointFloor;
  102. UI_DuplicateWindow.switchIndex = info.switchIndex;
  103. switch (info.NextMapId)
  104. {
  105. case 200101:
  106. UI_DuplicateWindow.floorNum = 10;
  107. UI_DuplicateWindow.duplicateTypeName = "<color=magenta>" + "唤灵师碎片" + "</color>";
  108. PanelHelper.Instance.ShowPanel("UI_DuplicateFloorWindow");
  109. break;
  110. case 200201:
  111. UI_DuplicateWindow.floorNum = 5;
  112. UI_DuplicateWindow.duplicateTypeName = "<color=magenta>" + "武器突破石" + "</color>";
  113. PanelHelper.Instance.ShowPanel("UI_DuplicateFloorWindow");
  114. break;
  115. case 200301:
  116. UI_DuplicateWindow.floorNum = 5;
  117. UI_DuplicateWindow.duplicateTypeName = "<color=magenta>" + "言灵突破石" + "</color>";
  118. PanelHelper.Instance.ShowPanel("UI_DuplicateFloorWindow");
  119. break;
  120. case 210101:
  121. case 210102:
  122. case 210103:
  123. case 210104:
  124. case 210105:
  125. case 210106:
  126. case 210107:
  127. case 210108:
  128. UI_DuplicateWindow.floorNum = 10;
  129. UI_DuplicateWindow.duplicateTypeName = "<color=magenta>" + "言灵召唤材料" + "</color>";
  130. PanelHelper.Instance.ShowPanel("UI_DuplicateFloorWindow");
  131. break;
  132. case 210201:
  133. UI_DuplicateWindow.floorNum = 5;
  134. UI_DuplicateWindow.duplicateTypeName = "<color=magenta>" + "武器强化符" + "</color>";
  135. PanelHelper.Instance.ShowPanel("UI_DuplicateFloorWindow");
  136. break;
  137. case 210301:
  138. case 210302:
  139. case 210303:
  140. UI_DuplicateWindow.floorNum = 5;
  141. UI_DuplicateWindow.duplicateTypeName = "<color=magenta>" + "武器突破材料" + "</color>";
  142. PanelHelper.Instance.ShowPanel("UI_DuplicateFloorWindow");
  143. break;
  144. case 210401:
  145. case 210402:
  146. case 210403:
  147. case 210404:
  148. case 210405:
  149. case 210406:
  150. case 210407:
  151. case 210408:
  152. UI_DuplicateWindow.floorNum = 5;
  153. UI_DuplicateWindow.duplicateTypeName = "<color=magenta>" + "言灵突破材料" + "</color>";
  154. PanelHelper.Instance.ShowPanel("UI_DuplicateFloorWindow");
  155. break;
  156. case 507001:
  157. UI_DuplicateWindow.floorNum = 1;
  158. UI_DuplicateWindow.duplicateTypeName = "<color=magenta>" + "Boss战副本" + "</color>";
  159. PanelHelper.Instance.ShowPanel("UI_DuplicateFloorWindow");
  160. break;
  161. case 507002:
  162. UI_DuplicateWindow.floorNum = 1;
  163. UI_DuplicateWindow.duplicateTypeName = "<color=magenta>" + "Boss战副本" + "</color>";
  164. PanelHelper.Instance.ShowPanel("UI_DuplicateFloorWindow");
  165. break;
  166. }
  167. }
  168. public void TeleportPoint()
  169. {
  170. if(info.switchIndex != 0)
  171. {
  172. GameDateManager.Instance.GateID = info.NextMapId;
  173. GameDateManager.Instance.GateVO = new UIVO_Gate.SelectGateVo((UIVO_Gate.EGateDiffculty)GameDateManager.Instance.GateDifficulty);
  174. GameDateManager.Instance.GateVO.gateId = info.NextMapId;
  175. GameDateManager.Instance.isBackTicket = false;
  176. GameDateManager.Instance.IsBackDoor = false;
  177. isTeleport = false;
  178. GameDateManager.Instance.CreateMapSwitchPoint = info.NextSwitchIndex;
  179. //// 上传本张地图数据同步到服务器
  180. //var mapdata = new NetData.Info_Map()
  181. //{
  182. // mapId = UserProxy.Instance.player.newMap.curMapId,
  183. //};
  184. //mapdata.ResetData();
  185. //MapTcpProxy.Instance.Peer.ReportDataChange(mapdata);
  186. // 获取下一张地图服务器数据
  187. MapTcpProxy.Instance.Peer.SwitchNextMap(GameDateManager.Instance.GateID, 0, (mapData) =>
  188. {
  189. // 切换关卡
  190. EventComponent eventCmpt = GameEntry.GetComponent<EventComponent>();
  191. SceneCmptManager.Instance.Reset();
  192. if(info.isEntry)
  193. {
  194. eventCmpt.FireNow(this, new MainEventGoBattle(GameDateManager.Instance.GateID, GameDateManager.Instance.GateDifficulty, info.NextSwitchIndex));
  195. }
  196. else
  197. {
  198. eventCmpt.FireNow(this, new MainEventGoBattle(GameDateManager.Instance.GateID, GameDateManager.Instance.GateDifficulty, MapTcpProxy.Instance.Peer.MapData.BirthPoint));
  199. }
  200. });
  201. }
  202. }
  203. public void AddFunctionIcon()
  204. {
  205. string srcName = "";
  206. if(info.isEntry)
  207. {
  208. srcName = "minimap_entry";
  209. }
  210. else
  211. {
  212. srcName = "minimap_export";
  213. }
  214. ResourceHelper.Instance.LoadAssetBundle(srcName, (ab) =>
  215. {
  216. GameObject iconObj = (GameObject)Instantiate(ab.LoadAsset(srcName));
  217. iconObj.SetActive(true);
  218. iconObj.SetLayerRecursively(LayerMask.NameToLayer("MiniMap"));
  219. iconObj.AddComponent<SceneCmptIconByMiniMap>();
  220. iconObj.transform.parent = this.transform;
  221. iconObj.transform.position = Vector3.zero;
  222. iconObj.transform.localPosition = Vector3.zero;
  223. iconObj.transform.SetLocalPositionY(0.5f);
  224. });
  225. }
  226. }