TestTrigger.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class TestTrigger : MonoBehaviour
  6. {
  7. public Text text;
  8. /// <summary>
  9. /// 所有触发器
  10. /// </summary>
  11. public List<GameObject> list_box;
  12. /// <summary>
  13. /// 对应触发器显示的效果
  14. /// </summary>
  15. public List<GameObject> list_Effects;
  16. /// <summary>
  17. /// 水晶点
  18. /// </summary>
  19. public List<GameObject> list_points;
  20. public Transform mapPlayer;
  21. public TeshMap teshMap;
  22. public TestP6Car testP6Car;
  23. public List<string> list_TriggerName;
  24. /// <summary>
  25. /// 4个区域的累计触发次数
  26. /// </summary>
  27. private int[] udpTrigger;
  28. void Start()
  29. {
  30. udpTrigger = new int[4];
  31. for (int i = 0; i < udpTrigger.Length; i++)
  32. {
  33. udpTrigger[i] = 0;
  34. }
  35. }
  36. private void LateUpdate()
  37. {
  38. if (API_SVR.GetHead() != null && transform.position != API_SVR.GetHead().transform.position)
  39. {
  40. transform.position = API_SVR.GetHead().transform.position;
  41. mapPlayer.position = transform.position;
  42. mapPlayer.eulerAngles = API_SVR.GetHead().transform.eulerAngles;
  43. //transform.eulerAngles = API_SVR.GetHead().transform.eulerAngles;
  44. }
  45. }
  46. private void OnTriggerEnter(Collider other)
  47. {
  48. Debug.Log(other.name);
  49. QueryBox(other, true);
  50. }
  51. private void OnTriggerExit(Collider other)
  52. {
  53. QueryBox(other, false);
  54. AudioManager.Instance.StopMusic();
  55. }
  56. /// <summary>
  57. /// 查找触发器
  58. /// </summary>
  59. /// <param name="other"></param>
  60. /// <param name="state"></param>
  61. private void QueryBox(Collider other, bool state)
  62. {
  63. for (int i = 0; i < list_box.Count; i++)
  64. {
  65. if (other.name == list_box[i].name)
  66. {
  67. if (state)
  68. {
  69. HttpSocket.Instance.SendIpToPointTrigger(list_TriggerName[i < 4 ? 0 : i % 3], AllTool.GetTimeStamp());
  70. }
  71. // 擎天柱大模型关闭
  72. if (!state && i < list_Effects.Count && list_Effects[i].name == "P6")
  73. {
  74. testP6Car.CloseTestObj();
  75. }
  76. SetShowObject(list_points[i], list_Effects[i], state);
  77. teshMap.testMinMapShow.ShowMap(state);
  78. teshMap.testMaxMapShow.ShowMap(state);
  79. }
  80. }
  81. }
  82. /// <summary>
  83. /// 设置显示效果(触发器判定选择)
  84. /// </summary>
  85. private void SetShowObject(GameObject Obj, GameObject Effect, bool state)
  86. {
  87. Effect.SetActive(state);
  88. Obj.SetActive(!state);
  89. }
  90. private void SetShowObject(GameObject Effect, bool state)
  91. {
  92. Effect.SetActive(state);
  93. }
  94. }