增加皮肤属性

This commit is contained in:
ww-rm
2025-03-26 15:20:59 +08:00
parent 81b1333091
commit 0597852178
9 changed files with 180 additions and 17 deletions

View File

@@ -75,13 +75,19 @@ namespace SpineViewer.Spine.Implementations.Spine
}
}
foreach (var skin in skeletonData.Skins)
skinNames.Add(skin.Name);
animationStateData = new AnimationStateData(skeletonData);
skeleton = new Skeleton(skeletonData);
animationState = new AnimationState(animationStateData);
foreach (var anime in skeletonData.Animations)
animationNames.Add(anime.Name);
CurrentAnimation = DefaultAnimationName;
// 取最后一个作为初始, 尽可能去显示非默认的内容
CurrentAnimation = animationNames.Last();
CurrentSkin = skinNames.Last();
}
protected override void Dispose(bool disposing)
@@ -185,6 +191,18 @@ namespace SpineViewer.Spine.Implementations.Spine
}
}
public override string CurrentSkin
{
get => skeleton.Skin.Name;
set
{
if (!skinNames.Contains(value))
return;
skeleton.SetSkin(value);
Update(0);
}
}
public override RectangleF Bounds
{
get

View File

@@ -74,13 +74,19 @@ namespace SpineViewer.Spine.Implementations.Spine
}
}
foreach (var skin in skeletonData.Skins)
skinNames.Add(skin.Name);
animationStateData = new AnimationStateData(skeletonData);
skeleton = new Skeleton(skeletonData);
animationState = new AnimationState(animationStateData);
foreach (var anime in skeletonData.Animations)
animationNames.Add(anime.Name);
CurrentAnimation = DefaultAnimationName;
// 取最后一个作为初始, 尽可能去显示非默认的内容
CurrentAnimation = animationNames.Last();
CurrentSkin = skinNames.Last();
}
protected override void Dispose(bool disposing)
@@ -183,6 +189,18 @@ namespace SpineViewer.Spine.Implementations.Spine
}
}
public override string CurrentSkin
{
get => skeleton.Skin.Name;
set
{
if (!skinNames.Contains(value))
return;
skeleton.SetSkin(value);
Update(0);
}
}
public override RectangleF Bounds
{
get

View File

@@ -72,6 +72,9 @@ namespace SpineViewer.Spine.Implementations.Spine
}
}
foreach (var skin in skeletonData.Skins)
skinNames.Add(skin.Name);
animationStateData = new AnimationStateData(skeletonData);
skeleton = new Skeleton(skeletonData);
animationState = new AnimationState(animationStateData);
@@ -79,7 +82,9 @@ namespace SpineViewer.Spine.Implementations.Spine
foreach (var anime in skeletonData.Animations)
animationNames.Add(anime.Name);
CurrentAnimation = DefaultAnimationName;
// 取最后一个作为初始, 尽可能去显示非默认的内容
CurrentAnimation = animationNames.Last();
CurrentSkin = skinNames.Last();
}
protected override void Dispose(bool disposing)
@@ -190,6 +195,18 @@ namespace SpineViewer.Spine.Implementations.Spine
}
}
public override string CurrentSkin
{
get => skeleton.Skin.Name;
set
{
if (!skinNames.Contains(value))
return;
skeleton.SetSkin(value);
Update(0);
}
}
public override RectangleF Bounds
{
get

View File

@@ -75,6 +75,9 @@ namespace SpineViewer.Spine.Implementations.Spine
}
}
foreach (var skin in skeletonData.Skins)
skinNames.Add(skin.Name);
animationStateData = new AnimationStateData(skeletonData);
skeleton = new Skeleton(skeletonData);
animationState = new AnimationState(animationStateData);
@@ -82,7 +85,9 @@ namespace SpineViewer.Spine.Implementations.Spine
foreach (var anime in skeletonData.Animations)
animationNames.Add(anime.Name);
CurrentAnimation = DefaultAnimationName;
// 取最后一个作为初始, 尽可能去显示非默认的内容
CurrentAnimation = animationNames.Last();
CurrentSkin = skinNames.Last();
}
protected override void Dispose(bool disposing)
@@ -193,6 +198,18 @@ namespace SpineViewer.Spine.Implementations.Spine
}
}
public override string CurrentSkin
{
get => skeleton.Skin.Name;
set
{
if (!skinNames.Contains(value))
return;
skeleton.SetSkin(value);
Update(0);
}
}
public override RectangleF Bounds
{
get

View File

@@ -74,6 +74,9 @@ namespace SpineViewer.Spine.Implementations.Spine
}
}
foreach (var skin in skeletonData.Skins)
skinNames.Add(skin.Name);
animationStateData = new AnimationStateData(skeletonData);
skeleton = new Skeleton(skeletonData);
animationState = new AnimationState(animationStateData);
@@ -81,7 +84,9 @@ namespace SpineViewer.Spine.Implementations.Spine
foreach (var anime in skeletonData.Animations)
animationNames.Add(anime.Name);
CurrentAnimation = DefaultAnimationName;
// 取最后一个作为初始, 尽可能去显示非默认的内容
CurrentAnimation = animationNames.Last();
CurrentSkin = skinNames.Last();
}
protected override void Dispose(bool disposing)
@@ -192,6 +197,18 @@ namespace SpineViewer.Spine.Implementations.Spine
}
}
public override string CurrentSkin
{
get => skeleton.Skin.Name;
set
{
if (!skinNames.Contains(value))
return;
skeleton.SetSkin(value);
Update(0);
}
}
public override RectangleF Bounds
{
get

View File

@@ -74,6 +74,9 @@ namespace SpineViewer.Spine.Implementations.Spine
}
}
foreach (var skin in skeletonData.Skins)
skinNames.Add(skin.Name);
animationStateData = new AnimationStateData(skeletonData);
skeleton = new Skeleton(skeletonData);
animationState = new AnimationState(animationStateData);
@@ -81,7 +84,9 @@ namespace SpineViewer.Spine.Implementations.Spine
foreach (var anime in skeletonData.Animations)
animationNames.Add(anime.Name);
CurrentAnimation = DefaultAnimationName;
// 取最后一个作为初始, 尽可能去显示非默认的内容
CurrentAnimation = animationNames.Last();
CurrentSkin = skinNames.Last();
}
protected override void Dispose(bool disposing)
@@ -192,6 +197,18 @@ namespace SpineViewer.Spine.Implementations.Spine
}
}
public override string CurrentSkin
{
get => skeleton.Skin.Name;
set
{
if (!skinNames.Contains(value))
return;
skeleton.SetSkin(value);
Update(0);
}
}
public override RectangleF Bounds
{
get

View File

@@ -74,6 +74,9 @@ namespace SpineViewer.Spine.Implementations.Spine
}
}
foreach (var skin in skeletonData.Skins)
skinNames.Add(skin.Name);
animationStateData = new AnimationStateData(skeletonData);
skeleton = new Skeleton(skeletonData);
animationState = new AnimationState(animationStateData);
@@ -81,7 +84,9 @@ namespace SpineViewer.Spine.Implementations.Spine
foreach (var anime in skeletonData.Animations)
animationNames.Add(anime.Name);
CurrentAnimation = DefaultAnimationName;
// 取最后一个作为初始, 尽可能去显示非默认的内容
CurrentAnimation = animationNames.Last();
CurrentSkin = skinNames.Last();
}
protected override void Dispose(bool disposing)
@@ -192,6 +197,18 @@ namespace SpineViewer.Spine.Implementations.Spine
}
}
public override string CurrentSkin
{
get => skeleton.Skin.Name;
set
{
if (!skinNames.Contains(value))
return;
skeleton.SetSkin(value);
Update(0);
}
}
public override RectangleF Bounds
{
get

View File

@@ -287,16 +287,18 @@ namespace SpineViewer.Spine
#endregion
#region |
#region |
/// <summary>
/// 是否使用预乘Alpha
/// </summary>
[Category("画面"), DisplayName("预乘Alpha通道")]
[Category("渲染"), DisplayName("预乘Alpha通道")]
public bool UsePremultipliedAlpha { get; set; } = true;
#endregion
#region |
/// <summary>
/// 包含的所有动画名称
/// </summary>
@@ -304,14 +306,6 @@ namespace SpineViewer.Spine
public ReadOnlyCollection<string> AnimationNames { get => animationNames.AsReadOnly(); }
protected List<string> animationNames = [EMPTY_ANIMATION];
/// <summary>
/// 默认动画名称
/// </summary>
[Browsable(false)]
public string DefaultAnimationName { get => animationNames.Last(); }
#region |
/// <summary>
/// 当前动画名称, 如果设置的动画不存在则忽略
/// </summary>
@@ -325,6 +319,20 @@ namespace SpineViewer.Spine
[Category("动画"), DisplayName("当前动画时长")]
public float CurrentAnimationDuration { get => GetAnimationDuration(CurrentAnimation); }
/// <summary>
/// 包含的所有皮肤名称
/// </summary>
[Browsable(false)]
public ReadOnlyCollection<string> SkinNames { get => skinNames.AsReadOnly(); }
protected List<string> skinNames = [];
/// <summary>
/// 当前皮肤名称, 如果设置的皮肤不存在则忽略
/// </summary>
[TypeConverter(typeof(SkinConverter))]
[Category("动画"), DisplayName("当前皮肤")]
public abstract string CurrentSkin { get; set; }
#endregion
/// <summary>

View File

@@ -58,4 +58,38 @@ namespace SpineViewer.Spine
return base.GetStandardValues(context);
}
}
public class SkinConverter : StringConverter
{
public override bool GetStandardValuesSupported(ITypeDescriptorContext? context)
{
// 支持标准值列表
return true;
}
public override bool GetStandardValuesExclusive(ITypeDescriptorContext? context)
{
// 排他模式,只有下拉列表中的值可选
return true;
}
public override StandardValuesCollection? GetStandardValues(ITypeDescriptorContext? context)
{
if (context?.Instance is Spine obj)
{
return new StandardValuesCollection(obj.SkinNames);
}
else if (context?.Instance is Spine[] spines)
{
if (spines.Length > 0)
{
IEnumerable<string> common = spines[0].SkinNames;
foreach (var spine in spines.Skip(1))
common = common.Intersect(spine.SkinNames);
return new StandardValuesCollection(common.ToArray());
}
}
return base.GetStandardValues(context);
}
}
}