孙广东 2016.4.1 愚人节
两种方式:
1、更改源代码: 两个地方 (不推荐,修改源代码不是好事!)
在 SkeletonComponent.cs 中添加这 ︰ public bool ignoreTimeScale; // Now in line 45 // Inside Update float delta = Time.deltaTime; // Line 135 if (ignoreTimeScale && Application.isPlaying) //To not take effect in editor { float timeNow = Time.realtimeSinceStartup; delta = timeNow - lastInterval; lastInterval = timeNow; } UpdateSkeleton(delta); // Line 144
在 SkeletonAnimationInspector.cs: 中添加:
, ignoreTimeScale // Line 35 EditorGUILayout.PropertyField(ignoreTimeScale); // Line 106
2、不更改源代码:
正常使用的是:
SkeletonAnimationNotScaleTime.cs 代替官方的 SkeletonAnimation.cs
SkeletonAnimationInspector.cs 代替官方 的 SkeletonAnimationNotScaleTimeEditor.cs
using UnityEngine; using System.Collections; [ExecuteInEditMode] [AddComponentMenu("Spine/SkeletonAnimationNotScaleTime")] public class SkeletonAnimationNotScaleTime : SkeletonAnimation { public override void Update() { float unscaledDelta = Time.unscaledDeltaTime; base.Update(unscaledDelta); } }
以及 代码 :
using System; using UnityEditor; using UnityEngine; using Spine; [CustomEditor(typeof(SkeletonAnimationNotScaleTime))] public class SkeletonAnimationNotScaleTimeEditor : SkeletonRendererInspector { protected SerializedProperty animationName, loop, timeScale; protected bool isPrefab; protected override void OnEnable() { base.OnEnable(); animationName = serializedObject.FindProperty("_animationName"); loop = serializedObject.FindProperty("loop"); timeScale = serializedObject.FindProperty("timeScale"); if (PrefabUtility.GetPrefabType(this.target) == PrefabType.Prefab) isPrefab = true; } protected override void gui() { base.gui(); SkeletonAnimation component = (SkeletonAnimation)target; if (!component.valid) return; //catch case where SetAnimation was used to set track 0 without using AnimationName if (Application.isPlaying) { TrackEntry currentState = component.state.GetCurrent(0); if (currentState != null) { if (component.AnimationName != animationName.stringValue) { animationName.stringValue = currentState.Animation.Name; } } } EditorGUILayout.Space(); //TODO: Refactor this to use GenericMenu and callbacks to avoid interfering with control by other behaviours. // Animation name. { String[] animations = new String[component.skeleton.Data.Animations.Count + 1]; animations[0] = "<None>"; int animationIndex = 0; for (int i = 0; i < animations.Length - 1; i++) { String name = component.skeleton.Data.Animations.Items[i].Name; animations[i + 1] = name; if (name == animationName.stringValue) animationIndex = i + 1; } animationIndex = EditorGUILayout.Popup("Animation", animationIndex, animations); String selectedAnimationName = animationIndex == 0 ? null : animations[animationIndex]; if (component.AnimationName != selectedAnimationName) { component.AnimationName = selectedAnimationName; animationName.stringValue = selectedAnimationName; } } EditorGUILayout.PropertyField(loop); EditorGUILayout.PropertyField(timeScale); component.timeScale = Math.Max(component.timeScale, 0); EditorGUILayout.Space(); if (!isPrefab) { if (component.GetComponent<SkeletonUtility>() == null) { if (GUILayout.Button(new GUIContent("Add Skeleton Utility", SpineEditorUtilities.Icons.skeletonUtility), GUILayout.Height(30))) { component.gameObject.AddComponent<SkeletonUtility>(); } } } } }
当然了第二个脚本是可以简化为:
using System; using UnityEditor; using UnityEngine; using Spine; [CustomEditor(typeof(SkeletonAnimationNotScaleTime))] public class SkeletonAnimationNotScaleTimeEditor : SkeletonAnimationInspector { }