Selaa lähdekoodia

[unity] Added `UnscaledTime` property at `SkeletonAnimation`, behaving like `SkeletonGraphic.UnscaledTime`.

Harald Csaszar 3 vuotta sitten
vanhempi
commit
9427732038

+ 2 - 0
CHANGELOG.md

@@ -241,6 +241,7 @@
 
     Also removed less commonly used extension methods:
     `TrackEntry.AllowImmediateQueue()`, `Animation.SetKeyedItemsToSetupPose()` and `Attachment.IsRenderable()`.
+  * Made `SkeletonGraphic.unscaledTime` parameter protected, use the new property `UnscaledTime` instead.
 
   * **`SkeletonGraphic` now no longer uses a `RawImage` component at each submesh renderer** GameObject when `allowMultipleCanvasRenderers` is true. Instead,  a new custom component `SkeletonSubmeshGraphic` is used which is more resource friendly. Replacement of these components will be performed automatically through editor scripting, saving scenes or prefabs will persist the upgrade.
   * **Linear color space:** Previously Slot colors were not displayed the same in Unity as in the Spine Editor. This is now fixed at all shaders, including URP and LWRP shaders. See section *Additions* below for more details. If you have tweaked Slot colors to look correct in `Linear` color space in Unity but incorrect in Spine, you might want to adjust the tweaked colors. Slot colors displayed in Unity should now match colors displayed in the Spine Editor when configured to display as `Linear` color space in the Spine Editor Settings.
@@ -307,6 +308,7 @@
   * Added example component `SkeletonRenderTexture` to render a `SkeletonRenderer` to a `RenderTexture`, mainly for proper transparency. Added an example scene named `RenderTexture FadeOut Transparency` that demonstrates usage for a fadeout transparency effect.
   * Added another fadeout example component named `SkeletonRenderTextureFadeout` which takes over transparency fadeout when enabled. You can use this component as-is, attach it in disabled state and enable it to start a fadeout effect.
   * Timeline clips now offer an additional `Alpha` parameter for setting a custom constant mix alpha value other than 1.0, just as `TrackEntry.Alpha`. Defaults to 1.0.
+  * Added `UnscaledTime` property at `SkeletonAnimation` as well, behaving like `SkeletonGraphic.UnscaledTime`. If enabled, AnimationState uses unscaled game time (`Time.unscaledDeltaTime`), running animations independent of e.g. game pause (`Time.timeScale`).
 
 * **Changes of default values**
 

+ 7 - 1
spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonAnimationInspector.cs

@@ -36,16 +36,21 @@ namespace Spine.Unity.Editor {
 	[CustomEditor(typeof(SkeletonAnimation))]
 	[CanEditMultipleObjects]
 	public class SkeletonAnimationInspector : SkeletonRendererInspector {
-		protected SerializedProperty animationName, loop, timeScale, autoReset;
+		protected SerializedProperty animationName, loop, timeScale, unscaledTime, autoReset;
 		protected bool wasAnimationParameterChanged = false;
 		readonly GUIContent LoopLabel = new GUIContent("Loop", "Whether or not .AnimationName should loop. This only applies to the initial animation specified in the inspector, or any subsequent Animations played through .AnimationName. Animations set through state.SetAnimation are unaffected.");
 		readonly GUIContent TimeScaleLabel = new GUIContent("Time Scale", "The rate at which animations progress over time. 1 means normal speed. 0.5 means 50% speed.");
+		readonly GUIContent UnscaledTimeLabel = new GUIContent("Unscaled Time",
+			"If enabled, AnimationState uses unscaled game time (Time.unscaledDeltaTime), " +
+				"running animations independent of e.g. game pause (Time.timeScale). " +
+				"Instance SkeletonAnimation.timeScale will still be applied.");
 
 		protected override void OnEnable () {
 			base.OnEnable();
 			animationName = serializedObject.FindProperty("_animationName");
 			loop = serializedObject.FindProperty("loop");
 			timeScale = serializedObject.FindProperty("timeScale");
+			unscaledTime = serializedObject.FindProperty("unscaledTime");
 		}
 
 		protected override void DrawInspectorGUI (bool multi) {
@@ -69,6 +74,7 @@ namespace Spine.Unity.Editor {
 			EditorGUILayout.PropertyField(loop, LoopLabel);
 			wasAnimationParameterChanged |= EditorGUI.EndChangeCheck(); // Value used in the next update.
 			EditorGUILayout.PropertyField(timeScale, TimeScaleLabel);
+			EditorGUILayout.PropertyField(unscaledTime, UnscaledTimeLabel);
 			foreach (var o in targets) {
 				var component = o as SkeletonAnimation;
 				component.timeScale = Mathf.Max(component.timeScale, 0);

+ 5 - 2
spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonGraphicInspector.cs

@@ -62,7 +62,10 @@ namespace Spine.Unity.Editor {
 		SerializedProperty allowMultipleCanvasRenderers, separatorSlotNames, enableSeparatorSlots, updateSeparatorPartLocation;
 		SerializedProperty raycastTarget;
 
-
+		readonly GUIContent UnscaledTimeLabel = new GUIContent("Unscaled Time",
+			"If enabled, AnimationState uses unscaled game time (Time.unscaledDeltaTime), " +
+				"running animations independent of e.g. game pause (Time.timeScale). " +
+				"Instance SkeletonAnimation.timeScale will still be applied.");
 
 		SkeletonGraphic thisSkeletonGraphic;
 		protected bool isInspectingPrefab;
@@ -284,7 +287,7 @@ namespace Spine.Unity.Editor {
 			EditorGUILayout.PropertyField(startingAnimation);
 			EditorGUILayout.PropertyField(startingLoop);
 			EditorGUILayout.PropertyField(timeScale);
-			EditorGUILayout.PropertyField(unscaledTime, SpineInspectorUtility.TempContent(unscaledTime.displayName, tooltip: "If checked, this will use Time.unscaledDeltaTime to make this update independent of game Time.timeScale. Instance SkeletonGraphic.timeScale will still be applied."));
+			EditorGUILayout.PropertyField(unscaledTime, UnscaledTimeLabel);
 			EditorGUILayout.Space();
 			EditorGUILayout.PropertyField(freeze);
 			EditorGUILayout.Space();

+ 9 - 2
spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonAnimation.cs

@@ -93,6 +93,13 @@ namespace Spine.Unity {
 
 		[SerializeField] protected UpdateTiming updateTiming = UpdateTiming.InUpdate;
 		public UpdateTiming UpdateTiming { get { return updateTiming; } set { updateTiming = value; } }
+
+		/// <summary>If enabled, AnimationState uses unscaled game time
+		/// (<c>Time.unscaledDeltaTime</c> instead of normal game time(<c>Time.deltaTime</c>),
+		/// running animations independent of e.g. game pause (<c>Time.timeScale</c>).
+		/// Instance SkeletonAnimation.timeScale will still be applied.</summary>
+		[SerializeField] protected bool unscaledTime;
+		public bool UnscaledTime { get { return unscaledTime; } set { unscaledTime = value; } }
 		#endregion
 
 		#region Serialized state and Beginner API
@@ -200,12 +207,12 @@ namespace Spine.Unity {
 			}
 #endif
 			if (updateTiming != UpdateTiming.InUpdate) return;
-			Update(Time.deltaTime);
+			Update(unscaledTime ? Time.unscaledDeltaTime : Time.deltaTime);
 		}
 
 		virtual protected void FixedUpdate () {
 			if (updateTiming != UpdateTiming.InFixedUpdate) return;
-			Update(Time.deltaTime);
+			Update(unscaledTime ? Time.unscaledDeltaTime : Time.deltaTime);
 		}
 
 		/// <summary>Progresses the AnimationState according to the given deltaTime, and applies it to the Skeleton. Use Time.deltaTime to update manually. Use deltaTime 0 to update without progressing the time.</summary>

+ 3 - 1
spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs

@@ -77,7 +77,6 @@ namespace Spine.Unity {
 		/// reset to <c>UpdateMode.FullUpdate</c> when the mesh becomes visible again.</summary>
 		public UpdateMode updateWhenInvisible = UpdateMode.FullUpdate;
 
-		public bool unscaledTime;
 		public bool allowMultipleCanvasRenderers = false;
 		public List<CanvasRenderer> canvasRenderers = new List<CanvasRenderer>();
 		protected List<SkeletonSubmeshGraphic> submeshGraphics = new List<SkeletonSubmeshGraphic>();
@@ -499,6 +498,9 @@ namespace Spine.Unity {
 		[SerializeField] protected UpdateTiming updateTiming = UpdateTiming.InUpdate;
 		public UpdateTiming UpdateTiming { get { return updateTiming; } set { updateTiming = value; } }
 
+		[SerializeField] protected bool unscaledTime;
+		public bool UnscaledTime { get { return unscaledTime; } set { unscaledTime = value; } }
+
 		/// <summary> Occurs after the vertex data populated every frame, before the vertices are pushed into the mesh.</summary>
 		public event Spine.Unity.MeshGeneratorDelegate OnPostProcessVertices;
 

+ 10 - 0
spine-unity/Assets/Spine/Runtime/spine-unity/ISkeletonAnimation.cs

@@ -43,6 +43,11 @@ namespace Spine.Unity {
 		InFixedUpdate
 	}
 
+	public enum UpdateTimeScale {
+		GameTime = 0,
+		UnscaledGameTime
+	}
+
 	public delegate void UpdateBonesDelegate (ISkeletonAnimation animated);
 
 	public interface ISpineComponent { }
@@ -82,6 +87,11 @@ namespace Spine.Unity {
 	public interface IAnimationStateComponent : ISpineComponent {
 		/// <summary>Gets the Spine.AnimationState of the animated Spine Component. This is equivalent to SkeletonAnimation.state.</summary>
 		AnimationState AnimationState { get; }
+		/// <summary>If enabled, AnimationState time is advanced by Unscaled Game Time
+		/// (<c>Time.unscaledDeltaTime</c> instead of the default Game Time(<c>Time.deltaTime</c>).
+		/// to animate independent of game <c>Time.timeScale</c>.
+		/// Instance SkeletonGraphic.timeScale and SkeletonAnimation.timeScale will still be applied.</summary>
+		public bool UnscaledTime { get; set; }
 	}
 
 	/// <summary>A Spine-Unity Component that holds a reference to a SkeletonRenderer.</summary>