public override void OnInspectorGUI() { EditorGUI.BeginChangeCheck(); base.OnInspectorGUI(); EditorGUILayout.Space(); EditorGUILayout.BeginVertical("box"); EditorGUILayout.LabelField("预览工具"); //endPos = EditorGUILayout.Vector3Field("终点位置", endPos); //startAngle = EditorGUILayout.FloatField("起点角度", startAngle); //endAngle = EditorGUILayout.FloatField("终点角度", endAngle); EditorGUILayout.EndVertical(); if (EditorGUI.EndChangeCheck()) { DiLineCtrl line = target as DiLineCtrl; Vector3 p1 = line.localP1; Vector3 p2 = line.localP2; Vector3 p3 = line.localEndPos; (target as DiLineCtrl).SetMyLocalTarget(p1, p2, p3); } }
private void OnSceneGUI() { DiLineCtrl line = target as DiLineCtrl; LineRenderer lr = (target as DiLineCtrl).gameObject.GetComponent <LineRenderer>(); Transform handleTransform = line.transform; //p0 Quaternion handleRotation = handleTransform.rotation; // p0 Vector3 controlPoint1 = handleTransform.TransformPoint(line.localP1); Vector3 controlPoint2 = handleTransform.TransformPoint(line.localP2); Vector3 endPoint3 = handleTransform.TransformPoint(line.localEndPos); Handles.color = Color.cyan; Handles.DrawLine(handleTransform.position, endPoint3); Handles.color = Color.black; Handles.DrawLine(handleTransform.position, controlPoint1); Handles.DrawLine(endPoint3, controlPoint2); bool isChanged = false; //bool isStartChanged = false; Handles.color = Color.red; Handles.SphereHandleCap(0, handleTransform.position, handleRotation, 1f, EventType.Repaint); EditorGUI.BeginChangeCheck(); //Vector3 lastPosition = handleTransform.position; handleTransform.position = Handles.DoPositionHandle(handleTransform.position, handleRotation); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(line, "Move Point"); EditorUtility.SetDirty(line); isChanged = true; //isStartChanged = true; } Handles.SphereHandleCap(0, endPoint3, handleRotation, 1f, EventType.Repaint); EditorGUI.BeginChangeCheck(); Vector3 newWorldEndPos = Handles.DoPositionHandle(endPoint3, handleRotation); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(line, "Move Point"); EditorUtility.SetDirty(line); line.localEndPos = handleTransform.InverseTransformPoint(newWorldEndPos); isChanged = true; } Handles.color = Color.blue; Handles.SphereHandleCap(0, controlPoint1, handleRotation, 1f, EventType.Repaint); EditorGUI.BeginChangeCheck(); Vector3 newLocalP1 = Handles.DoPositionHandle(controlPoint1, handleRotation); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(line, "Move Point"); EditorUtility.SetDirty(line); line.localP1 = handleTransform.InverseTransformPoint(newLocalP1); isChanged = true; } Handles.SphereHandleCap(0, controlPoint2, handleRotation, 1f, EventType.Repaint); EditorGUI.BeginChangeCheck(); Vector3 newLocalP2 = Handles.DoPositionHandle(controlPoint2, handleRotation); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(line, "Move Point"); EditorUtility.SetDirty(line); line.localP2 = handleTransform.InverseTransformPoint(newLocalP2); isChanged = true; } if (isChanged) { //if (isStartChanged) { // Vector3 offset = handleTransform.position - lastPosition; // line.localP1 += offset; // line.localP2 += offset; // line.localEndPos += offset; //} Vector3 p1 = line.localP1; Vector3 p2 = line.localP2; Vector3 p3 = line.localEndPos; line.SetMyLocalTarget(p1, p2, p3); } }