private int GetAngleRange(int index) { int startPoint = 0; SpriteShapeController sc = SplineEditorCache.GetTarget(); return(GetAngleRange(sc, index, ref startPoint)); }
private void ResetTangents(int pointIndex) { Vector3 position = GetPosition(pointIndex); Vector3 positionNext = GetPosition(SplineUtility.NextIndex(pointIndex, GetPointCount())); Vector3 positionPrev = GetPosition(SplineUtility.PreviousIndex(pointIndex, GetPointCount())); Vector3 forward = Vector3.forward; if (SplineEditorCache.IsValid() && SplineEditorCache.GetTarget() != null) { forward = SplineEditorCache.GetTarget().transform.forward; } float scale = Mathf.Min((positionNext - position).magnitude, (positionPrev - position).magnitude) * 0.33f; Vector3 leftTangent = (positionPrev - position).normalized * scale; Vector3 rightTangent = (positionNext - position).normalized * scale; if (GetTangentMode(pointIndex) == TangentMode.Continuous) { SplineUtility.CalculateTangents(position, positionPrev, positionNext, forward, scale, out rightTangent, out leftTangent); } SetLeftTangent(pointIndex, leftTangent); SetRightTangent(pointIndex, rightTangent); }
public void SetTangentModeUseThisOne(int pointIndex, TangentMode mode) { SetTangentMode(pointIndex, mode); if (SplineEditorCache.IsValid() && SplineEditorCache.GetTarget() != null) { if (mode == TangentMode.Continuous) { SetLeftTangent(pointIndex, SplineEditorCache.instance.GetLeftTangentContinous(pointIndex)); SetRightTangent(pointIndex, SplineEditorCache.instance.GetRightTangentContinous(pointIndex)); } if (mode == TangentMode.Broken) { SetLeftTangent(pointIndex, SplineEditorCache.instance.GetLeftTangentBroken(pointIndex)); SetRightTangent(pointIndex, SplineEditorCache.instance.GetRightTangentBroken(pointIndex)); } } if (mode == TangentMode.Continuous || mode == TangentMode.Broken) { if (GetLeftTangent(pointIndex).sqrMagnitude == 0f && GetRightTangent(pointIndex).sqrMagnitude == 0f) { ResetTangents(pointIndex); } } SetDirty(); }
public void CycleSpriteIndex() { var selection = SplineEditorCache.GetSelection(); var spriteShape = SplineEditorCache.GetTarget().spriteShape; if (selection.single == -1 || spriteShape == null) { return; } Debug.Assert(SplineEditorCache.GetTarget() != null); var angleRangeIndex = GetAngleRange(selection.single); if (angleRangeIndex != -1) { var angleRange = spriteShape.angleRanges[angleRangeIndex]; var spriteIndex = 0; if (angleRange.sprites.Count > 0) { spriteIndex = (GetSpriteIndex(selection.single) + 1) % angleRange.sprites.Count; } RegisterUndo(); SetSpriteIndex(selection.single, spriteIndex); SetDirty(); } }
private int ResolveSpriteIndex(List <int> spriteIndices, ISelection selection, ref List <int> startPoints) { var spriteIndexValue = spriteIndices.FirstOrDefault(); SpriteShapeController sc = SplineEditorCache.GetTarget(); if (sc == null || sc.spriteShape == null) { return(-1); } // Either SpriteShape Asset or SpriteShape Data has changed. List <ShapeAngleRange> angleRanges = GetAngleRangeSorted(sc.spriteShape); if (m_SpriteShapeHashCode != sc.spriteShapeHashCode) { GenerateSegments(sc, angleRanges); m_SpriteShapeHashCode = sc.spriteShapeHashCode; m_SelectedPoint = -1; } if (sc.spriteShape != null) { if (selection.single != -1) { m_SelectedAngleRange = GetAngleRange(sc, selection.single, ref m_SelectedPoint); startPoints.Add(m_SelectedPoint); spriteIndexValue = m_Spline.GetSpriteIndex(m_SelectedPoint); } else { m_SelectedAngleRange = -1; foreach (var index in selection) { int startPoint = index; int angleRange = GetAngleRange(sc, index, ref startPoint); if (m_SelectedAngleRange != -1 && angleRange != m_SelectedAngleRange) { m_SelectedAngleRange = -1; break; } startPoints.Add(startPoint); m_SelectedAngleRange = angleRange; } } } if (m_SelectedAngleRange != -1) { spriteSelector.UpdateSprites(sc.spriteShape.angleRanges[m_SelectedAngleRange].sprites.ToArray()); } else { spriteIndexValue = -1; } return(spriteIndexValue); }
private int GetAngleRangeLocal(int index) { var selection = SplineEditorCache.GetSelection(); var spriteShape = SplineEditorCache.GetTarget().spriteShape; var nextIndex = SplineUtility.NextIndex(selection.single, GetPointCount()); var pos1 = GetLocalPosition(selection.single); var pos2 = GetLocalPosition(nextIndex); var angle = SplineUtility.SlopeAngle(pos1, pos2) + 90; var angleRangeIndex = SpriteShapeEditorUtility.GetRangeIndexFromAngle(spriteShape, angle); return(angleRangeIndex); }
private void SelectionChanged() { if (target == null) { return; } if (target != SplineEditorCache.GetTarget()) { SplineEditorCache.RigisterUndo(); } InvalidateShapeEditor(); }
private bool InitializeCheck() { if (target != SplineEditorCache.GetTarget()) { InvalidateShapeEditor(); SplineEditorCache.ClearSelection(); SplineEditorCache.SetTarget(target); } if (target != null && m_SplineEditor == null) { SetupSpriteShapeEditor(target.spline); } return(target != null); }
public void MirrorTangent() { if (SpriteShapeTool.instance.isActive && SplineEditorCache.IsValid() && SplineEditorCache.GetTarget() != null) { var selection = SplineEditorCache.GetSelection(); if (selection.Count != 1) { return; } var mode = GetTangentMode(selection.single); if (mode == TangentMode.Linear) { return; } var leftTangent = GetLeftTangent(selection.single); var rightTangent = GetRightTangent(selection.single); if (!Mathf.Approximately((leftTangent + rightTangent).sqrMagnitude, 0f)) { if (GUIUtility.hotControl == 0) { Undo.RegisterCompleteObjectUndo(SplineEditorCache.GetTarget(), "Mirror Tangents"); } if (SplineEditorCache.instance.rightTangentChanged) { SetLeftTangent(selection.single, rightTangent * -1); } else { SetRightTangent(selection.single, leftTangent * -1); } UpdateTangentCache(); } } }
private void SetDirty() { Debug.Assert(SpriteShapeTool.instance.isActive); EditorUtility.SetDirty(SplineEditorCache.GetTarget()); }
private void RegisterUndo(string name) { Debug.Assert(SpriteShapeTool.instance.isActive); Undo.RegisterCompleteObjectUndo(SplineEditorCache.GetTarget(), name); }
private void RegisterUndo() { Undo.RegisterCompleteObjectUndo(SplineEditorCache.GetTarget(), "Edit Sprite Shape"); }