DebugLine.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using UnityEngine;
  2. public class DebugLine : MonoBehaviour
  3. {
  4. LineRenderer lr;
  5. Vector3[] vs = new Vector3[100];
  6. Vector3[] vs1 = new Vector3[303];
  7. float startX = -6;
  8. float len = 12;
  9. static DebugLine ins;
  10. void Start()
  11. {
  12. ins = this;
  13. this.lr = this.GetComponent<LineRenderer>();
  14. for (int i = 0; i < ins.vs.Length; i++)
  15. {
  16. this.vs[i].x = startX + len * i / ins.vs.Length;
  17. }
  18. LineRenderer lr1 = this.transform.GetChild(0).GetComponent<LineRenderer>();
  19. for (int i = 0; i < ins.vs1.Length; i+=3)
  20. {
  21. this.vs1[i].x = this.vs1[i+1].x = this.vs1[i+2].x = startX + len * i / 3 / this.vs.Length;
  22. this.vs1[i+1].y = -0.3f;
  23. }
  24. lr1.SetPositions(this.vs1);
  25. }
  26. void OnDestroy()
  27. {
  28. if (ins == this) ins = null;
  29. }
  30. public static void show(float value)
  31. {
  32. if (ins != null) {
  33. for (int i = ins.vs.Length - 1; i > 0; i--)
  34. {
  35. ins.vs[i].y = ins.vs[i - 1].y;
  36. }
  37. ins.vs[0].y = value;
  38. ins.lr.SetPositions(ins.vs);
  39. }
  40. }
  41. public static void showSteady(float value)
  42. {
  43. if (ins != null) {
  44. Transform t = ins.transform.Find("SteadyLine");
  45. Vector3 p = t.localPosition;
  46. p.y = value;
  47. t.localPosition = p;
  48. }
  49. }
  50. }