VFXLineGizmos.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using UnityEngine;
  6. using UnityEngine.VFX;
  7. namespace UnityEditor.VFX
  8. {
  9. [VFXGizmo(typeof(Line))]
  10. class VFXLineGizmo : VFXSpaceableGizmo<Line>
  11. {
  12. IProperty<Vector3> m_StartProperty;
  13. IProperty<Vector3> m_EndProperty;
  14. public override void RegisterEditableMembers(IContext context)
  15. {
  16. m_StartProperty = context.RegisterProperty<Vector3>("start");
  17. m_EndProperty = context.RegisterProperty<Vector3>("end");
  18. }
  19. public override void OnDrawSpacedGizmo(Line line)
  20. {
  21. Handles.DrawLine(line.start, line.end);
  22. PositionGizmo(line.start, Vector3.zero, m_StartProperty, true);
  23. PositionGizmo(line.end, Vector3.zero, m_EndProperty, true);
  24. }
  25. public override Bounds OnGetSpacedGizmoBounds(Line value)
  26. {
  27. Vector3 center = (value.start + value.end) * 0.5f;
  28. Vector3 size = value.end - value.start;
  29. size.x = Mathf.Abs(size.x);
  30. size.y = Mathf.Abs(size.y);
  31. size.z = Mathf.Abs(size.z);
  32. return new Bounds(center, size);
  33. }
  34. }
  35. }