public void HandleSinglePointSelection() { ISelection selection = ShapeEditorCache.GetSelection(); if (selection.single != -1) { TangentMode mode = GetTangentMode(selection.single); SetTangentMode(selection.single, TangentMode.Broken); Vector3 leftTangent = GetLeftTangent(selection.single); Vector3 rightTangent = GetRightTangent(selection.single); ShapeEditorCache.instance.leftTangent = leftTangent; ShapeEditorCache.instance.rightTangent = rightTangent; ShapeEditorCache.instance.rightTangentChanged = true; if (rightTangent.magnitude == 0f) { ShapeEditorCache.instance.rightTangentChanged = false; } SetTangentMode(selection.single, mode); } }
private void ValidateTangents(bool rightTangentChanged) { ISelection selection = ShapeEditorCache.GetSelection(); TangentMode mode = GetTangentMode(selection.single); Vector3 leftTangent = GetLeftTangent(selection.single); Vector3 rightTangent = GetRightTangent(selection.single); if (mode == TangentMode.Continuous) { if (rightTangentChanged) { leftTangent = -rightTangent; } else { rightTangent = -leftTangent; } } SetLeftTangent(selection.single, leftTangent); SetRightTangent(selection.single, rightTangent); ShapeEditorCache.RecordUndo(); ShapeEditorCache.instance.rightTangentChanged = rightTangentChanged; if (rightTangentChanged) { ShapeEditorCache.instance.rightTangent = rightTangent; } else { ShapeEditorCache.instance.leftTangent = leftTangent; } }
private void DrawPoints() { if (currentEvent.type != EventType.Repaint) { return; } for (int index = 0; index < GetPointCount(); index++) { var position = GetPosition(index); if (m_ActivePointIndex == index) { GetPointCapActive(0, position, Quaternion.LookRotation(GetForwardVector(), GetUpVector()), GetHandleSize(position), currentEvent.type); } else if (m_HoveredPointIndex == index && GUIUtility.hotControl == 0) { GetPointCapHovered(0, position, Quaternion.LookRotation(GetForwardVector(), GetUpVector()), GetHandleSize(position), currentEvent.type); } else if (ShapeEditorCache.GetSelection().IsSelected(index)) { GetPointCapSelected(0, position, Quaternion.LookRotation(GetForwardVector(), GetUpVector()), GetHandleSize(position), currentEvent.type); } else { GetPointCapNormal(0, position, Quaternion.LookRotation(GetForwardVector(), GetUpVector()), GetHandleSize(position), currentEvent.type); } } }
public void OnInspectorGUI(Spline spline) { m_Spline = spline; EditorGUI.BeginChangeCheck(); DoTangentGUI(); if (EditMode.IsOwner(m_CurrentEditor)) { SnappingUtility.enabled = EditorGUILayout.Toggle(Contents.enableSnapLabel, SnappingUtility.enabled); } if (ShapeEditorCache.GetSelection().Count > 0) { DoPointInspector(); } if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(m_CurrentEditor.target); } HandleHotKeys(); }
public void CycleSpriteIndex() { ISelection selection = ShapeEditorCache.GetSelection(); if (selection.single == -1) { return; } int nextIndex = SplineUtility.NextIndex(selection.single, m_Spline.GetPointCount()); float angle = SpriteShapeHandleUtility.PosToAngle(m_Spline.GetPosition(selection.single), m_Spline.GetPosition(nextIndex), 0f); int angleRangeIndex = SpriteShapeEditorUtility.GetRangeIndexFromAngle(m_SpriteShape, angle); if (angleRangeIndex == -1) { return; } AngleRange angleRange = m_SpriteShape.angleRanges[angleRangeIndex]; int spriteIndex = (m_Spline.GetSpriteIndex(selection.single) + 1) % angleRange.sprites.Count; Undo.RecordObject(m_CurrentEditor.target, "Edit Sprite Index"); m_Spline.SetSpriteIndex(selection.single, spriteIndex); EditorUtility.SetDirty(m_CurrentEditor.target); }
private void DrawTangents() { ISelection selection = ShapeEditorCache.GetSelection(); int selectedPoint = selection.single; if (selectedPoint == -1 || GetTangentMode(selectedPoint) == TangentMode.Linear || currentEvent.type != EventType.Repaint) { return; } Vector3 position = GetPosition(selectedPoint); Vector3 leftTangent = GetLeftTangent(selectedPoint); Vector3 rightTangent = GetRightTangent(selection.single); Color color = kTangentColor; DrawTangentLine(position, leftTangent, color); if (GetTangentMode(selectedPoint) == TangentMode.Broken) { color = kTangentColorAlternative; } DrawTangentLine(position, rightTangent, color); if (m_ActiveTangentPointIndex != -1) { if (m_DragLeftTangent) { GetTangentCapActive(0, leftTangent + position, Quaternion.identity, GetHandleSize(leftTangent + position), EventType.Repaint); GetTangentCapNormal(0, rightTangent + position, Quaternion.identity, GetHandleSize(rightTangent + position), EventType.Repaint); } else { GetTangentCapNormal(0, leftTangent + position, Quaternion.identity, GetHandleSize(leftTangent + position), EventType.Repaint); GetTangentCapActive(0, rightTangent + position, Quaternion.identity, GetHandleSize(rightTangent + position), EventType.Repaint); } } else if (GUIUtility.hotControl == 0 && m_HoveredTangentPoint != -1) { if (m_HoveredLeftTangent) { GetTangentCapHovered(0, leftTangent + position, Quaternion.identity, GetHandleSize(leftTangent + position), EventType.Repaint); GetTangentCapNormal(0, rightTangent + position, Quaternion.identity, GetHandleSize(rightTangent + position), EventType.Repaint); } else { GetTangentCapNormal(0, leftTangent + position, Quaternion.identity, GetHandleSize(leftTangent + position), EventType.Repaint); GetTangentCapHovered(0, rightTangent + position, Quaternion.identity, GetHandleSize(rightTangent + position), EventType.Repaint); } } else { GetTangentCapNormal(0, leftTangent + position, Quaternion.identity, GetHandleSize(leftTangent + position), EventType.Repaint); GetTangentCapNormal(0, rightTangent + position, Quaternion.identity, GetHandleSize(rightTangent + position), EventType.Repaint); } }
void DoTangentGUI() { ISelection selection = ShapeEditorCache.GetSelection(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(Contents.pointModeLabel); ShapeTangentMode?tangentMode = null; if (selection.single != -1) { tangentMode = m_Spline.GetTangentMode(selection.single); } ShapeTangentMode?prevTangentMode = tangentMode; GUIContent tangentStraightIcon = Contents.tangentStraightIcon; GUIContent tangentCurvedIcon = Contents.tangentCurvedIcon; GUIContent tangentAsymmetricIcon = Contents.tangentAsymmetricIcon; if (EditorGUIUtility.isProSkin) { tangentStraightIcon = Contents.tangentStraightIconPro; tangentCurvedIcon = Contents.tangentCurvedIconPro; tangentAsymmetricIcon = Contents.tangentAsymmetricIconPro; } using (new EditorGUI.DisabledScope(selection.single == -1)) { if (GUILayout.Toggle(tangentMode == ShapeTangentMode.Linear, tangentStraightIcon, new GUIStyle("Button"), GUILayout.Height(23), GUILayout.Width(29))) { tangentMode = ShapeTangentMode.Linear; } if (GUILayout.Toggle(tangentMode == ShapeTangentMode.Continuous, tangentCurvedIcon, new GUIStyle("Button"), GUILayout.Height(23), GUILayout.Width(29))) { tangentMode = ShapeTangentMode.Continuous; } if (GUILayout.Toggle(tangentMode == ShapeTangentMode.Broken, tangentAsymmetricIcon, new GUIStyle("Button"), GUILayout.Height(23), GUILayout.Width(29))) { tangentMode = ShapeTangentMode.Broken; } if (tangentMode.HasValue && prevTangentMode.HasValue && tangentMode.Value != prevTangentMode.Value) { Undo.RecordObject(m_CurrentEditor.target, "Edit Tangent Mode"); RefreshTangentsAfterModeChange(selection.single, tangentMode.Value); } } EditorGUILayout.EndHorizontal(); }
private void MoveSelectedPoints(Vector3 delta) { ISelection selection = ShapeEditorCache.GetSelection(); RecordUndo(); if (delta.sqrMagnitude < float.Epsilon) { return; } foreach (int index in selection) { SetPosition(index, GetPosition(index) + delta); } }
private void CycleTangentMode() { ISelection selection = ShapeEditorCache.GetSelection(); if (selection.single == -1) { return; } Undo.RecordObject(m_CurrentEditor.target, "Edit Tangent Mode"); ShapeTangentMode oldMode = m_Spline.GetTangentMode(selection.single); ShapeTangentMode newMode = GetNextTangentMode(oldMode); RefreshTangentsAfterModeChange(selection.single, newMode); }
private void Framing() { if (GetPointCount() == 0) { return; } ISelection selection = ShapeEditorCache.GetSelection(); if (currentEvent.commandName == "FrameSelected" && selection.Count > 0) { switch (currentEvent.type) { case EventType.ExecuteCommand: Bounds bounds = default(Bounds); if (selection.Count == 0) { bounds = new Bounds(GetPosition(0), Vector3.zero); for (int index = 1; index < GetPointCount(); ++index) { bounds.Encapsulate(GetPosition(index)); } } else { bounds = new Bounds(GetPosition(selection.any), Vector3.zero); foreach (int index in selection) { bounds.Encapsulate(GetPosition(index)); } } Frame(bounds); currentEvent.Use(); break; case EventType.ValidateCommand: currentEvent.Use(); break; } } }
private void DoRectSelectionGUI() { ISelection selection = ShapeEditorCache.GetSelection(); if (m_RectSelectionID == -1) { m_RectSelectionID = GUIUtility.GetControlID("RectSelection".GetHashCode(), FocusType.Passive); } if (Event.current.GetTypeForControl(m_RectSelectionID) == EventType.MouseDown && Event.current.button == 0) { if (!Event.current.shift && !EditorGUI.actionKey) { ShapeEditorCache.RecordUndo("Edit Selection"); ShapeEditorCache.ClearSelection(); GUI.changed = true; } } if (Event.current.GetTypeForControl(m_RectSelectionID) == EventType.MouseUp && Event.current.button == 0) { ShapeEditorCache.RecordUndo("Edit Selection"); selection.EndSelection(true); m_ShapeEditor.HandleSinglePointSelection(); GUI.changed = true; } EditorGUI.BeginChangeCheck(); Rect selectionRect = m_RectSelectionTool.Do(m_RectSelectionID, (m_CurrentEditor.target as Component).transform.position); if (EditorGUI.EndChangeCheck()) { selection.BeginSelection(); for (int i = 0; i < m_Spline.GetPointCount(); ++i) { if (selectionRect.Contains(HandleUtility.WorldToGUIPoint(LocalToWorld(m_Spline.GetPosition(i))), true)) { selection.Select(i, true); } } } }
private void LayoutTangents() { ISelection selection = ShapeEditorCache.GetSelection(); int selectedPoint = selection.single; if (selectedPoint == -1 || GetTangentMode(selectedPoint) == TangentMode.Linear) { return; } int tangentId = GUIUtility.GetControlID("Tangent".GetHashCode(), FocusType.Passive); Vector3 position = GetPosition(selectedPoint); if (currentEvent.type == EventType.Layout) { Vector3 leftTangentPosition = GetLeftTangent(selectedPoint); GetTangentCapNormal(tangentId, leftTangentPosition + position, Quaternion.identity, GetHandleSize(leftTangentPosition + position), EventType.Layout); if (HandleUtility.nearestControl == tangentId) { m_HoveredTangentPoint = selectedPoint; m_HoveredLeftTangent = true; m_HoveredPointIndex = -1; } } tangentId = GUIUtility.GetControlID("Tangent".GetHashCode(), FocusType.Passive); if (currentEvent.type == EventType.Layout) { Vector3 rightTangentPosition = GetRightTangent(selection.single); GetTangentCapNormal(tangentId, rightTangentPosition + position, Quaternion.identity, GetHandleSize(rightTangentPosition + position), EventType.Layout); if (HandleUtility.nearestControl == tangentId) { m_HoveredTangentPoint = selectedPoint; m_HoveredLeftTangent = false; m_HoveredPointIndex = -1; } } }
private void SelectPoint(int index) { ISelection selection = ShapeEditorCache.GetSelection(); bool additive = currentEvent.shift; bool subtractive = EditorGUI.actionKey; ShapeEditorCache.RecordUndo("Edit Selection"); if (!additive && !subtractive) { ShapeEditorCache.ClearSelection(); } selection.Select(index, (!selection.IsSelected(index) || additive) && !subtractive); HandleSinglePointSelection(); GUI.changed = true; }
private void ValidateSelection() { int pointCount = m_SpriteShapeController.spline.GetPointCount(); bool selectionValid = true; ISelection selection = ShapeEditorCache.GetSelection(); foreach (int index in selection) { if (index >= pointCount) { selectionValid = false; break; } } if (!selectionValid) { ShapeEditorCache.RecordUndo(); ShapeEditorCache.ClearSelection(); } }
private void DeleteSelected() { ISelection selection = ShapeEditorCache.GetSelection(); if (GetPointCount() <= 2) { return; } RecordUndo(); List <int> indices = new List <int>(selection); indices.Sort(); for (int i = indices.Count - 1; i >= 0; --i) { RemovePointAt(indices[i]); } ClearSelection(); GUI.changed = true; }
private void DoPointInspector() { ISelection selection = ShapeEditorCache.GetSelection(); List <Vector3> positions = new List <Vector3>(); List <float> heights = new List <float>(); List <float> bevelCutoffs = new List <float>(); List <float> bevelSizes = new List <float>(); List <int> spriteIndices = new List <int>(); List <bool> corners = new List <bool>(); foreach (int index in selection) { positions.Add(m_Spline.GetPosition(index)); heights.Add(m_Spline.GetHeight(index)); bevelCutoffs.Add(m_Spline.GetBevelCutoff(index)); bevelSizes.Add(m_Spline.GetBevelSize(index)); spriteIndices.Add(m_Spline.GetSpriteIndex(index)); corners.Add(m_Spline.GetCorner(index)); } EditorGUIUtility.wideMode = true; EditorGUI.BeginChangeCheck(); positions = MultiVector2Field(Contents.positionLabel, positions, 1.5f); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(m_CurrentEditor.target, "Undo Inspector"); for (int index = 0; index < positions.Count; index++) { m_Spline.SetPosition(selection.ElementAt(index), positions[index]); } SceneView.RepaintAll(); } EditorGUIUtility.wideMode = false; bool mixedValue = EditorGUI.showMixedValue; EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = !heights.All(v => Mathf.Approximately(v, heights.First())); float height = EditorGUILayout.Slider(Contents.heightLabel, heights[0], 0.1f, 2.0f); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(m_CurrentEditor.target, "Undo Inspector"); foreach (int index in selection) { m_Spline.SetHeight(index, height); } } EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = !bevelCutoffs.All(v => Mathf.Approximately(v, bevelCutoffs.First())); float cornerTolerance = EditorGUILayout.Slider(Contents.bevelCutoffLabel, bevelCutoffs[0], 0, 180.0f); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(m_CurrentEditor.target, "Undo Inspector"); foreach (int index in selection) { m_Spline.SetBevelCutoff(index, cornerTolerance); } } EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = !bevelSizes.All(v => Mathf.Approximately(v, bevelSizes.First())); float bevelLength = EditorGUILayout.Slider(Contents.bevelSizeLabel, bevelSizes[0], 0.0f, 0.5f); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(m_CurrentEditor.target, "Undo Inspector"); foreach (int index in selection) { m_Spline.SetBevelSize(index, bevelLength); } } EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = !spriteIndices.All(v => (v == spriteIndices.First())); int spriteIndex = EditorGUILayout.IntSlider(Contents.spriteIndexLabel, spriteIndices[0], 0, 63); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(m_CurrentEditor.target, "Undo Inspector"); foreach (int index in selection) { m_Spline.SetSpriteIndex(index, spriteIndex); } } EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = !corners.All(v => (v == corners.First())); int val = (int)EditorGUILayout.IntPopup(Contents.cornerLabel, corners[0] ? 1 : 0, Contents.cornerOptions, Contents.cornerValues); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(m_CurrentEditor.target, "Undo Inspector"); foreach (int index in selection) { m_Spline.SetCorner(index, (val > 0) ? true : false); } } EditorGUI.showMixedValue = mixedValue; }