lockstep creates its own rendertextures

swapped button order on title screen
added null checks to animation helpers
disabled controller auto-search for now
This commit is contained in:
minenice55 2023-11-26 22:53:22 -05:00
parent d5c443d40b
commit a548c847ce
11 changed files with 76 additions and 217 deletions

View file

@ -66,7 +66,7 @@ MonoBehaviour:
m_OnCullStateChanged: m_OnCullStateChanged:
m_PersistentCalls: m_PersistentCalls:
m_Calls: [] m_Calls: []
m_Texture: {fileID: 8600000, guid: 7772de3e46eb44448b1d178755b3e627, type: 2} m_Texture: {fileID: 0}
m_UVRect: m_UVRect:
serializedVersion: 2 serializedVersion: 2
x: 0 x: 0
@ -138,7 +138,7 @@ Camera:
serializedVersion: 2 serializedVersion: 2
m_Bits: 1024 m_Bits: 1024
m_RenderingPath: -1 m_RenderingPath: -1
m_TargetTexture: {fileID: 8600000, guid: fc18082ae04938247a9aef9892d1ae5b, type: 2} m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0 m_TargetDisplay: 0
m_TargetEye: 3 m_TargetEye: 3
m_HDR: 0 m_HDR: 0
@ -382,7 +382,7 @@ MonoBehaviour:
m_OnCullStateChanged: m_OnCullStateChanged:
m_PersistentCalls: m_PersistentCalls:
m_Calls: [] m_Calls: []
m_Texture: {fileID: 8600000, guid: 7772de3e46eb44448b1d178755b3e627, type: 2} m_Texture: {fileID: 0}
m_UVRect: m_UVRect:
serializedVersion: 2 serializedVersion: 2
x: 0 x: 0
@ -997,9 +997,7 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
SoundSequences: [] SoundSequences: []
EligibleHits: []
scheduledInputs: [] scheduledInputs: []
firstEnable: 0
currentBGOnColor: {r: 0.9411765, g: 0.2, b: 0.5529412, a: 0} currentBGOnColor: {r: 0.9411765, g: 0.2, b: 0.5529412, a: 0}
currentBGOffColor: {r: 0.6039216, g: 0.15294118, b: 0.3764706, a: 0} currentBGOffColor: {r: 0.6039216, g: 0.15294118, b: 0.3764706, a: 0}
stepswitcherPlayer: {fileID: 5548089329135658778} stepswitcherPlayer: {fileID: 5548089329135658778}
@ -1031,10 +1029,16 @@ MonoBehaviour:
- {fileID: 4532798257539804896} - {fileID: 4532798257539804896}
- {fileID: 3262450115413950937} - {fileID: 3262450115413950937}
- {fileID: 1533188956834819093} - {fileID: 1533188956834819093}
renderTextures: rtSize: {x: 1024, y: 1860}
- {fileID: 8600000, guid: 6db82951191c9bb4a9433416ec4b8acd, type: 2} cameraNear1: {fileID: 4375666065977025420}
- {fileID: 8600000, guid: fc18082ae04938247a9aef9892d1ae5b, type: 2} cameraNear2: {fileID: 5999766133995784627}
- {fileID: 8600000, guid: 7772de3e46eb44448b1d178755b3e627, type: 2} cameraDV: {fileID: 1430771648366705456}
topT: {fileID: 828408474045052941}
topN: {fileID: 734131896781435878}
bottomL: {fileID: 5608916635847886312}
bottomC: {fileID: 4640860822531792563}
bottomR: {fileID: 1412824496340258240}
bottomN: {fileID: 2902868773272670157}
background: {fileID: 6381378020296668381} background: {fileID: 6381378020296668381}
stepperMaterial: {fileID: 2100000, guid: 471c4a2ed0684d24d9abb5c5aeffc0c4, type: 2} stepperMaterial: {fileID: 2100000, guid: 471c4a2ed0684d24d9abb5c5aeffc0c4, type: 2}
--- !u!1 &3794864692894715104 --- !u!1 &3794864692894715104
@ -1988,7 +1992,7 @@ Camera:
serializedVersion: 2 serializedVersion: 2
m_Bits: 1024 m_Bits: 1024
m_RenderingPath: -1 m_RenderingPath: -1
m_TargetTexture: {fileID: 8600000, guid: 6db82951191c9bb4a9433416ec4b8acd, type: 2} m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0 m_TargetDisplay: 0
m_TargetEye: 3 m_TargetEye: 3
m_HDR: 0 m_HDR: 0
@ -2401,7 +2405,7 @@ MonoBehaviour:
m_OnCullStateChanged: m_OnCullStateChanged:
m_PersistentCalls: m_PersistentCalls:
m_Calls: [] m_Calls: []
m_Texture: {fileID: 8600000, guid: fc18082ae04938247a9aef9892d1ae5b, type: 2} m_Texture: {fileID: 0}
m_UVRect: m_UVRect:
serializedVersion: 2 serializedVersion: 2
x: 0 x: 0
@ -2924,7 +2928,7 @@ Camera:
serializedVersion: 2 serializedVersion: 2
m_Bits: 3072 m_Bits: 3072
m_RenderingPath: -1 m_RenderingPath: -1
m_TargetTexture: {fileID: 8600000, guid: 7772de3e46eb44448b1d178755b3e627, type: 2} m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0 m_TargetDisplay: 0
m_TargetEye: 3 m_TargetEye: 3
m_HDR: 0 m_HDR: 0
@ -3242,7 +3246,7 @@ MonoBehaviour:
m_OnCullStateChanged: m_OnCullStateChanged:
m_PersistentCalls: m_PersistentCalls:
m_Calls: [] m_Calls: []
m_Texture: {fileID: 8600000, guid: 7772de3e46eb44448b1d178755b3e627, type: 2} m_Texture: {fileID: 0}
m_UVRect: m_UVRect:
serializedVersion: 2 serializedVersion: 2
x: 0 x: 0
@ -3399,7 +3403,7 @@ MonoBehaviour:
m_OnCullStateChanged: m_OnCullStateChanged:
m_PersistentCalls: m_PersistentCalls:
m_Calls: [] m_Calls: []
m_Texture: {fileID: 8600000, guid: 7772de3e46eb44448b1d178755b3e627, type: 2} m_Texture: {fileID: 0}
m_UVRect: m_UVRect:
serializedVersion: 2 serializedVersion: 2
x: 0 x: 0
@ -3578,7 +3582,7 @@ MonoBehaviour:
m_OnCullStateChanged: m_OnCullStateChanged:
m_PersistentCalls: m_PersistentCalls:
m_Calls: [] m_Calls: []
m_Texture: {fileID: 8600000, guid: 6db82951191c9bb4a9433416ec4b8acd, type: 2} m_Texture: {fileID: 0}
m_UVRect: m_UVRect:
serializedVersion: 2 serializedVersion: 2
x: 0 x: 0

View file

@ -5468,7 +5468,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1 m_IsActive: 0
--- !u!224 &3918594455165826550 --- !u!224 &3918594455165826550
RectTransform: RectTransform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -5486,9 +5486,9 @@ RectTransform:
m_Father: {fileID: 3918594455809915007} m_Father: {fileID: 3918594455809915007}
m_RootOrder: 2 m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 0, y: 0} m_AnchoredPosition: {x: 500, y: -25}
m_SizeDelta: {x: 206.38, y: 30} m_SizeDelta: {x: 206.38, y: 30}
m_Pivot: {x: 0, y: 0.5} m_Pivot: {x: 0, y: 0.5}
--- !u!222 &3918594455165826539 --- !u!222 &3918594455165826539
@ -8025,8 +8025,8 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 754, y: 0} m_AnchoredPosition: {x: 951.5, y: 0}
m_SizeDelta: {x: 1468, y: 0} m_SizeDelta: {x: 1863, y: 0}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &3918594456218978261 --- !u!222 &3918594456218978261
CanvasRenderer: CanvasRenderer:

View file

@ -1,54 +0,0 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!86 &8600000
CustomRenderTexture:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: SteppersNearBottom
m_ImageContentsHash:
serializedVersion: 2
Hash: 00000000000000000000000000000000
m_ForcedFallbackFormat: 4
m_DownscaleFallback: 0
m_IsAlphaChannelOptional: 0
serializedVersion: 5
m_Width: 1024
m_Height: 1860
m_AntiAliasing: 2
m_MipCount: -1
m_DepthStencilFormat: 91
m_ColorFormat: 8
m_MipMap: 0
m_GenerateMips: 1
m_SRGB: 0
m_UseDynamicScale: 0
m_BindMS: 0
m_EnableCompatibleFormat: 1
m_TextureSettings:
serializedVersion: 2
m_FilterMode: 1
m_Aniso: 0
m_MipBias: 0
m_WrapU: 0
m_WrapV: 0
m_WrapW: 0
m_Dimension: 2
m_VolumeDepth: 1
m_ShadowSamplingMode: 2
m_Material: {fileID: 0}
m_InitSource: 0
m_InitMaterial: {fileID: 0}
m_InitColor: {r: 0, g: 0, b: 0, a: 0}
m_InitTexture: {fileID: 0}
m_UpdateMode: 1
m_InitializationMode: 0
m_UpdateZoneSpace: 0
m_CurrentUpdateZoneSpace: 0
m_UpdateZones: []
m_UpdatePeriod: 0
m_ShaderPass: 0
m_CubemapFaceMask: 4294967295
m_DoubleBuffered: 1
m_WrapUpdateZones: 0

View file

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 6db82951191c9bb4a9433416ec4b8acd
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 8600000
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,54 +0,0 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!86 &8600000
CustomRenderTexture:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: SteppersNearTop
m_ImageContentsHash:
serializedVersion: 2
Hash: 00000000000000000000000000000000
m_ForcedFallbackFormat: 4
m_DownscaleFallback: 0
m_IsAlphaChannelOptional: 0
serializedVersion: 5
m_Width: 1024
m_Height: 1860
m_AntiAliasing: 2
m_MipCount: -1
m_DepthStencilFormat: 91
m_ColorFormat: 8
m_MipMap: 0
m_GenerateMips: 1
m_SRGB: 0
m_UseDynamicScale: 0
m_BindMS: 0
m_EnableCompatibleFormat: 1
m_TextureSettings:
serializedVersion: 2
m_FilterMode: 1
m_Aniso: 0
m_MipBias: 0
m_WrapU: 0
m_WrapV: 0
m_WrapW: 0
m_Dimension: 2
m_VolumeDepth: 1
m_ShadowSamplingMode: 2
m_Material: {fileID: 0}
m_InitSource: 0
m_InitMaterial: {fileID: 0}
m_InitColor: {r: 0, g: 0, b: 0, a: 0}
m_InitTexture: {fileID: 0}
m_UpdateMode: 1
m_InitializationMode: 0
m_UpdateZoneSpace: 0
m_CurrentUpdateZoneSpace: 0
m_UpdateZones: []
m_UpdatePeriod: 0
m_ShaderPass: 0
m_CubemapFaceMask: 4294967295
m_DoubleBuffered: 1
m_WrapUpdateZones: 0

View file

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: fc18082ae04938247a9aef9892d1ae5b
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 8600000
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,54 +0,0 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!86 &8600000
CustomRenderTexture:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: SteppersTileable
m_ImageContentsHash:
serializedVersion: 2
Hash: 00000000000000000000000000000000
m_ForcedFallbackFormat: 4
m_DownscaleFallback: 0
m_IsAlphaChannelOptional: 0
serializedVersion: 5
m_Width: 1024
m_Height: 1860
m_AntiAliasing: 2
m_MipCount: -1
m_DepthStencilFormat: 91
m_ColorFormat: 8
m_MipMap: 0
m_GenerateMips: 1
m_SRGB: 0
m_UseDynamicScale: 0
m_BindMS: 0
m_EnableCompatibleFormat: 1
m_TextureSettings:
serializedVersion: 2
m_FilterMode: 1
m_Aniso: 0
m_MipBias: 0
m_WrapU: 0
m_WrapV: 0
m_WrapW: 0
m_Dimension: 2
m_VolumeDepth: 1
m_ShadowSamplingMode: 2
m_Material: {fileID: 0}
m_InitSource: 0
m_InitMaterial: {fileID: 0}
m_InitColor: {r: 0, g: 0, b: 0, a: 0}
m_InitTexture: {fileID: 0}
m_UpdateMode: 1
m_InitializationMode: 0
m_UpdateZoneSpace: 0
m_CurrentUpdateZoneSpace: 0
m_UpdateZones: []
m_UpdatePeriod: 0
m_ShaderPass: 0
m_CubemapFaceMask: 4294967295
m_DoubleBuffered: 1
m_WrapUpdateZones: 0

View file

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 7772de3e46eb44448b1d178755b3e627
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 8600000
userData:
assetBundleName:
assetBundleVariant:

View file

@ -264,9 +264,9 @@ RectTransform:
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: m_Children:
- {fileID: 2098364309}
- {fileID: 1433046563}
- {fileID: 348029482} - {fileID: 348029482}
- {fileID: 1433046563}
- {fileID: 2098364309}
m_Father: {fileID: 551511482} m_Father: {fileID: 551511482}
m_RootOrder: 6 m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -418,7 +418,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1} m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1} m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 493, y: -3.5762405} m_AnchoredPosition: {x: 493, y: -3.576233}
m_SizeDelta: {x: 1149.1, y: 139.9575} m_SizeDelta: {x: 1149.1, y: 139.9575}
m_Pivot: {x: 0.5, y: 1} m_Pivot: {x: 0.5, y: 1}
--- !u!114 &75677143 --- !u!114 &75677143
@ -810,7 +810,7 @@ RectTransform:
m_Children: m_Children:
- {fileID: 1660460770} - {fileID: 1660460770}
m_Father: {fileID: 39837708} m_Father: {fileID: 39837708}
m_RootOrder: 2 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0}
@ -6889,7 +6889,7 @@ RectTransform:
m_Children: m_Children:
- {fileID: 1867253428} - {fileID: 1867253428}
m_Father: {fileID: 39837708} m_Father: {fileID: 39837708}
m_RootOrder: 0 m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0}

View file

@ -9,6 +9,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
using UnityEngine.UI;
namespace HeavenStudio.Games.Loaders namespace HeavenStudio.Games.Loaders
{ {
@ -197,13 +198,16 @@ namespace HeavenStudio.Games
[SerializeField] SpriteRenderer[] slaveSteppers; [SerializeField] SpriteRenderer[] slaveSteppers;
// rendertextures update when the slave steppers change sprites // rendertextures update when the slave steppers change sprites
[SerializeField] CustomRenderTexture[] renderTextures; [SerializeField] Vector2 rtSize;
[SerializeField] Camera cameraNear1, cameraNear2, cameraDV;
[SerializeField] RawImage topT, topN, bottomL, bottomC, bottomR, bottomN;
[SerializeField] SpriteRenderer background; [SerializeField] SpriteRenderer background;
[SerializeField] Material stepperMaterial; [SerializeField] Material stepperMaterial;
[Header("Properties")] [Header("Properties")]
static List<QueuedMarch> queuedInputs = new(); static List<QueuedMarch> queuedInputs = new();
RenderTexture[] renderTextures;
Sprite masterSprite; Sprite masterSprite;
HowMissed currentMissStage; HowMissed currentMissStage;
bool lessSteppers = false; bool lessSteppers = false;
@ -243,6 +247,31 @@ namespace HeavenStudio.Games
} }
bachEvents = EventCaller.GetAllInGameManagerList("lockstep", new string[] { "bach" }); bachEvents = EventCaller.GetAllInGameManagerList("lockstep", new string[] { "bach" });
renderTextures = new RenderTexture[3];
renderTextures[0] = new RenderTexture((int)rtSize.x, (int)rtSize.y, 24, RenderTextureFormat.ARGB32)
{
wrapMode = TextureWrapMode.Repeat,
};
renderTextures[1] = new RenderTexture((int)rtSize.x, (int)rtSize.y, 24, RenderTextureFormat.ARGB32)
{
wrapMode = TextureWrapMode.Repeat,
};
renderTextures[2] = new RenderTexture((int)rtSize.x, (int)rtSize.y, 24, RenderTextureFormat.ARGB32)
{
wrapMode = TextureWrapMode.Repeat,
};
cameraNear1.targetTexture = renderTextures[0];
cameraNear2.targetTexture = renderTextures[1];
cameraDV.targetTexture = renderTextures[2];
topT.texture = renderTextures[2];
topN.texture = renderTextures[0];
bottomL.texture = renderTextures[2];
bottomC.texture = renderTextures[2];
bottomR.texture = renderTextures[2];
bottomN.texture = renderTextures[1];
} }
void OnDestroy() void OnDestroy()
@ -320,6 +349,10 @@ namespace HeavenStudio.Games
masterStepperAnim.gameObject.SetActive(!lessSteppers); masterStepperAnim.gameObject.SetActive(!lessSteppers);
UpdateAndRenderSlaves(); UpdateAndRenderSlaves();
cameraNear1.Render();
cameraNear2.Render();
cameraDV.Render();
} }
void UpdateAndRenderSlaves() void UpdateAndRenderSlaves()
@ -701,7 +734,7 @@ namespace HeavenStudio.Games
private void JustOn(PlayerActionEvent caller, float state) private void JustOn(PlayerActionEvent caller, float state)
{ {
currentMissStage = HowMissed.NotMissed; currentMissStage = HowMissed.NotMissed;
stepswitcherPlayer.DoScaledAnimationAsync("OnbeatMarch", 0.5f); stepswitcherPlayer?.DoScaledAnimationAsync("OnbeatMarch", 0.5f);
if (state >= 1f || state <= -1f) if (state >= 1f || state <= -1f)
{ {
SoundByte.PlayOneShot("nearMiss"); SoundByte.PlayOneShot("nearMiss");
@ -714,7 +747,7 @@ namespace HeavenStudio.Games
private void JustOff(PlayerActionEvent caller, float state) private void JustOff(PlayerActionEvent caller, float state)
{ {
currentMissStage = HowMissed.NotMissed; currentMissStage = HowMissed.NotMissed;
stepswitcherPlayer.DoScaledAnimationAsync("OffbeatMarch", 0.5f); stepswitcherPlayer?.DoScaledAnimationAsync("OffbeatMarch", 0.5f);
if (state >= 1f || state <= -1f) if (state >= 1f || state <= -1f)
{ {
SoundByte.PlayOneShot("nearMiss"); SoundByte.PlayOneShot("nearMiss");
@ -727,7 +760,7 @@ namespace HeavenStudio.Games
private void MissOn(PlayerActionEvent caller) private void MissOn(PlayerActionEvent caller)
{ {
if (currentMissStage == HowMissed.MissedOn) return; if (currentMissStage == HowMissed.MissedOn) return;
stepswitcherPlayer.Play("OnbeatMiss", 0, 0); stepswitcherPlayer?.Play("OnbeatMiss", 0, 0);
SoundByte.PlayOneShotGame("lockstep/wayOff"); SoundByte.PlayOneShotGame("lockstep/wayOff");
currentMissStage = HowMissed.MissedOn; currentMissStage = HowMissed.MissedOn;
} }
@ -735,7 +768,7 @@ namespace HeavenStudio.Games
private void MissOff(PlayerActionEvent caller) private void MissOff(PlayerActionEvent caller)
{ {
if (currentMissStage == HowMissed.MissedOff) return; if (currentMissStage == HowMissed.MissedOff) return;
stepswitcherPlayer.Play("OffbeatMiss", 0, 0); stepswitcherPlayer?.Play("OffbeatMiss", 0, 0);
SoundByte.PlayOneShotGame("lockstep/wayOff"); SoundByte.PlayOneShotGame("lockstep/wayOff");
currentMissStage = HowMissed.MissedOff; currentMissStage = HowMissed.MissedOff;
} }

View file

@ -7,6 +7,7 @@ namespace HeavenStudio.Util
{ {
public static bool IsAnimationNotPlaying(this Animator anim) public static bool IsAnimationNotPlaying(this Animator anim)
{ {
if (anim == null) return true;
var stateInfo = anim.GetCurrentAnimatorStateInfo(0); var stateInfo = anim.GetCurrentAnimatorStateInfo(0);
return (stateInfo.normalizedTime >= stateInfo.speed || stateInfo.loop) && !anim.IsInTransition(0); return (stateInfo.normalizedTime >= stateInfo.speed || stateInfo.loop) && !anim.IsInTransition(0);
} }
@ -17,6 +18,7 @@ namespace HeavenStudio.Util
/// <param name="animName">name of animation to look out for</param> /// <param name="animName">name of animation to look out for</param>
public static bool IsPlayingAnimationName(this Animator anim, string animName) public static bool IsPlayingAnimationName(this Animator anim, string animName)
{ {
if (anim == null) return false;
var stateInfo = anim.GetCurrentAnimatorStateInfo(0); var stateInfo = anim.GetCurrentAnimatorStateInfo(0);
return (stateInfo.normalizedTime < stateInfo.speed || stateInfo.loop) && stateInfo.IsName(animName); return (stateInfo.normalizedTime < stateInfo.speed || stateInfo.loop) && stateInfo.IsName(animName);
} }
@ -33,6 +35,7 @@ namespace HeavenStudio.Util
/// <param name="animLayer">animator layer to play animation on</param> /// <param name="animLayer">animator layer to play animation on</param>
public static void DoScaledAnimation(this Animator anim, string animName, double startTime, float length = 1f, float timeScale = 1f, int animLayer = -1, bool clamp = false) public static void DoScaledAnimation(this Animator anim, string animName, double startTime, float length = 1f, float timeScale = 1f, int animLayer = -1, bool clamp = false)
{ {
if (anim == null) return;
float pos = Conductor.instance.GetPositionFromBeat(startTime, length) * timeScale; float pos = Conductor.instance.GetPositionFromBeat(startTime, length) * timeScale;
if (clamp) pos = Mathf.Clamp01(pos); if (clamp) pos = Mathf.Clamp01(pos);
anim.Play(animName, animLayer, pos); anim.Play(animName, animLayer, pos);
@ -48,6 +51,7 @@ namespace HeavenStudio.Util
/// <param name="animLayer">animator layer to play animation on</param> /// <param name="animLayer">animator layer to play animation on</param>
public static void DoNormalizedAnimation(this Animator anim, string animName, float pos = 0f, int animLayer = -1) public static void DoNormalizedAnimation(this Animator anim, string animName, float pos = 0f, int animLayer = -1)
{ {
if (anim == null) return;
anim.Play(animName, animLayer, pos); anim.Play(animName, animLayer, pos);
anim.speed = 1f; anim.speed = 1f;
} }
@ -63,6 +67,7 @@ namespace HeavenStudio.Util
/// <param name="animLayer">animator layer to play animation on</param> /// <param name="animLayer">animator layer to play animation on</param>
public static void DoScaledAnimationFromBeatAsync(this Animator anim, string animName, float timeScale = 1f, double startBeat = 0, int animLayer = -1) public static void DoScaledAnimationFromBeatAsync(this Animator anim, string animName, float timeScale = 1f, double startBeat = 0, int animLayer = -1)
{ {
if (anim == null) return;
float pos = 0; float pos = 0;
if (!double.IsNaN(startBeat)) { if (!double.IsNaN(startBeat)) {
var cond = Conductor.instance; var cond = Conductor.instance;
@ -86,12 +91,14 @@ namespace HeavenStudio.Util
/// <param name="animLayer">animator layer to play animation on</param> /// <param name="animLayer">animator layer to play animation on</param>
public static void DoScaledAnimationAsync(this Animator anim, string animName, float timeScale = 1f, float startPos = 0f, int animLayer = -1) public static void DoScaledAnimationAsync(this Animator anim, string animName, float timeScale = 1f, float startPos = 0f, int animLayer = -1)
{ {
if (anim == null) return;
anim.Play(animName, animLayer, startPos); anim.Play(animName, animLayer, startPos);
anim.speed = (1f / Conductor.instance.pitchedSecPerBeat) * timeScale; anim.speed = (1f / Conductor.instance.pitchedSecPerBeat) * timeScale;
} }
public static void SetScaledAnimationSpeed(this Animator anim, float timeScale = 0.5f) public static void SetScaledAnimationSpeed(this Animator anim, float timeScale = 0.5f)
{ {
if (anim == null) return;
anim.speed = (1f / Conductor.instance.pitchedSecPerBeat) * timeScale; anim.speed = (1f / Conductor.instance.pitchedSecPerBeat) * timeScale;
} }
@ -105,6 +112,7 @@ namespace HeavenStudio.Util
/// <param name="animLayer">animator layer to play animation on</param> /// <param name="animLayer">animator layer to play animation on</param>
public static void DoUnscaledAnimation(this Animator anim, string animName, float startPos = 0f, int animLayer = -1) public static void DoUnscaledAnimation(this Animator anim, string animName, float startPos = 0f, int animLayer = -1)
{ {
if (anim == null) return;
anim.Play(animName, animLayer, startPos); anim.Play(animName, animLayer, startPos);
anim.speed = 1f; anim.speed = 1f;
} }