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 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); } } }
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; } }
public override string ToString() { return($"{time: 0.000}: {value:0.000} ({CurveTypeValues.FromInt(curveType)}, {controlPointIn:0.0}/{controlPointOut:0.0})"); }