diff --git a/SpineViewer/Models/SpineObjectConfigModel.cs b/SpineViewer/Models/SpineObjectConfigModel.cs index 58dc5fd..6f2c532 100644 --- a/SpineViewer/Models/SpineObjectConfigModel.cs +++ b/SpineViewer/Models/SpineObjectConfigModel.cs @@ -35,7 +35,7 @@ namespace SpineViewer.Models public List DisabledSlots { get; set; } = []; - public List Animations { get; set; } = []; + public List Animations { get; set; } = []; public bool DebugTexture { get; set; } = true; @@ -59,12 +59,12 @@ namespace SpineViewer.Models } - public class AnimationConfigModel + public class TrackConfigModel { - string Name { get; set; } = ""; + public string AnimationName { get; set; } = ""; - float TimeScale { get; set; } = 1f; + public float TimeScale { get; set; } = 1f; - float Alpha { get; set; } = 1f; + public float Alpha { get; set; } = 1f; } } diff --git a/SpineViewer/Models/SpineObjectModel.cs b/SpineViewer/Models/SpineObjectModel.cs index 49b6acc..58b232a 100644 --- a/SpineViewer/Models/SpineObjectModel.cs +++ b/SpineViewer/Models/SpineObjectModel.cs @@ -459,7 +459,22 @@ namespace SpineViewer.Models config.DisabledSlots = _spineObject.Skeleton.Slots.Where(it => it.Disabled).Select(it => it.Name).ToList(); // XXX: 处理空动画 - config.Animations.AddRange(_spineObject.AnimationState.IterTracks().Select(tr => tr?.Animation.Name)); + foreach (var tr in _spineObject.AnimationState.IterTracks()) + { + if (tr is not null) + { + config.Animations.Add(new() + { + AnimationName = tr.Animation.Name, + TimeScale = tr.TimeScale, + Alpha = tr.Alpha + }); + } + else + { + config.Animations.Add(null); + } + } return config; } @@ -498,11 +513,15 @@ namespace SpineViewer.Models // XXX: 处理空动画 _spineObject.AnimationState.ClearTracks(); int trackIndex = 0; - foreach (var name in value.Animations) + foreach (var trConfig in value.Animations) { - if (!string.IsNullOrEmpty(name)) - _spineObject.AnimationState.SetAnimation(trackIndex, name, true); - TrackPropertyChanged?.Invoke(this, new(trackIndex, nameof(TrackPropertyChangedEventArgs.AnimationName))); + if (trConfig is not null && !string.IsNullOrEmpty(trConfig.AnimationName)) + { + var tr = _spineObject.AnimationState.SetAnimation(trackIndex, trConfig.AnimationName, true); + tr.TimeScale = trConfig.TimeScale; + tr.Alpha = trConfig.Alpha; + TrackPropertyChanged?.Invoke(this, new(trackIndex, nameof(TrackPropertyChangedEventArgs.AnimationName))); + } trackIndex++; }