PathDefinition.cs 1012 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using UnityEngine;
  5. public class PathDefinition : BaseBehaviour
  6. {
  7. public IEnumerator<Transform> GetPathEnumerator()
  8. {
  9. if (this.Points == null || this.Points.Length < 1)
  10. {
  11. yield break;
  12. }
  13. int direction = 1;
  14. int index = 0;
  15. for (;;)
  16. {
  17. yield return this.Points[index];
  18. if (this.Points.Length != 1)
  19. {
  20. if (index <= 0)
  21. {
  22. direction = 1;
  23. }
  24. else if (index >= this.Points.Length - 1)
  25. {
  26. direction = -1;
  27. }
  28. index += direction;
  29. }
  30. }
  31. yield break;
  32. }
  33. public void OnDrawGizmos()
  34. {
  35. if (this.Points == null || this.Points.Length < 2)
  36. {
  37. return;
  38. }
  39. List<Transform> list = (from t in this.Points
  40. where t != null
  41. select t).ToList<Transform>();
  42. if (list.Count < 2)
  43. {
  44. return;
  45. }
  46. for (int i = 1; i < list.Count; i++)
  47. {
  48. Gizmos.DrawLine(list[i - 1].position, list[i].position);
  49. }
  50. }
  51. public Transform[] Points;
  52. }