Esempio n. 1
0
        public void ChangeCurve(string val)
        {
            if (string.IsNullOrEmpty(val))
            {
                return;
            }
            _changeCurveJSON.valNoCallback = "";

            foreach (var target in animationEditContext.GetAllOrSelectedTargets().OfType <ICurveAnimationTarget>())
            {
                target.StartBulkUpdates();
                try
                {
                    var leadCurve = target.GetLeadCurve();
                    for (var key = 0; key < leadCurve.length; key++)
                    {
                        var keyTime = leadCurve.GetKeyframeByKey(key).time;
                        if (keyTime >= _startJSON.valNoCallback && keyTime <= _endJSON.valNoCallback)
                        {
                            target.ChangeCurve(keyTime, CurveTypeValues.ToInt(val));
                        }
                    }
                }
                finally
                {
                    target.EndBulkUpdates();
                }
            }
        }
Esempio n. 2
0
        private void ChangeCurve(string val)
        {
            if (!_animationEditContext.CanEdit())
            {
                RefreshCurrentCurveType(_animationEditContext.clipTime);
                return;
            }

            if (string.IsNullOrEmpty(val) || val.StartsWith("("))
            {
                RefreshCurrentCurveType(_animationEditContext.clipTime);
                return;
            }
            var time = _animationEditContext.clipTime.Snap();

            var curveType = CurveTypeValues.ToInt(val);

            foreach (var target in _animationEditContext.GetAllOrSelectedTargets().OfType <ICurveAnimationTarget>())
            {
                target.ChangeCurve(time, curveType);
            }

            if (curveType == CurveTypeValues.CopyPrevious)
            {
                _animationEditContext.Sample();
            }

            RefreshCurrentCurveType(_animationEditContext.clipTime);
        }
        private void DeserializeCurveFromStringLegacy(AnimationCurve curve, JSONNode curveJSON, SortedDictionary <int, KeyframeSettings> keyframeSettings = null)
        {
            var strFrames = curveJSON.Value.Split(';').Where(x => x != "").ToList();

            if (strFrames.Count == 0)
            {
                return;
            }

            var last = -1f;

            foreach (var keyframe in strFrames)
            {
                var parts = keyframe.Split(',');
                try
                {
                    var time = float.Parse(parts[0], CultureInfo.InvariantCulture).Snap();
                    if (time == last)
                    {
                        continue;
                    }
                    last = time;
                    var value = DeserializeFloat(parts[1]);
                    curve.AddKey(new Keyframe
                    {
                        time       = time,
                        value      = value,
                        inTangent  = DeserializeFloat(parts[3]),
                        outTangent = DeserializeFloat(parts[4])
                    });
                    if (keyframeSettings != null)
                    {
                        keyframeSettings.Add(time.ToMilliseconds(), new KeyframeSettings {
                            curveType = CurveTypeValues.FromInt(int.Parse(parts[2]))
                        });
                    }
                }
                catch (IndexOutOfRangeException exc)
                {
                    throw new InvalidOperationException($"Failed to read curve: {keyframe}", exc);
                }
            }
        }
        private JSONNode SerializeCurve(AnimationCurve curve, SortedDictionary <int, KeyframeSettings> settings = null)
        {
            var curveJSON = new JSONArray();

            for (var key = 0; key < curve.length; key++)
            {
                var keyframe   = curve[key];
                var ms         = keyframe.time.ToMilliseconds();
                var curveEntry = new JSONClass
                {
                    ["t"]  = keyframe.time.ToString(CultureInfo.InvariantCulture),
                    ["v"]  = keyframe.value.ToString(CultureInfo.InvariantCulture),
                    ["c"]  = settings == null ? "0" : (settings.ContainsKey(ms) ? CurveTypeValues.ToInt(settings[ms].curveType).ToString() : "0"),
                    ["ti"] = keyframe.inTangent.ToString(CultureInfo.InvariantCulture),
                    ["to"] = keyframe.outTangent.ToString(CultureInfo.InvariantCulture)
                };
                curveJSON.Add(curveEntry);
            }

            return(curveJSON);
        }
        private void DeserializeCurveFromArray(AnimationCurve curve, JSONArray curveJSON, SortedDictionary <int, KeyframeSettings> keyframeSettings = null)
        {
            if (curveJSON.Count == 0)
            {
                return;
            }

            var last = -1f;

            foreach (JSONClass keyframeJSON in curveJSON)
            {
                try
                {
                    var time = float.Parse(keyframeJSON["t"], CultureInfo.InvariantCulture).Snap();
                    if (time == last)
                    {
                        continue;
                    }
                    last = time;
                    var value = DeserializeFloat(keyframeJSON["v"]);
                    curve.AddKey(new Keyframe
                    {
                        time       = time,
                        value      = value,
                        inTangent  = DeserializeFloat(keyframeJSON["ti"]),
                        outTangent = DeserializeFloat(keyframeJSON["to"])
                    });
                    if (keyframeSettings != null)
                    {
                        keyframeSettings.Add(time.ToMilliseconds(), new KeyframeSettings {
                            curveType = CurveTypeValues.FromInt(int.Parse(keyframeJSON["c"]))
                        });
                    }
                }
                catch (IndexOutOfRangeException exc)
                {
                    throw new InvalidOperationException($"Failed to read curve: {keyframeJSON}", exc);
                }
            }
        }
Esempio n. 6
0
        private void RefreshCurrentCurveType(float currentClipTime)
        {
            if (curveTypeJSON == null)
            {
                return;
            }

            var time = currentClipTime.Snap();

            _curveTypes.Clear();
            foreach (var target in _animationEditContext.GetAllOrSelectedTargets().OfType <ICurveAnimationTarget>())
            {
                var curveType = target.GetKeyframeCurveType(time);
                if (curveType == BezierKeyframe.NullKeyframeCurveType)
                {
                    continue;
                }
                _curveTypes.Add(CurveTypeValues.FromInt(curveType));
            }

            switch (_curveTypes.Count)
            {
            case 0:
                curveTypeJSON.valNoCallback = _noKeyframeCurveType;
                curveTypeUI.popup.topButton.interactable = false;
                break;

            case 1:
                curveTypeJSON.valNoCallback = _curveTypes.First();
                curveTypeUI.popup.topButton.interactable = true;
                break;

            default:
                curveTypeJSON.valNoCallback = "(" + string.Join("/", _curveTypes.ToArray()) + ")";
                curveTypeUI.popup.topButton.interactable = true;
                break;
            }
        }
Esempio n. 7
0
 public override string ToString()
 {
     return($"{time: 0.000}: {value:0.000} ({CurveTypeValues.FromInt(curveType)}, {controlPointIn:0.0}/{controlPointOut:0.0})");
 }