优化缩放实现
This commit is contained in:
@@ -115,7 +115,8 @@ namespace SpineViewer.Spine.Implementations.Spine
|
|||||||
var position = Position;
|
var position = Position;
|
||||||
var flipX = FlipX;
|
var flipX = FlipX;
|
||||||
var flipY = FlipY;
|
var flipY = FlipY;
|
||||||
var savedTrack0 = animationState.GetCurrent(0);
|
var animation = CurrentAnimation;
|
||||||
|
var skin = CurrentSkin;
|
||||||
|
|
||||||
var val = Math.Max(value, SCALE_MIN);
|
var val = Math.Max(value, SCALE_MIN);
|
||||||
if (skeletonBinary is not null)
|
if (skeletonBinary is not null)
|
||||||
@@ -138,21 +139,8 @@ namespace SpineViewer.Spine.Implementations.Spine
|
|||||||
Position = position;
|
Position = position;
|
||||||
FlipX = flipX;
|
FlipX = flipX;
|
||||||
FlipY = flipY;
|
FlipY = flipY;
|
||||||
|
CurrentAnimation = animation;
|
||||||
// 恢复原本 Track0 上所有动画
|
CurrentSkin = skin;
|
||||||
if (savedTrack0 is not null)
|
|
||||||
{
|
|
||||||
var entry = animationState.SetAnimation(0, savedTrack0.Animation.Name, true);
|
|
||||||
entry.Time = savedTrack0.Time;
|
|
||||||
// 2.1.x 没有提供 Next 访问器,故放弃还原后续动画,问题不大,因为预览画面目前不需要连续播放不同动画,只需要循环同一个动画
|
|
||||||
//var savedEntry = savedTrack0.Next;
|
|
||||||
//while (savedEntry is not null)
|
|
||||||
//{
|
|
||||||
// entry = animationState.AddAnimation(0, savedEntry.Animation.Name, true, 0);
|
|
||||||
// entry.Time = savedEntry.TrackTime;
|
|
||||||
// savedEntry = savedEntry.Next;
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,11 +181,10 @@ namespace SpineViewer.Spine.Implementations.Spine
|
|||||||
|
|
||||||
public override string CurrentSkin
|
public override string CurrentSkin
|
||||||
{
|
{
|
||||||
get => skeleton.Skin.Name;
|
get => skeleton.Skin?.Name ?? "default";
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (!skinNames.Contains(value))
|
if (!skinNames.Contains(value)) return;
|
||||||
return;
|
|
||||||
skeleton.SetSkin(value);
|
skeleton.SetSkin(value);
|
||||||
skeleton.SetToSetupPose();
|
skeleton.SetToSetupPose();
|
||||||
Update(0);
|
Update(0);
|
||||||
|
|||||||
@@ -114,7 +114,8 @@ namespace SpineViewer.Spine.Implementations.Spine
|
|||||||
var position = Position;
|
var position = Position;
|
||||||
var flipX = FlipX;
|
var flipX = FlipX;
|
||||||
var flipY = FlipY;
|
var flipY = FlipY;
|
||||||
var savedTrack0 = animationState.GetCurrent(0);
|
var animation = CurrentAnimation;
|
||||||
|
var skin = CurrentSkin;
|
||||||
|
|
||||||
var val = Math.Max(value, SCALE_MIN);
|
var val = Math.Max(value, SCALE_MIN);
|
||||||
if (skeletonBinary is not null)
|
if (skeletonBinary is not null)
|
||||||
@@ -137,20 +138,8 @@ namespace SpineViewer.Spine.Implementations.Spine
|
|||||||
Position = position;
|
Position = position;
|
||||||
FlipX = flipX;
|
FlipX = flipX;
|
||||||
FlipY = flipY;
|
FlipY = flipY;
|
||||||
|
CurrentAnimation = animation;
|
||||||
// 恢复原本 Track0 上所有动画
|
CurrentSkin = skin;
|
||||||
if (savedTrack0 is not null)
|
|
||||||
{
|
|
||||||
var entry = animationState.SetAnimation(0, savedTrack0.Animation.Name, true);
|
|
||||||
entry.TrackTime = savedTrack0.TrackTime;
|
|
||||||
var savedEntry = savedTrack0.Next;
|
|
||||||
while (savedEntry is not null)
|
|
||||||
{
|
|
||||||
entry = animationState.AddAnimation(0, savedEntry.Animation.Name, true, 0);
|
|
||||||
entry.TrackTime = savedEntry.TrackTime;
|
|
||||||
savedEntry = savedEntry.Next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,11 +180,10 @@ namespace SpineViewer.Spine.Implementations.Spine
|
|||||||
|
|
||||||
public override string CurrentSkin
|
public override string CurrentSkin
|
||||||
{
|
{
|
||||||
get => skeleton.Skin.Name;
|
get => skeleton.Skin?.Name ?? "default";
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (!skinNames.Contains(value))
|
if (!skinNames.Contains(value)) return;
|
||||||
return;
|
|
||||||
skeleton.SetSkin(value);
|
skeleton.SetSkin(value);
|
||||||
skeleton.SetToSetupPose();
|
skeleton.SetToSetupPose();
|
||||||
Update(0);
|
Update(0);
|
||||||
|
|||||||
@@ -197,11 +197,10 @@ namespace SpineViewer.Spine.Implementations.Spine
|
|||||||
|
|
||||||
public override string CurrentSkin
|
public override string CurrentSkin
|
||||||
{
|
{
|
||||||
get => skeleton.Skin.Name;
|
get => skeleton.Skin?.Name ?? "default";
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (!skinNames.Contains(value))
|
if (!skinNames.Contains(value)) return;
|
||||||
return;
|
|
||||||
skeleton.SetSkin(value);
|
skeleton.SetSkin(value);
|
||||||
skeleton.SetToSetupPose();
|
skeleton.SetToSetupPose();
|
||||||
Update(0);
|
Update(0);
|
||||||
|
|||||||
@@ -100,58 +100,11 @@ namespace SpineViewer.Spine.Implementations.Spine
|
|||||||
|
|
||||||
public override float Scale
|
public override float Scale
|
||||||
{
|
{
|
||||||
get
|
get => Math.Abs(skeleton.ScaleX);
|
||||||
{
|
|
||||||
if (skeletonBinary is not null)
|
|
||||||
return skeletonBinary.Scale;
|
|
||||||
else if (skeletonJson is not null)
|
|
||||||
return skeletonJson.Scale;
|
|
||||||
else
|
|
||||||
return 1f;
|
|
||||||
}
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
// 保存状态
|
skeleton.ScaleX = Math.Sign(skeleton.ScaleX) * value;
|
||||||
var position = Position;
|
skeleton.ScaleY = Math.Sign(skeleton.ScaleY) * value;
|
||||||
var flipX = FlipX;
|
|
||||||
var flipY = FlipY;
|
|
||||||
var savedTrack0 = animationState.GetCurrent(0);
|
|
||||||
|
|
||||||
var val = Math.Max(value, SCALE_MIN);
|
|
||||||
if (skeletonBinary is not null)
|
|
||||||
{
|
|
||||||
skeletonBinary.Scale = val;
|
|
||||||
skeletonData = skeletonBinary.ReadSkeletonData(SkelPath);
|
|
||||||
}
|
|
||||||
else if (skeletonJson is not null)
|
|
||||||
{
|
|
||||||
skeletonJson.Scale = val;
|
|
||||||
skeletonData = skeletonJson.ReadSkeletonData(SkelPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
// reload skel-dependent data
|
|
||||||
animationStateData = new AnimationStateData(skeletonData) { DefaultMix = animationStateData.DefaultMix };
|
|
||||||
skeleton = new Skeleton(skeletonData);
|
|
||||||
animationState = new AnimationState(animationStateData);
|
|
||||||
|
|
||||||
// 恢复状态
|
|
||||||
Position = position;
|
|
||||||
FlipX = flipX;
|
|
||||||
FlipY = flipY;
|
|
||||||
|
|
||||||
// 恢复原本 Track0 上所有动画
|
|
||||||
if (savedTrack0 is not null)
|
|
||||||
{
|
|
||||||
var entry = animationState.SetAnimation(0, savedTrack0.Animation.Name, true);
|
|
||||||
entry.TrackTime = savedTrack0.TrackTime;
|
|
||||||
var savedEntry = savedTrack0.Next;
|
|
||||||
while (savedEntry is not null)
|
|
||||||
{
|
|
||||||
entry = animationState.AddAnimation(0, savedEntry.Animation.Name, true, 0);
|
|
||||||
entry.TrackTime = savedEntry.TrackTime;
|
|
||||||
savedEntry = savedEntry.Next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,11 +153,10 @@ namespace SpineViewer.Spine.Implementations.Spine
|
|||||||
|
|
||||||
public override string CurrentSkin
|
public override string CurrentSkin
|
||||||
{
|
{
|
||||||
get => skeleton.Skin.Name;
|
get => skeleton.Skin?.Name ?? "default";
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (!skinNames.Contains(value))
|
if (!skinNames.Contains(value)) return;
|
||||||
return;
|
|
||||||
skeleton.SetSkin(value);
|
skeleton.SetSkin(value);
|
||||||
skeleton.SetToSetupPose();
|
skeleton.SetToSetupPose();
|
||||||
Update(0);
|
Update(0);
|
||||||
|
|||||||
@@ -99,58 +99,11 @@ namespace SpineViewer.Spine.Implementations.Spine
|
|||||||
|
|
||||||
public override float Scale
|
public override float Scale
|
||||||
{
|
{
|
||||||
get
|
get => Math.Abs(skeleton.ScaleX);
|
||||||
{
|
|
||||||
if (skeletonBinary is not null)
|
|
||||||
return skeletonBinary.Scale;
|
|
||||||
else if (skeletonJson is not null)
|
|
||||||
return skeletonJson.Scale;
|
|
||||||
else
|
|
||||||
return 1f;
|
|
||||||
}
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
// 保存状态
|
skeleton.ScaleX = Math.Sign(skeleton.ScaleX) * value;
|
||||||
var position = Position;
|
skeleton.ScaleY = Math.Sign(skeleton.ScaleY) * value;
|
||||||
var flipX = FlipX;
|
|
||||||
var flipY = FlipY;
|
|
||||||
var savedTrack0 = animationState.GetCurrent(0);
|
|
||||||
|
|
||||||
var val = Math.Max(value, SCALE_MIN);
|
|
||||||
if (skeletonBinary is not null)
|
|
||||||
{
|
|
||||||
skeletonBinary.Scale = val;
|
|
||||||
skeletonData = skeletonBinary.ReadSkeletonData(SkelPath);
|
|
||||||
}
|
|
||||||
else if (skeletonJson is not null)
|
|
||||||
{
|
|
||||||
skeletonJson.Scale = val;
|
|
||||||
skeletonData = skeletonJson.ReadSkeletonData(SkelPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
// reload skel-dependent data
|
|
||||||
animationStateData = new AnimationStateData(skeletonData) { DefaultMix = animationStateData.DefaultMix };
|
|
||||||
skeleton = new Skeleton(skeletonData);
|
|
||||||
animationState = new AnimationState(animationStateData);
|
|
||||||
|
|
||||||
// 恢复状态
|
|
||||||
Position = position;
|
|
||||||
FlipX = flipX;
|
|
||||||
FlipY = flipY;
|
|
||||||
|
|
||||||
// 恢复原本 Track0 上所有动画
|
|
||||||
if (savedTrack0 is not null)
|
|
||||||
{
|
|
||||||
var entry = animationState.SetAnimation(0, savedTrack0.Animation.Name, true);
|
|
||||||
entry.TrackTime = savedTrack0.TrackTime;
|
|
||||||
var savedEntry = savedTrack0.Next;
|
|
||||||
while (savedEntry is not null)
|
|
||||||
{
|
|
||||||
entry = animationState.AddAnimation(0, savedEntry.Animation.Name, true, 0);
|
|
||||||
entry.TrackTime = savedEntry.TrackTime;
|
|
||||||
savedEntry = savedEntry.Next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,11 +152,10 @@ namespace SpineViewer.Spine.Implementations.Spine
|
|||||||
|
|
||||||
public override string CurrentSkin
|
public override string CurrentSkin
|
||||||
{
|
{
|
||||||
get => skeleton.Skin.Name;
|
get => skeleton.Skin?.Name ?? "default";
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (!skinNames.Contains(value))
|
if (!skinNames.Contains(value)) return;
|
||||||
return;
|
|
||||||
skeleton.SetSkin(value);
|
skeleton.SetSkin(value);
|
||||||
skeleton.SetToSetupPose();
|
skeleton.SetToSetupPose();
|
||||||
Update(0);
|
Update(0);
|
||||||
|
|||||||
@@ -99,58 +99,11 @@ namespace SpineViewer.Spine.Implementations.Spine
|
|||||||
|
|
||||||
public override float Scale
|
public override float Scale
|
||||||
{
|
{
|
||||||
get
|
get => Math.Abs(skeleton.ScaleX);
|
||||||
{
|
|
||||||
if (skeletonBinary is not null)
|
|
||||||
return skeletonBinary.Scale;
|
|
||||||
else if (skeletonJson is not null)
|
|
||||||
return skeletonJson.Scale;
|
|
||||||
else
|
|
||||||
return 1f;
|
|
||||||
}
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
// 保存状态
|
skeleton.ScaleX = Math.Sign(skeleton.ScaleX) * value;
|
||||||
var position = Position;
|
skeleton.ScaleY = Math.Sign(skeleton.ScaleY) * value;
|
||||||
var flipX = FlipX;
|
|
||||||
var flipY = FlipY;
|
|
||||||
var savedTrack0 = animationState.GetCurrent(0);
|
|
||||||
|
|
||||||
var val = Math.Max(value, SCALE_MIN);
|
|
||||||
if (skeletonBinary is not null)
|
|
||||||
{
|
|
||||||
skeletonBinary.Scale = val;
|
|
||||||
skeletonData = skeletonBinary.ReadSkeletonData(SkelPath);
|
|
||||||
}
|
|
||||||
else if (skeletonJson is not null)
|
|
||||||
{
|
|
||||||
skeletonJson.Scale = val;
|
|
||||||
skeletonData = skeletonJson.ReadSkeletonData(SkelPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
// reload skel-dependent data
|
|
||||||
animationStateData = new AnimationStateData(skeletonData) { DefaultMix = animationStateData.DefaultMix };
|
|
||||||
skeleton = new Skeleton(skeletonData);
|
|
||||||
animationState = new AnimationState(animationStateData);
|
|
||||||
|
|
||||||
// 恢复状态
|
|
||||||
Position = position;
|
|
||||||
FlipX = flipX;
|
|
||||||
FlipY = flipY;
|
|
||||||
|
|
||||||
// 恢复原本 Track0 上所有动画
|
|
||||||
if (savedTrack0 is not null)
|
|
||||||
{
|
|
||||||
var entry = animationState.SetAnimation(0, savedTrack0.Animation.Name, true);
|
|
||||||
entry.TrackTime = savedTrack0.TrackTime;
|
|
||||||
var savedEntry = savedTrack0.Next;
|
|
||||||
while (savedEntry is not null)
|
|
||||||
{
|
|
||||||
entry = animationState.AddAnimation(0, savedEntry.Animation.Name, true, 0);
|
|
||||||
entry.TrackTime = savedEntry.TrackTime;
|
|
||||||
savedEntry = savedEntry.Next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,11 +152,10 @@ namespace SpineViewer.Spine.Implementations.Spine
|
|||||||
|
|
||||||
public override string CurrentSkin
|
public override string CurrentSkin
|
||||||
{
|
{
|
||||||
get => skeleton.Skin.Name;
|
get => skeleton.Skin?.Name ?? "default";
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (!skinNames.Contains(value))
|
if (!skinNames.Contains(value)) return;
|
||||||
return;
|
|
||||||
skeleton.SetSkin(value);
|
skeleton.SetSkin(value);
|
||||||
skeleton.SetToSetupPose();
|
skeleton.SetToSetupPose();
|
||||||
Update(0);
|
Update(0);
|
||||||
|
|||||||
@@ -99,58 +99,11 @@ namespace SpineViewer.Spine.Implementations.Spine
|
|||||||
|
|
||||||
public override float Scale
|
public override float Scale
|
||||||
{
|
{
|
||||||
get
|
get => Math.Abs(skeleton.ScaleX);
|
||||||
{
|
|
||||||
if (skeletonBinary is not null)
|
|
||||||
return skeletonBinary.Scale;
|
|
||||||
else if (skeletonJson is not null)
|
|
||||||
return skeletonJson.Scale;
|
|
||||||
else
|
|
||||||
return 1f;
|
|
||||||
}
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
// 保存状态
|
skeleton.ScaleX = Math.Sign(skeleton.ScaleX) * value;
|
||||||
var position = Position;
|
skeleton.ScaleY = Math.Sign(skeleton.ScaleY) * value;
|
||||||
var flipX = FlipX;
|
|
||||||
var flipY = FlipY;
|
|
||||||
var savedTrack0 = animationState.GetCurrent(0);
|
|
||||||
|
|
||||||
var val = Math.Max(value, SCALE_MIN);
|
|
||||||
if (skeletonBinary is not null)
|
|
||||||
{
|
|
||||||
skeletonBinary.Scale = val;
|
|
||||||
skeletonData = skeletonBinary.ReadSkeletonData(SkelPath);
|
|
||||||
}
|
|
||||||
else if (skeletonJson is not null)
|
|
||||||
{
|
|
||||||
skeletonJson.Scale = val;
|
|
||||||
skeletonData = skeletonJson.ReadSkeletonData(SkelPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
// reload skel-dependent data
|
|
||||||
animationStateData = new AnimationStateData(skeletonData) { DefaultMix = animationStateData.DefaultMix };
|
|
||||||
skeleton = new Skeleton(skeletonData);
|
|
||||||
animationState = new AnimationState(animationStateData);
|
|
||||||
|
|
||||||
// 恢复状态
|
|
||||||
Position = position;
|
|
||||||
FlipX = flipX;
|
|
||||||
FlipY = flipY;
|
|
||||||
|
|
||||||
// 恢复原本 Track0 上所有动画
|
|
||||||
if (savedTrack0 is not null)
|
|
||||||
{
|
|
||||||
var entry = animationState.SetAnimation(0, savedTrack0.Animation.Name, true);
|
|
||||||
entry.TrackTime = savedTrack0.TrackTime;
|
|
||||||
var savedEntry = savedTrack0.Next;
|
|
||||||
while (savedEntry is not null)
|
|
||||||
{
|
|
||||||
entry = animationState.AddAnimation(0, savedEntry.Animation.Name, true, 0);
|
|
||||||
entry.TrackTime = savedEntry.TrackTime;
|
|
||||||
savedEntry = savedEntry.Next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,11 +152,10 @@ namespace SpineViewer.Spine.Implementations.Spine
|
|||||||
|
|
||||||
public override string CurrentSkin
|
public override string CurrentSkin
|
||||||
{
|
{
|
||||||
get => skeleton.Skin.Name;
|
get => skeleton.Skin?.Name ?? "default";
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (!skinNames.Contains(value))
|
if (!skinNames.Contains(value)) return;
|
||||||
return;
|
|
||||||
skeleton.SetSkin(value);
|
skeleton.SetSkin(value);
|
||||||
skeleton.SetToSetupPose();
|
skeleton.SetToSetupPose();
|
||||||
Update(0);
|
Update(0);
|
||||||
|
|||||||
Reference in New Issue
Block a user