private void DrawSelectedSegmentGUI() { int segmentIndex = splineEditingGUIDrawer.selectedSegmentIndex; if (segmentIndex < 0 || segmentIndex >= water.Spline.Anchors.Count) { return; } string label = "Selected Segment"; string id = "poseidon-selected-segment"; PEditorCommon.Foldout(label, true, id, () => { EditorGUI.indentLevel -= 1; EditorGUI.BeginChangeCheck(); PSplineSegment s = water.Spline.Segments[segmentIndex]; GUI.enabled = !PSplineToolConfig.Instance.AutoTangent; s.StartTangent = PEditorCommon.InlineVector3Field("Start Tangent", s.StartTangent); s.EndTangent = PEditorCommon.InlineVector3Field("End Tangent", s.EndTangent); GUI.enabled = true; s.ResolutionMultiplierY = EditorGUILayout.Slider("Resolution Multiplier Y", s.ResolutionMultiplierY, 0f, 2f); water.Spline.Segments[segmentIndex] = s; if (EditorGUI.EndChangeCheck()) { water.GenerateSplineMeshAtSegment(segmentIndex); } 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(); } } } }