diff --git a/CHANGELOG.md b/CHANGELOG.md index fd7e65f30..b8dd85bd0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -90,6 +90,7 @@ * Added outline shader parameter `Advanced - Opaque Alpha` which can be used to exclude problematic semi-transparent areas, which may receive an undesired large outline color overlay otherwise. * Added Spine Preferences setting `Prefabs` - `Optimize Preview Meshes`. When enabled, Spine prefab preview meshes will be removed in a pre-build step to reduce build size. This increases build time as all prefabs in the project will be processed. Defaults to false to not slow down builds substantially every time. * Added Spine Preferences setting `Reload SkeletonData after Play`. When enabled, the shared `SkeletonData` of all skeletons in the active scene is reloaded (from the `.json` or `.skel.bytes` file) after exiting play-mode. You can disable this setting to avoid the reloading delay if you can ensure that there are no (accidental) modifications to the shared `SkeletonData` during play-mode (otherwise it would carry over its effect into subsequent plays). Defaults to `true` (the safe setting), which maintains existing behaviour. + * Added `SkeletonAnimationMulti` sample component methods `SetActiveSkeleton(int index)` and getter property `SkeletonAnimations` to more easily apply changes at all SkeletonAnimation instances instead of only the active one. * **Breaking changes** * Made `SkeletonGraphic.unscaledTime` parameter protected, use the new property `UnscaledTime` instead. diff --git a/spine-unity/Assets/Spine Examples/Scripts/Sample Components/SkeletonAnimationMulti/SkeletonAnimationMulti.cs b/spine-unity/Assets/Spine Examples/Scripts/Sample Components/SkeletonAnimationMulti/SkeletonAnimationMulti.cs index 509230bb4..f207c3074 100644 --- a/spine-unity/Assets/Spine Examples/Scripts/Sample Components/SkeletonAnimationMulti/SkeletonAnimationMulti.cs +++ b/spine-unity/Assets/Spine Examples/Scripts/Sample Components/SkeletonAnimationMulti/SkeletonAnimationMulti.cs @@ -56,17 +56,24 @@ namespace Spine.Unity { SkeletonAnimation currentSkeletonAnimation; void Clear () { - foreach (var s in skeletonAnimations) - Destroy(s.gameObject); + foreach (SkeletonAnimation skeletonAnimation in skeletonAnimations) + Destroy(skeletonAnimation.gameObject); skeletonAnimations.Clear(); animationNameTable.Clear(); animationSkeletonTable.Clear(); } + void SetActiveSkeleton (int index) { + if (index < 0 || index >= skeletonAnimations.Count) + SetActiveSkeleton(null); + else + SetActiveSkeleton(skeletonAnimations[index]); + } + void SetActiveSkeleton (SkeletonAnimation skeletonAnimation) { - foreach (var sa in skeletonAnimations) - sa.gameObject.SetActive(sa == skeletonAnimation); + foreach (SkeletonAnimation iter in skeletonAnimations) + iter.gameObject.SetActive(iter == skeletonAnimation); currentSkeletonAnimation = skeletonAnimation; } @@ -81,34 +88,35 @@ namespace Spine.Unity { public Dictionary AnimationSkeletonTable { get { return this.animationSkeletonTable; } } public Dictionary AnimationNameTable { get { return this.animationNameTable; } } public SkeletonAnimation CurrentSkeletonAnimation { get { return this.currentSkeletonAnimation; } } + public List SkeletonAnimations { get { return skeletonAnimations; } } public void Initialize (bool overwrite) { if (skeletonAnimations.Count != 0 && !overwrite) return; Clear(); - var settings = this.meshGeneratorSettings; + MeshGenerator.Settings settings = this.meshGeneratorSettings; Transform thisTransform = this.transform; - foreach (var sda in skeletonDataAssets) { - var sa = SkeletonAnimation.NewSkeletonAnimationGameObject(sda); - sa.transform.SetParent(thisTransform, false); + foreach (SkeletonDataAsset dataAsset in skeletonDataAssets) { + SkeletonAnimation newSkeletonAnimation = SkeletonAnimation.NewSkeletonAnimationGameObject(dataAsset); + newSkeletonAnimation.transform.SetParent(thisTransform, false); - sa.SetMeshSettings(settings); - sa.initialFlipX = this.initialFlipX; - sa.initialFlipY = this.initialFlipY; - var skeleton = sa.skeleton; + newSkeletonAnimation.SetMeshSettings(settings); + newSkeletonAnimation.initialFlipX = this.initialFlipX; + newSkeletonAnimation.initialFlipY = this.initialFlipY; + Skeleton skeleton = newSkeletonAnimation.skeleton; skeleton.ScaleX = this.initialFlipX ? -1 : 1; skeleton.ScaleY = this.initialFlipY ? -1 : 1; - sa.Initialize(false); - skeletonAnimations.Add(sa); + newSkeletonAnimation.Initialize(false); + skeletonAnimations.Add(newSkeletonAnimation); } // Build cache - var animationNameTable = this.animationNameTable; - var animationSkeletonTable = this.animationSkeletonTable; - foreach (var skeletonAnimation in skeletonAnimations) { - foreach (var animationObject in skeletonAnimation.Skeleton.Data.Animations) { + Dictionary animationNameTable = this.animationNameTable; + Dictionary animationSkeletonTable = this.animationSkeletonTable; + foreach (SkeletonAnimation skeletonAnimation in skeletonAnimations) { + foreach (Animation animationObject in skeletonAnimation.Skeleton.Data.Animations) { animationNameTable[animationObject.Name] = animationObject; animationSkeletonTable[animationObject] = skeletonAnimation; } @@ -119,7 +127,6 @@ namespace Spine.Unity { } public Animation FindAnimation (string animationName) { - // Analysis disable once LocalVariableHidesMember Animation animation; animationNameTable.TryGetValue(animationName, out animation); return animation; @@ -138,11 +145,10 @@ namespace Spine.Unity { if (skeletonAnimation != null) { SetActiveSkeleton(skeletonAnimation); skeletonAnimation.skeleton.SetToSetupPose(); - var trackEntry = skeletonAnimation.state.SetAnimation(MainTrackIndex, animation, loop); + TrackEntry trackEntry = skeletonAnimation.state.SetAnimation(MainTrackIndex, animation, loop); skeletonAnimation.Update(0); return trackEntry; } - return null; }