瀏覽代碼

[unity] Fixed null reference exception at ActivateBasedOnFlipDirection Component. Closes #1643.

Harald Csaszar 5 年之前
父節點
當前提交
36a6d62ef0

+ 2 - 1
spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonUtilityBoneInspector.cs

@@ -319,7 +319,8 @@ namespace Spine.Unity.Editor {
 
 			GameObject commonParentObject = new GameObject(skeletonUtility.name + " HingeChain Parent " + utilityBone.name);
 			var commonParentActivateOnFlip = commonParentObject.AddComponent<ActivateBasedOnFlipDirection>();
-			commonParentActivateOnFlip.skeletonRenderer = skeletonUtility.SkeletonComponent;
+			commonParentActivateOnFlip.skeletonRenderer = skeletonUtility.skeletonRenderer;
+			commonParentActivateOnFlip.skeletonGraphic = skeletonUtility.skeletonGraphic;
 
 			// HingeChain Parent
 			// Needs to be on top hierarchy level (not attached to the moving skeleton at least) for physics to apply proper momentum.

+ 5 - 2
spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonUtility/ActivateBasedOnFlipDirection.cs

@@ -39,21 +39,24 @@ namespace Spine.Unity {
 	/// </summary>
 	public class ActivateBasedOnFlipDirection : MonoBehaviour {
 
-		public ISkeletonComponent skeletonRenderer;
+		public SkeletonRenderer skeletonRenderer;
+		public SkeletonGraphic skeletonGraphic;
 		public GameObject activeOnNormalX;
 		public GameObject activeOnFlippedX;
 		HingeJoint2D[] jointsNormalX;
 		HingeJoint2D[] jointsFlippedX;
+		ISkeletonComponent skeletonComponent;
 
 		bool wasFlippedXBefore = false;
 
 		private void Start () {
 			jointsNormalX = activeOnNormalX.GetComponentsInChildren<HingeJoint2D>();
 			jointsFlippedX = activeOnFlippedX.GetComponentsInChildren<HingeJoint2D>();
+			skeletonComponent = skeletonRenderer != null ? (ISkeletonComponent)skeletonRenderer : (ISkeletonComponent)skeletonGraphic;
 		}
 
 		private void FixedUpdate () {
-			bool isFlippedX = (skeletonRenderer.Skeleton.ScaleX < 0);
+			bool isFlippedX = (skeletonComponent.Skeleton.ScaleX < 0);
 			if (isFlippedX != wasFlippedXBefore) {
 				HandleFlip(isFlippedX);
 			}