TestTrigger.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. public Robot robot;
  25. /// <summary>
  26. /// 4个区域的累计触发次数
  27. /// </summary>
  28. private int[] udpTrigger;
  29. void Start()
  30. {
  31. udpTrigger = new int[4];
  32. for (int i = 0; i < udpTrigger.Length; i++)
  33. {
  34. udpTrigger[i] = 0;
  35. }
  36. }
  37. private void LateUpdate()
  38. {
  39. if (API_SVR.GetHead() != null && transform.position != API_SVR.GetHead().transform.position)
  40. {
  41. transform.position = API_SVR.GetHead().transform.position;
  42. mapPlayer.position = transform.position;
  43. mapPlayer.eulerAngles = API_SVR.GetHead().transform.eulerAngles;
  44. //transform.eulerAngles = API_SVR.GetHead().transform.eulerAngles;
  45. }
  46. }
  47. private void OnTriggerEnter(Collider other)
  48. {
  49. Debug.Log(other.name);
  50. QueryBox(other, true);
  51. }
  52. private void OnTriggerExit(Collider other)
  53. {
  54. QueryBox(other, false);
  55. AudioManager.Instance.StopMusic();
  56. }
  57. /// <summary>
  58. /// 查找触发器
  59. /// </summary>
  60. /// <param name="other"></param>
  61. /// <param name="state"></param>
  62. private void QueryBox(Collider other, bool state)
  63. {
  64. for (int i = 0; i < list_box.Count; i++)
  65. {
  66. if (other.name == list_box[i].name)
  67. {
  68. if (state)
  69. {
  70. HttpSocket.Instance.SendIpToPointTrigger(list_TriggerName[i < 4 ? 0 : i % 3], AllTool.GetTimeStamp());
  71. }
  72. // 擎天柱大模型关闭
  73. if (!state && i < list_Effects.Count && list_Effects[i].name == "P6")
  74. {
  75. testP6Car.CloseTestObj();
  76. }
  77. SetShowObject(list_points[i], list_Effects[i], state);
  78. teshMap.testMinMapShow.ShowMap(state);
  79. teshMap.testMaxMapShow.ShowMap(state);
  80. }
  81. }
  82. }
  83. /// <summary>
  84. /// 设置显示效果(触发器判定选择)
  85. /// </summary>
  86. private void SetShowObject(GameObject Obj, GameObject Effect, bool state)
  87. {
  88. Effect.SetActive(state);
  89. Obj.SetActive(!state);
  90. if (state)
  91. robot.Walk(Effect.name);
  92. if (state == false && Effect.name == "Party")
  93. robot.transform.parent.gameObject.SetActive(true);
  94. }
  95. private void SetShowObject(GameObject Effect, bool state)
  96. {
  97. Effect.SetActive(state);
  98. }
  99. }