From 16739c39d6be0b3abc76984ca1e4a212af6804da Mon Sep 17 00:00:00 2001 From: ww-rm Date: Sat, 19 Apr 2025 00:41:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=B0=8Fbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Spine/SpineView/SpineAnimationProperty.cs | 5 ++--- .../Spine/SpineView/SpineSkinProperty.cs | 10 ++++----- .../Spine/SpineView/SpineSlotProperty.cs | 21 ++++++++----------- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/SpineViewer/Spine/SpineView/SpineAnimationProperty.cs b/SpineViewer/Spine/SpineView/SpineAnimationProperty.cs index 1436e26..2891e55 100644 --- a/SpineViewer/Spine/SpineView/SpineAnimationProperty.cs +++ b/SpineViewer/Spine/SpineView/SpineAnimationProperty.cs @@ -186,10 +186,9 @@ namespace SpineViewer.Spine.SpineView { return new StandardValuesCollection(tracks.Spine.AnimationNames); } - else if (context?.Instance is object[] instances && instances.All(x => x is SpineAnimationProperty)) + else if (context?.Instance is SpineAnimationProperty[] animTracks) { - // XXX: 这里不知道为啥总是会得到 object[] 类型而不是具体的类型 - var animTracks = instances.Cast().ToArray(); + // XXX: 莫名其妙好了, 不是 object[] 类型是具体的类型了 if (animTracks.Length > 0) { IEnumerable common = animTracks[0].Spine.AnimationNames; diff --git a/SpineViewer/Spine/SpineView/SpineSkinProperty.cs b/SpineViewer/Spine/SpineView/SpineSkinProperty.cs index 7d30dfb..93c3f60 100644 --- a/SpineViewer/Spine/SpineView/SpineSkinProperty.cs +++ b/SpineViewer/Spine/SpineView/SpineSkinProperty.cs @@ -61,12 +61,10 @@ namespace SpineViewer.Spine.SpineView } /// - /// 皮肤属性描述符, 实现对皮肤的加载和卸载, .Skin_{name} + /// 皮肤属性描述符, 实现对皮肤的加载和卸载, .{name} /// - private class SkinPropertyDescriptor(string name, Attribute[]? attributes) : PropertyDescriptor($"Skin_{name}", attributes) + private class SkinPropertyDescriptor(string name, Attribute[]? attributes) : PropertyDescriptor(name, attributes) { - private readonly string name = name; - public override Type ComponentType => typeof(SpineSkinProperty); public override bool IsReadOnly => false; public override Type PropertyType => typeof(bool); @@ -77,7 +75,7 @@ namespace SpineViewer.Spine.SpineView public override object? GetValue(object? component) { if (component is SpineSkinProperty prop) - return prop.Spine.GetSkinStatus(name); + return prop.Spine.GetSkinStatus(Name); return null; } @@ -86,7 +84,7 @@ namespace SpineViewer.Spine.SpineView if (component is SpineSkinProperty prop) { if (value is bool s) - prop.Spine.SetSkinStatus(name, s); + prop.Spine.SetSkinStatus(Name, s); } } } diff --git a/SpineViewer/Spine/SpineView/SpineSlotProperty.cs b/SpineViewer/Spine/SpineView/SpineSlotProperty.cs index 5e4f29a..8cd79bb 100644 --- a/SpineViewer/Spine/SpineView/SpineSlotProperty.cs +++ b/SpineViewer/Spine/SpineView/SpineSlotProperty.cs @@ -65,10 +65,8 @@ namespace SpineViewer.Spine.SpineView /// /// 槽位属性描述符, 实现对属性的读取和赋值 /// - internal class SlotPropertyDescriptor(string name, Attribute[]? attributes) : PropertyDescriptor($"Slot_{name}", attributes) + internal class SlotPropertyDescriptor(string name, Attribute[]? attributes) : PropertyDescriptor(name, attributes) { - public string SlotName { get; } = name; - public override Type ComponentType => typeof(SpineSlotProperty); public override bool IsReadOnly => false; public override Type PropertyType => typeof(SlotProperty); @@ -82,7 +80,7 @@ namespace SpineViewer.Spine.SpineView public override object? GetValue(object? component) { if (component is SpineSlotProperty slots) - return slots.Spine.GetSlotAttachment(SlotName); + return slots.Spine.GetSlotAttachment(Name); return null; } @@ -94,7 +92,7 @@ namespace SpineViewer.Spine.SpineView if (component is SpineSlotProperty slots) { if (value is string s) - slots.Spine.SetSlotAttachment(SlotName, s); + slots.Spine.SetSlotAttachment(Name, s); } } } @@ -103,7 +101,7 @@ namespace SpineViewer.Spine.SpineView } /// - /// 对 .Slot_{name} 属性的包装类 + /// 对 .{name} 属性的包装类 /// [TypeConverter(typeof(SlotPropertyConverter))] public class SlotProperty(SpineObject spine, string name) @@ -148,23 +146,22 @@ namespace SpineViewer.Spine.SpineView public override StandardValuesCollection? GetStandardValues(ITypeDescriptorContext? context) { - if (context?.PropertyDescriptor is SpineSlotProperty.SlotPropertyDescriptor pd) + if (context?.PropertyDescriptor is PropertyDescriptor pd) { if (context?.Instance is SpineSlotProperty slots) { - if (slots.Spine.SlotAttachmentNames.TryGetValue(pd.SlotName, out var names)) + if (slots.Spine.SlotAttachmentNames.TryGetValue(pd.Name, out var names)) return new StandardValuesCollection(names); } - else if (context?.Instance is object[] instances && instances.All(x => x is SpineSlotProperty)) + else if (context?.Instance is SpineSlotProperty[] spinesSlots) { - // XXX: 这里不知道为啥总是会得到 object[] 类型而不是具体的类型 - var spinesSlots = instances.Cast().ToArray(); + // XXX: 莫名其妙好了, 不是 object[] 类型是具体的类型了 if (spinesSlots.Length > 0) { IEnumerable common = []; foreach (var t in spinesSlots) { - if (t.Spine.SlotAttachmentNames.TryGetValue(pd.SlotName, out var names)) + if (t.Spine.SlotAttachmentNames.TryGetValue(pd.Name, out var names)) common = common.Union(names); } return new StandardValuesCollection(common.ToArray());