TestTrigger.cs 3.8 KB

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