Pārlūkot izejas kodu

[unity] Automatically updating SkeletonRootMotion references after SkeletonDataAsset change. Exposed `rootMotionBoneName`. Closes #2575.

Harald Csaszar 1 gadu atpakaļ
vecāks
revīzija
d2953d6053

+ 1 - 0
CHANGELOG.md

@@ -161,6 +161,7 @@
   - Added support for BlendModeMaterials at runtime instantiation from files via an additional method `SkeletonDataAsset.SetupRuntimeBlendModeMaterials`. See example scene `Spine Examples/Other Examples/Instantiate from Script` for a usage example.
   - Added support for BlendModeMaterials at runtime instantiation from files via an additional method `SkeletonDataAsset.SetupRuntimeBlendModeMaterials`. See example scene `Spine Examples/Other Examples/Instantiate from Script` for a usage example.
   - SkeletonGraphic: You can now offset the skeleton mesh relative to the pivot via a newly added green circle handle. This allows you to e.g. frame only the face of a skeleton inside a masked frame. Previously offsetting the pivot downwards fails when `Layout Scale Mode` scales the mesh smaller and towards the pivot (e.g. the feet) and thus out of the frame. Now you can keep the pivot in the center of the `RectTransform` while offsetting only the mesh downwards, keeping the desired skeleton area (e.g. the face) centered while resizing. Moving the new larger green circle handle moves the mesh offset, while moving the blue pivot circle handle moves the pivot as usual.
   - SkeletonGraphic: You can now offset the skeleton mesh relative to the pivot via a newly added green circle handle. This allows you to e.g. frame only the face of a skeleton inside a masked frame. Previously offsetting the pivot downwards fails when `Layout Scale Mode` scales the mesh smaller and towards the pivot (e.g. the feet) and thus out of the frame. Now you can keep the pivot in the center of the `RectTransform` while offsetting only the mesh downwards, keeping the desired skeleton area (e.g. the face) centered while resizing. Moving the new larger green circle handle moves the mesh offset, while moving the blue pivot circle handle moves the pivot as usual.
   - `Universal Render Pipeline/Spine/Skeleton` shader now performs proper alpha-testing when `Depth Write` is enabled, using the existing `Shadow alpha cutoff` parameter.
   - `Universal Render Pipeline/Spine/Skeleton` shader now performs proper alpha-testing when `Depth Write` is enabled, using the existing `Shadow alpha cutoff` parameter.
+  - `SkeletonRootMotion` components now provide a public `Initialize()` method which is automatically called when calling `skeletonAnimation.Initialize(true)` to update the necessary skeleton references. If a different root bone shall be used, be sure to set `skeletonRootMotion.rootMotionBoneName` before calling `skeletonAnimation.Initialize(true)`.
 
 
 - **Breaking changes**
 - **Breaking changes**
 
 

+ 2 - 2
spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonMecanimRootMotion.cs

@@ -88,8 +88,8 @@ namespace Spine.Unity {
 			mecanimLayerFlags = DefaultMecanimLayerFlags;
 			mecanimLayerFlags = DefaultMecanimLayerFlags;
 		}
 		}
 
 
-		protected override void Start () {
-			base.Start();
+		public override void Initialize () {
+			base.Initialize();
 			skeletonMecanim = GetComponent<SkeletonMecanim>();
 			skeletonMecanim = GetComponent<SkeletonMecanim>();
 			if (skeletonMecanim) {
 			if (skeletonMecanim) {
 				skeletonMecanim.Translator.OnClipApplied -= OnClipApplied;
 				skeletonMecanim.Translator.OnClipApplied -= OnClipApplied;

+ 2 - 2
spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotion.cs

@@ -88,8 +88,8 @@ namespace Spine.Unity {
 			animationTrackFlags = DefaultAnimationTrackFlags;
 			animationTrackFlags = DefaultAnimationTrackFlags;
 		}
 		}
 
 
-		protected override void Start () {
-			base.Start();
+		public override void Initialize () {
+			base.Initialize();
 			IAnimationStateComponent animstateComponent = skeletonComponent as IAnimationStateComponent;
 			IAnimationStateComponent animstateComponent = skeletonComponent as IAnimationStateComponent;
 			this.animationState = (animstateComponent != null) ? animstateComponent.AnimationState : null;
 			this.animationState = (animstateComponent != null) ? animstateComponent.AnimationState : null;
 
 

+ 14 - 3
spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotionBase.cs

@@ -42,8 +42,7 @@ namespace Spine.Unity {
 
 
 		#region Inspector
 		#region Inspector
 		[SpineBone]
 		[SpineBone]
-		[SerializeField]
-		protected string rootMotionBoneName = "root";
+		public string rootMotionBoneName = "root";
 		public bool transformPositionX = true;
 		public bool transformPositionX = true;
 		public bool transformPositionY = true;
 		public bool transformPositionY = true;
 		public bool transformRotation = false;
 		public bool transformRotation = false;
@@ -155,6 +154,14 @@ namespace Spine.Unity {
 		}
 		}
 
 
 		protected virtual void Start () {
 		protected virtual void Start () {
+			Initialize();
+		}
+
+		protected void InitializeOnRebuild (ISkeletonAnimation animatedSkeletonComponent) {
+			Initialize();
+		}
+
+		public virtual void Initialize () {
 			skeletonComponent = GetComponent<ISkeletonComponent>();
 			skeletonComponent = GetComponent<ISkeletonComponent>();
 			GatherTopLevelBones();
 			GatherTopLevelBones();
 			SetRootMotionBone(rootMotionBoneName);
 			SetRootMotionBone(rootMotionBoneName);
@@ -167,6 +174,9 @@ namespace Spine.Unity {
 			if (skeletonAnimation != null) {
 			if (skeletonAnimation != null) {
 				skeletonAnimation.UpdateLocal -= HandleUpdateLocal;
 				skeletonAnimation.UpdateLocal -= HandleUpdateLocal;
 				skeletonAnimation.UpdateLocal += HandleUpdateLocal;
 				skeletonAnimation.UpdateLocal += HandleUpdateLocal;
+
+				skeletonAnimation.OnAnimationRebuild -= InitializeOnRebuild;
+				skeletonAnimation.OnAnimationRebuild += InitializeOnRebuild;
 			}
 			}
 		}
 		}
 
 
@@ -271,7 +281,8 @@ namespace Spine.Unity {
 				this.rootMotionBone = bone;
 				this.rootMotionBone = bone;
 				FindTransformConstraintsAffectingBone();
 				FindTransformConstraintsAffectingBone();
 			} else {
 			} else {
-				Debug.Log("Bone named \"" + name + "\" could not be found.");
+				Debug.Log("Bone named \"" + name + "\" could not be found. " +
+					"Set 'skeletonRootMotion.rootMotionBoneName' before calling 'skeletonAnimation.Initialize(true)'.");
 				this.rootMotionBoneIndex = 0;
 				this.rootMotionBoneIndex = 0;
 				this.rootMotionBone = skeleton.RootBone;
 				this.rootMotionBone = skeleton.RootBone;
 			}
 			}

+ 1 - 1
spine-unity/Assets/Spine/package.json

@@ -2,7 +2,7 @@
 	"name": "com.esotericsoftware.spine.spine-unity",
 	"name": "com.esotericsoftware.spine.spine-unity",
 	"displayName": "spine-unity Runtime",
 	"displayName": "spine-unity Runtime",
 	"description": "This plugin provides the spine-unity runtime core.",
 	"description": "This plugin provides the spine-unity runtime core.",
-	"version": "4.2.76",
+	"version": "4.2.77",
 	"unity": "2018.3",
 	"unity": "2018.3",
 	"author": {
 	"author": {
 		"name": "Esoteric Software",
 		"name": "Esoteric Software",