Spine-Unity运行时 低版本 兼容 Unity高版本

spine-unity运行时版本 3.6

unity版本2022

问题:spine动画在编辑器中无法预览(不影响正常使用)

解决:

1.找到 SkeletonDataAssetInspector.cs 脚本

2.移除Initialize方法中 的宏定义,正常只需要移除这一个就可以,其他的是否删除不影响

#if UNITY_2017_4 || UNITY_2018
	previewRenderUtility.AddSingleGO(previewGameObject);
#endif
public void Initialize (Action repaintCallback, SkeletonDataAsset skeletonDataAsset, string skinName = "") {
			if (skeletonDataAsset == null) return;
			if (skeletonDataAsset.GetSkeletonData(false) == null) {
				DestroyPreviewGameObject();
				return;
			}

			this.Repaint = repaintCallback;
			this.skeletonDataAsset = skeletonDataAsset;
			this.skeletonData = skeletonDataAsset.GetSkeletonData(false);

			if (skeletonData == null) {
				DestroyPreviewGameObject();
				return;
			}

			if (previewRenderUtility == null) {
				previewRenderUtility = new PreviewRenderUtility(true);
				#if !(UNITY_2017_4 || UNITY_2018)
				animationLastTime = CurrentTime;
				#endif

				const int PreviewLayer = 30;
				const int PreviewCameraCullingMask = 1 << PreviewLayer;

				{
					var c = this.PreviewUtilityCamera;
					c.orthographic = true;
					c.cullingMask = PreviewCameraCullingMask;
					c.nearClipPlane = 0.01f;
					c.farClipPlane = 1000f;
					c.orthographicSize = lastCameraOrthoGoal;
					c.transform.position = lastCameraPositionGoal;
				}

				DestroyPreviewGameObject();

				if (previewGameObject == null) {
					try {
						previewGameObject = SpineEditorUtilities.InstantiateSkeletonAnimation(skeletonDataAsset, skinName).gameObject;

						if (previewGameObject != null) {
							previewGameObject.hideFlags = HideFlags.HideAndDontSave;
							previewGameObject.layer = PreviewLayer;
							skeletonAnimation = previewGameObject.GetComponent<SkeletonAnimation>();
							skeletonAnimation.initialSkinName = skinName;
							skeletonAnimation.LateUpdate();
							previewGameObject.GetComponent<Renderer>().enabled = false;

							#if UNITY_2017_4 || UNITY_2018
							previewRenderUtility.AddSingleGO(previewGameObject);
							#endif
						}

						if (this.ActiveTrack != null) cameraAdjustEndFrame = EditorApplication.timeSinceStartup + skeletonAnimation.AnimationState.GetCurrent(0).Alpha;
						AdjustCameraGoals();
					} catch {
						DestroyPreviewGameObject();
					}

					RefreshOnNextUpdate();
				}
			}
		}

修改后

public void Initialize (Action repaintCallback, SkeletonDataAsset skeletonDataAsset, string skinName = "") {
			if (skeletonDataAsset == null) return;
			if (skeletonDataAsset.GetSkeletonData(false) == null) {
				DestroyPreviewGameObject();
				return;
			}

			this.Repaint = repaintCallback;
			this.skeletonDataAsset = skeletonDataAsset;
			this.skeletonData = skeletonDataAsset.GetSkeletonData(false);

			if (skeletonData == null) {
				DestroyPreviewGameObject();
				return;
			}

			if (previewRenderUtility == null) {
				previewRenderUtility = new PreviewRenderUtility(true);
				animationLastTime = CurrentTime;

				const int PreviewLayer = 30;
				const int PreviewCameraCullingMask = 1 << PreviewLayer;

				{
					var c = this.PreviewUtilityCamera;
					c.orthographic = true;
					c.cullingMask = PreviewCameraCullingMask;
					c.nearClipPlane = 0.01f;
					c.farClipPlane = 1000f;
					c.orthographicSize = lastCameraOrthoGoal;
					c.transform.position = lastCameraPositionGoal;
				}

				DestroyPreviewGameObject();

				if (previewGameObject == null) {
					try {
						previewGameObject = SpineEditorUtilities.InstantiateSkeletonAnimation(skeletonDataAsset, skinName).gameObject;

						if (previewGameObject != null) {
							previewGameObject.hideFlags = HideFlags.HideAndDontSave;
							previewGameObject.layer = PreviewLayer;
							skeletonAnimation = previewGameObject.GetComponent<SkeletonAnimation>();
							skeletonAnimation.initialSkinName = skinName;
							skeletonAnimation.LateUpdate();
							previewGameObject.GetComponent<Renderer>().enabled = false;

							previewRenderUtility.AddSingleGO(previewGameObject);
						}

						if (this.ActiveTrack != null) cameraAdjustEndFrame = EditorApplication.timeSinceStartup + skeletonAnimation.AnimationState.GetCurrent(0).Alpha;
						AdjustCameraGoals();
					} catch {
						DestroyPreviewGameObject();
					}

					RefreshOnNextUpdate();
				}
			}
		}

ps:修改后可能会出现预览动画速率不对的问题,可将SkeletonDataAssetInspector.cs脚本中其余的 #if !(UNITY_2017_4 || UNITY_2018) 宏定义全部改为 #if !UNITY_2017_4_OR_NEWER

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值