TestTrigger.cs 3.2 KB

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