You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
1.0 KiB

5 years ago
  1. using UnityEditor;
  2. using UnityEngine;
  3. [CustomEditor(typeof(Line))]
  4. public class LineInspector : Editor {
  5. private void OnSceneGUI () {
  6. Line line = target as Line;
  7. Transform handleTransform = line.transform;
  8. Quaternion handleRotation = Tools.pivotRotation == PivotRotation.Local ? handleTransform.rotation : Quaternion.identity;
  9. Vector3 p0 = handleTransform.TransformPoint(line.p0);
  10. Vector3 p1 = handleTransform.TransformPoint(line.p1);
  11. Handles.color = Color.white;
  12. Handles.DrawLine(p0, p1);
  13. EditorGUI.BeginChangeCheck();
  14. p0 = Handles.DoPositionHandle(p0, handleRotation);
  15. if (EditorGUI.EndChangeCheck()) {
  16. Undo.RecordObject(line, "Move Point");
  17. EditorUtility.SetDirty(line);
  18. line.p0 = handleTransform.InverseTransformPoint(p0);
  19. }
  20. EditorGUI.BeginChangeCheck();
  21. p1 = Handles.DoPositionHandle(p1, handleRotation);
  22. if (EditorGUI.EndChangeCheck()) {
  23. Undo.RecordObject(line, "Move Point");
  24. EditorUtility.SetDirty(line);
  25. line.p1 = handleTransform.InverseTransformPoint(p1);
  26. }
  27. }
  28. }