CheckPathTool.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.Serialization;
  6. public class CheckPathTool : MonoBehaviour
  7. {
  8. public LineRenderer _LineRenderer;
  9. public List<GameObject> posList;
  10. public bool showPath;
  11. private void Awake()
  12. {
  13. _LineRenderer = this.GetComponent<LineRenderer>();
  14. _LineRenderer.enabled = false;
  15. }
  16. private void Start()
  17. {
  18. ActionInstance._Instance.SetCheckPathActive += SetPathActive;
  19. }
  20. private void OnDestroy()
  21. {
  22. ActionInstance._Instance.SetCheckPathActive -= SetPathActive;
  23. }
  24. private void Update()
  25. {
  26. SetPath();
  27. }
  28. public void SetPathActive(bool flag)
  29. {
  30. showPath = false;
  31. _LineRenderer.enabled = flag;
  32. }
  33. public void SetPath()
  34. {
  35. Vector3[] tempPos = new Vector3[posList.Count];
  36. for (int i = 0; i < tempPos.Length; i++)
  37. {
  38. tempPos[i] = posList[i].transform.position;
  39. }
  40. _LineRenderer.positionCount = tempPos.Length;
  41. _LineRenderer.SetPositions(tempPos);
  42. }
  43. }