コード例 #1
0
        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);
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        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();
                }
            }
        }