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