private void DrawSelectedAnchorGUI() { int anchorIndex = splineEditingGUIDrawer.selectedAnchorIndex; if (anchorIndex < 0 || anchorIndex >= water.Spline.Anchors.Count) { return; } string label = "Selected Anchor"; string id = "poseidon-selected-anchor"; PEditorCommon.Foldout(label, true, id, () => { EditorGUI.indentLevel -= 1; PSplineAnchor a = water.Spline.Anchors[anchorIndex]; EditorGUI.BeginChangeCheck(); a.Position = PEditorCommon.InlineVector3Field("Position", a.Position); a.Rotation = Quaternion.Euler(PEditorCommon.InlineVector3Field("Rotation", a.Rotation.eulerAngles)); a.Scale = PEditorCommon.InlineVector3Field("Scale", a.Scale); water.Spline.Anchors[anchorIndex] = a; if (EditorGUI.EndChangeCheck()) { if (PSplineToolConfig.Instance.AutoTangent) { int[] segmentIndices = water.Spline.SmoothTangents(anchorIndex); water.GenerateSplineMeshAtSegments(segmentIndices); } else { List <int> segmentIndices = water.Spline.FindSegments(anchorIndex); water.GenerateSplineMeshAtSegments(segmentIndices); } } EditorGUI.indentLevel += 1; }); }
private void HandleSelectTransformRemoveAnchor() { List <PSplineAnchor> anchors = water.Spline.Anchors; for (int i = 0; i < anchors.Count; ++i) { PSplineAnchor a = anchors[i]; Vector3 localPos = a.Position; Vector3 worldPos = water.transform.TransformPoint(localPos); float handleSize = HandleUtility.GetHandleSize(worldPos) * 0.2f; if (i == selectedAnchorIndex) { Handles.color = Handles.selectedColor; Handles.SphereHandleCap(0, worldPos, Quaternion.identity, handleSize, EventType.Repaint); bool isGlobalRotation = Tools.pivotRotation == PivotRotation.Global; EditorGUI.BeginChangeCheck(); if (Tools.current == Tool.Move) { worldPos = Handles.PositionHandle(worldPos, isGlobalRotation ? Quaternion.identity : a.Rotation); localPos = water.transform.InverseTransformPoint(worldPos); a.Position = localPos; } else if (Tools.current == Tool.Rotate && !PSplineToolConfig.Instance.AutoTangent) { a.Rotation = Handles.RotationHandle(a.Rotation, worldPos); } else if (Tools.current == Tool.Scale) { a.Scale = Handles.ScaleHandle(a.Scale, worldPos, isGlobalRotation ? Quaternion.identity : a.Rotation, HandleUtility.GetHandleSize(worldPos)); } anchors[i] = a; if (EditorGUI.EndChangeCheck()) { if (PSplineToolConfig.Instance.AutoTangent) { water.Spline.SmoothTangents(selectedAnchorIndex); } List <int> segmentIndices = water.Spline.FindSegments(selectedAnchorIndex); water.GenerateSplineMeshAtSegments(segmentIndices); } } else { Handles.color = Color.cyan; if (Handles.Button(worldPos, Quaternion.identity, handleSize, handleSize * 0.5f, Handles.SphereHandleCap)) { if (Event.current.control) { selectedAnchorIndex = -1; selectedSegmentIndex = -1; water.Spline.RemoveAnchor(i); } else if (Event.current.shift) { if (selectedAnchorIndex != i && selectedAnchorIndex >= 0 && selectedAnchorIndex < anchors.Count) { water.Spline.AddSegment(selectedAnchorIndex, i); if (PSplineToolConfig.Instance.AutoTangent) { int[] segmentsIndices = water.Spline.SmoothTangents(selectedAnchorIndex, i); water.GenerateSplineMeshAtSegments(segmentsIndices); } else { water.GenerateSplineMeshAtSegment(water.Spline.Segments.Count - 1); } selectedAnchorIndex = i; selectedSegmentIndex = -1; } } else { selectedAnchorIndex = i; selectedSegmentIndex = -1; } Event.current.Use(); } } } }