VFXPlaneGizmos.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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(Plane))]
  10. class VFXPlaneGizmo : VFXSpaceableGizmo<Plane>
  11. {
  12. IProperty<Vector3> m_PositionProperty;
  13. IProperty<Vector3> m_NormalProperty;
  14. public override void RegisterEditableMembers(IContext context)
  15. {
  16. m_PositionProperty = context.RegisterProperty<Vector3>("position");
  17. m_NormalProperty = context.RegisterProperty<Vector3>("normal");
  18. }
  19. public override void OnDrawSpacedGizmo(Plane plane)
  20. {
  21. Vector3 normal = plane.normal.normalized;
  22. if (normal == Vector3.zero)
  23. {
  24. normal = Vector3.up;
  25. }
  26. var normalQuat = Quaternion.FromToRotation(Vector3.forward, normal);
  27. float size = 10;
  28. Vector3[] points = new Vector3[]
  29. {
  30. new Vector3(size, size, 0),
  31. new Vector3(size, -size, 0),
  32. new Vector3(-size, -size, 0),
  33. new Vector3(-size, size, 0),
  34. new Vector3(size, size, 0),
  35. };
  36. using (new Handles.DrawingScope(Handles.matrix * Matrix4x4.Translate(plane.position) * Matrix4x4.Rotate(normalQuat)))
  37. {
  38. Handles.DrawPolyLine(points);
  39. }
  40. Handles.ArrowHandleCap(0, plane.position, normalQuat, 5, Event.current.type);
  41. PositionGizmo(plane.position, Vector3.zero, m_PositionProperty, false);
  42. if (m_NormalProperty.isEditable && NormalGizmo(plane.position, ref normal, false))
  43. {
  44. normal.Normalize();
  45. m_NormalProperty.SetValue(normal);
  46. }
  47. }
  48. public override Bounds OnGetSpacedGizmoBounds(Plane value)
  49. {
  50. return new Bounds(value.position, Vector3.one);
  51. }
  52. }
  53. }