修改皮肤设置操作为布尔型
This commit is contained in:
@@ -153,7 +153,7 @@ namespace SpineViewer.Spine.Implementations.SpineObject
|
|||||||
position = pos;
|
position = pos;
|
||||||
flipX = fX;
|
flipX = fX;
|
||||||
flipY = fY;
|
flipY = fY;
|
||||||
foreach (var s in loadedSkins) addSkin(s);
|
reloadSkins();
|
||||||
for (int i = 0; i < animations.Length; i++) setAnimation(i, animations[i]);
|
for (int i = 0; i < animations.Length; i++) setAnimation(i, animations[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -191,7 +191,7 @@ namespace SpineViewer.Spine.Implementations.SpineObject
|
|||||||
skeleton.SetSlotsToSetupPose();
|
skeleton.SetSlotsToSetupPose();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void clearSkin()
|
protected override void clearSkins()
|
||||||
{
|
{
|
||||||
skeleton.Skin.Attachments.Clear();
|
skeleton.Skin.Attachments.Clear();
|
||||||
skeleton.SetSlotsToSetupPose();
|
skeleton.SetSlotsToSetupPose();
|
||||||
@@ -229,7 +229,7 @@ namespace SpineViewer.Spine.Implementations.SpineObject
|
|||||||
tmpSkeleton.FlipY = skeleton.FlipY;
|
tmpSkeleton.FlipY = skeleton.FlipY;
|
||||||
tmpSkeleton.X = skeleton.X;
|
tmpSkeleton.X = skeleton.X;
|
||||||
tmpSkeleton.Y = skeleton.Y;
|
tmpSkeleton.Y = skeleton.Y;
|
||||||
foreach (var name in loadedSkins)
|
foreach (var (name, _) in skinLoadStatus.Where(e => e.Value))
|
||||||
{
|
{
|
||||||
foreach (var (k, v) in skeletonData.FindSkin(name).Attachments)
|
foreach (var (k, v) in skeletonData.FindSkin(name).Attachments)
|
||||||
tmpSkeleton.Skin.AddAttachment(k.Key, k.Value, v);
|
tmpSkeleton.Skin.AddAttachment(k.Key, k.Value, v);
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ namespace SpineViewer.Spine.Implementations.SpineObject
|
|||||||
position = pos;
|
position = pos;
|
||||||
flipX = fX;
|
flipX = fX;
|
||||||
flipY = fY;
|
flipY = fY;
|
||||||
foreach (var s in loadedSkins) addSkin(s);
|
reloadSkins();
|
||||||
for (int i = 0; i < animations.Length; i++) setAnimation(i, animations[i]);
|
for (int i = 0; i < animations.Length; i++) setAnimation(i, animations[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -190,7 +190,7 @@ namespace SpineViewer.Spine.Implementations.SpineObject
|
|||||||
skeleton.SetSlotsToSetupPose();
|
skeleton.SetSlotsToSetupPose();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void clearSkin()
|
protected override void clearSkins()
|
||||||
{
|
{
|
||||||
skeleton.Skin.Attachments.Clear();
|
skeleton.Skin.Attachments.Clear();
|
||||||
skeleton.SetSlotsToSetupPose();
|
skeleton.SetSlotsToSetupPose();
|
||||||
@@ -229,7 +229,7 @@ namespace SpineViewer.Spine.Implementations.SpineObject
|
|||||||
tmpSkeleton.FlipY = skeleton.FlipY;
|
tmpSkeleton.FlipY = skeleton.FlipY;
|
||||||
tmpSkeleton.X = skeleton.X;
|
tmpSkeleton.X = skeleton.X;
|
||||||
tmpSkeleton.Y = skeleton.Y;
|
tmpSkeleton.Y = skeleton.Y;
|
||||||
foreach (var name in loadedSkins)
|
foreach (var (name, _) in skinLoadStatus.Where(e => e.Value))
|
||||||
{
|
{
|
||||||
foreach (var (k, v) in skeletonData.FindSkin(name).Attachments)
|
foreach (var (k, v) in skeletonData.FindSkin(name).Attachments)
|
||||||
tmpSkeleton.Skin.AddAttachment(k.slotIndex, k.name, v);
|
tmpSkeleton.Skin.AddAttachment(k.slotIndex, k.name, v);
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ namespace SpineViewer.Spine.Implementations.SpineObject
|
|||||||
skeleton.SetSlotsToSetupPose();
|
skeleton.SetSlotsToSetupPose();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void clearSkin()
|
protected override void clearSkins()
|
||||||
{
|
{
|
||||||
skeleton.Skin.Attachments.Clear();
|
skeleton.Skin.Attachments.Clear();
|
||||||
skeleton.SetSlotsToSetupPose();
|
skeleton.SetSlotsToSetupPose();
|
||||||
@@ -200,7 +200,7 @@ namespace SpineViewer.Spine.Implementations.SpineObject
|
|||||||
tmpSkeleton.ScaleY = skeleton.ScaleY;
|
tmpSkeleton.ScaleY = skeleton.ScaleY;
|
||||||
tmpSkeleton.X = skeleton.X;
|
tmpSkeleton.X = skeleton.X;
|
||||||
tmpSkeleton.Y = skeleton.Y;
|
tmpSkeleton.Y = skeleton.Y;
|
||||||
foreach (var name in loadedSkins)
|
foreach (var (name, _) in skinLoadStatus.Where(e => e.Value))
|
||||||
{
|
{
|
||||||
foreach (var (k, v) in skeletonData.FindSkin(name).Attachments)
|
foreach (var (k, v) in skeletonData.FindSkin(name).Attachments)
|
||||||
tmpSkeleton.Skin.AddAttachment(k.slotIndex, k.name, v);
|
tmpSkeleton.Skin.AddAttachment(k.slotIndex, k.name, v);
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ namespace SpineViewer.Spine.Implementations.SpineObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void clearSkin()
|
protected override void clearSkins()
|
||||||
{
|
{
|
||||||
skeleton.Skin.Clear();
|
skeleton.Skin.Clear();
|
||||||
skeleton.SetSlotsToSetupPose();
|
skeleton.SetSlotsToSetupPose();
|
||||||
@@ -205,7 +205,7 @@ namespace SpineViewer.Spine.Implementations.SpineObject
|
|||||||
tmpSkeleton.ScaleY = skeleton.ScaleY;
|
tmpSkeleton.ScaleY = skeleton.ScaleY;
|
||||||
tmpSkeleton.X = skeleton.X;
|
tmpSkeleton.X = skeleton.X;
|
||||||
tmpSkeleton.Y = skeleton.Y;
|
tmpSkeleton.Y = skeleton.Y;
|
||||||
foreach (var sk in loadedSkins) tmpSkeleton.Skin.AddSkin(skeletonData.FindSkin(sk));
|
foreach (var (sk, _) in skinLoadStatus.Where(e => e.Value)) tmpSkeleton.Skin.AddSkin(skeletonData.FindSkin(sk));
|
||||||
foreach (var tr in animationState.Tracks.Select((_, i) => i).Where(i => animationState.Tracks.Items[i] is not null))
|
foreach (var tr in animationState.Tracks.Select((_, i) => i).Where(i => animationState.Tracks.Items[i] is not null))
|
||||||
{
|
{
|
||||||
var ani = animationState.GetCurrent(tr).Animation;
|
var ani = animationState.GetCurrent(tr).Animation;
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ namespace SpineViewer.Spine.Implementations.SpineObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void clearSkin()
|
protected override void clearSkins()
|
||||||
{
|
{
|
||||||
skeleton.Skin.Clear();
|
skeleton.Skin.Clear();
|
||||||
skeleton.SetSlotsToSetupPose();
|
skeleton.SetSlotsToSetupPose();
|
||||||
@@ -200,7 +200,7 @@ namespace SpineViewer.Spine.Implementations.SpineObject
|
|||||||
tmpSkeleton.ScaleY = skeleton.ScaleY;
|
tmpSkeleton.ScaleY = skeleton.ScaleY;
|
||||||
tmpSkeleton.X = skeleton.X;
|
tmpSkeleton.X = skeleton.X;
|
||||||
tmpSkeleton.Y = skeleton.Y;
|
tmpSkeleton.Y = skeleton.Y;
|
||||||
foreach (var sk in loadedSkins) tmpSkeleton.Skin.AddSkin(skeletonData.FindSkin(sk));
|
foreach (var (sk, _) in skinLoadStatus.Where(e => e.Value)) tmpSkeleton.Skin.AddSkin(skeletonData.FindSkin(sk));
|
||||||
foreach (var tr in animationState.Tracks.Select((_, i) => i).Where(i => animationState.Tracks.Items[i] is not null))
|
foreach (var tr in animationState.Tracks.Select((_, i) => i).Where(i => animationState.Tracks.Items[i] is not null))
|
||||||
{
|
{
|
||||||
var ani = animationState.GetCurrent(tr).Animation;
|
var ani = animationState.GetCurrent(tr).Animation;
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ namespace SpineViewer.Spine.Implementations.SpineObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void clearSkin()
|
protected override void clearSkins()
|
||||||
{
|
{
|
||||||
skeleton.Skin.Clear();
|
skeleton.Skin.Clear();
|
||||||
skeleton.SetSlotsToSetupPose();
|
skeleton.SetSlotsToSetupPose();
|
||||||
@@ -200,7 +200,7 @@ namespace SpineViewer.Spine.Implementations.SpineObject
|
|||||||
tmpSkeleton.ScaleY = skeleton.ScaleY;
|
tmpSkeleton.ScaleY = skeleton.ScaleY;
|
||||||
tmpSkeleton.X = skeleton.X;
|
tmpSkeleton.X = skeleton.X;
|
||||||
tmpSkeleton.Y = skeleton.Y;
|
tmpSkeleton.Y = skeleton.Y;
|
||||||
foreach (var sk in loadedSkins) tmpSkeleton.Skin.AddSkin(skeletonData.FindSkin(sk));
|
foreach (var (sk, _) in skinLoadStatus.Where(e => e.Value)) tmpSkeleton.Skin.AddSkin(skeletonData.FindSkin(sk));
|
||||||
foreach (var tr in animationState.Tracks.Select((_, i) => i).Where(i => animationState.Tracks.Items[i] is not null))
|
foreach (var tr in animationState.Tracks.Select((_, i) => i).Where(i => animationState.Tracks.Items[i] is not null))
|
||||||
{
|
{
|
||||||
var ani = animationState.GetCurrent(tr).Animation;
|
var ani = animationState.GetCurrent(tr).Animation;
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ namespace SpineViewer.Spine.Implementations.SpineObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void clearSkin()
|
protected override void clearSkins()
|
||||||
{
|
{
|
||||||
skeleton.Skin.Clear();
|
skeleton.Skin.Clear();
|
||||||
skeleton.SetSlotsToSetupPose();
|
skeleton.SetSlotsToSetupPose();
|
||||||
@@ -200,7 +200,7 @@ namespace SpineViewer.Spine.Implementations.SpineObject
|
|||||||
tmpSkeleton.ScaleY = skeleton.ScaleY;
|
tmpSkeleton.ScaleY = skeleton.ScaleY;
|
||||||
tmpSkeleton.X = skeleton.X;
|
tmpSkeleton.X = skeleton.X;
|
||||||
tmpSkeleton.Y = skeleton.Y;
|
tmpSkeleton.Y = skeleton.Y;
|
||||||
foreach (var sk in loadedSkins) tmpSkeleton.Skin.AddSkin(skeletonData.FindSkin(sk));
|
foreach (var (sk, _) in skinLoadStatus.Where(e => e.Value)) tmpSkeleton.Skin.AddSkin(skeletonData.FindSkin(sk));
|
||||||
foreach (var tr in animationState.Tracks.Select((_, i) => i).Where(i => animationState.Tracks.Items[i] is not null))
|
foreach (var tr in animationState.Tracks.Select((_, i) => i).Where(i => animationState.Tracks.Items[i] is not null))
|
||||||
{
|
{
|
||||||
var ani = animationState.GetCurrent(tr).Animation;
|
var ani = animationState.GetCurrent(tr).Animation;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ using SpineViewer.Extensions;
|
|||||||
using SpineViewer.Utils;
|
using SpineViewer.Utils;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using System.Collections.Frozen;
|
using System.Collections.Frozen;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace SpineViewer.Spine
|
namespace SpineViewer.Spine
|
||||||
{
|
{
|
||||||
@@ -92,13 +93,11 @@ namespace SpineViewer.Spine
|
|||||||
tex.Display();
|
tex.Display();
|
||||||
Preview = tex.Texture.CopyToBitmap();
|
Preview = tex.Texture.CopyToBitmap();
|
||||||
|
|
||||||
// 默认初始化10个空位
|
// 初始化皮肤加载情况
|
||||||
for (int i = 0; i < 10; i++)
|
foreach (var n in SkinNames) skinLoadStatus[n] = false;
|
||||||
{
|
|
||||||
setAnimation(i, AnimationNames.First());
|
// 默认初始化10个动画空位
|
||||||
loadedSkins.Add(SkinNames.First());
|
for (int i = 0; i < 10; i++) setAnimation(i, AnimationNames.First());
|
||||||
}
|
|
||||||
reloadSkins();
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -341,70 +340,53 @@ namespace SpineViewer.Spine
|
|||||||
public ImmutableArray<string> AnimationNames { get; protected set; }
|
public ImmutableArray<string> AnimationNames { get; protected set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取已加载的皮肤列表快照, 允许出现重复值
|
/// 皮肤的加载情况记录表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string[] GetLoadedSkins() { lock (_lock) return loadedSkins.ToArray(); }
|
protected readonly Dictionary<string, bool> skinLoadStatus = [];
|
||||||
protected readonly List<string> loadedSkins = [];
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 加载指定皮肤, 添加至列表末尾, 如果不存在则忽略, 允许加载重复的值
|
/// 查询皮肤是否被加载, 皮肤不存在时返回 false
|
||||||
|
/// </summary>
|
||||||
|
public bool GetSkinStatus(string name) { lock (_lock) return skinLoadStatus.TryGetValue(name, out var status) && status; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 加载指定皮肤, 如果不存在则忽略, 允许重复加载
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void LoadSkin(string name)
|
public void LoadSkin(string name)
|
||||||
{
|
{
|
||||||
if (!SkinNames.Contains(name)) return;
|
if (!skinLoadStatus.ContainsKey(name)) return;
|
||||||
lock (_lock)
|
lock (_lock)
|
||||||
{
|
{
|
||||||
loadedSkins.Add(name);
|
skinLoadStatus[name] = true;
|
||||||
reloadSkins();
|
reloadSkins();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 卸载列表指定位置皮肤, 如果超出范围则忽略
|
/// 卸载指定皮肤, 如果不存在则忽略, 允许重复卸载
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void UnloadSkin(int idx)
|
public void UnloadSkin(string name)
|
||||||
{
|
{
|
||||||
|
if (!skinLoadStatus.ContainsKey(name)) return;
|
||||||
lock (_lock)
|
lock (_lock)
|
||||||
{
|
{
|
||||||
if (idx < 0 || idx >= loadedSkins.Count) return;
|
skinLoadStatus[name] = false;
|
||||||
loadedSkins.RemoveAt(idx);
|
|
||||||
reloadSkins();
|
reloadSkins();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 替换皮肤列表指定位置皮肤, 超出范围或者皮肤不存在则忽略
|
/// 刷新已加载皮肤
|
||||||
/// </summary>
|
|
||||||
public void ReplaceSkin(int idx, string name)
|
|
||||||
{
|
|
||||||
lock (_lock)
|
|
||||||
{
|
|
||||||
if (idx < 0 || idx >= loadedSkins.Count || !SkinNames.Contains(name)) return;
|
|
||||||
loadedSkins[idx] = name;
|
|
||||||
reloadSkins();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 重新加载现有皮肤列表, 用于刷新等操作
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void ReloadSkins() { lock (_lock) reloadSkins(); }
|
public void ReloadSkins() { lock (_lock) reloadSkins(); }
|
||||||
private void reloadSkins()
|
protected void reloadSkins()
|
||||||
{
|
{
|
||||||
clearSkin();
|
clearSkins();
|
||||||
foreach (var s in loadedSkins.Distinct()) addSkin(s);
|
foreach (var (name, _) in skinLoadStatus.Where(e => e.Value)) addSkin(name);
|
||||||
update(0);
|
update(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 加载皮肤, 如果不存在则忽略
|
|
||||||
/// </summary>
|
|
||||||
protected abstract void addSkin(string name);
|
protected abstract void addSkin(string name);
|
||||||
|
protected abstract void clearSkins();
|
||||||
/// <summary>
|
|
||||||
/// 清空加载的所有皮肤
|
|
||||||
/// </summary>
|
|
||||||
protected abstract void clearSkin();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取所有非 null 的轨道索引快照
|
/// 获取所有非 null 的轨道索引快照
|
||||||
|
|||||||
Reference in New Issue
Block a user