RenderPathLine.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using UnityEngine;
  3. namespace ARLocation
  4. {
  5. /// <summary>
  6. /// This component renders a LocationPath using a given LineRenderer.
  7. /// </summary>
  8. [AddComponentMenu("AR+GPS/Render Path Line")]
  9. [HelpURL("https://http://docs.unity-ar-gps-location.com/guide/#renderpathline")]
  10. public class RenderPathLine : MonoBehaviour
  11. {
  12. public MoveAlongPath.PathSettingsData PathSettings;
  13. public MoveAlongPath.PlacementSettingsData PlacementSettings;
  14. [HideInInspector] public Transform arLocationRoot;
  15. [HideInInspector] public MoveAlongPath moveAlongPath;
  16. public void Start()
  17. {
  18. if (PathSettings.LineRenderer == null)
  19. {
  20. var lineRenderer = gameObject.GetComponent<LineRenderer>();
  21. if (!lineRenderer)
  22. {
  23. throw new NullReferenceException("[AR+GPS][RenderPathLine#Start]: No Line Renderer!");
  24. }
  25. PathSettings.LineRenderer = lineRenderer;
  26. }
  27. arLocationRoot = ARLocationManager.Instance.gameObject.transform;
  28. var pathGameObject = new GameObject($"{gameObject.name} - RenderPathLine");
  29. moveAlongPath = pathGameObject.AddComponent<MoveAlongPath>();
  30. moveAlongPath.PathSettings = PathSettings;
  31. moveAlongPath.PlacementSettings = PlacementSettings;
  32. }
  33. public void SetLocationPath(LocationPath path)
  34. {
  35. if (moveAlongPath != null)
  36. {
  37. moveAlongPath.SetLocationPath(path);
  38. }
  39. }
  40. }
  41. }