From a548c847ce2d97eb56e0d35439e7ef2e6fd8e363 Mon Sep 17 00:00:00 2001 From: minenice55 Date: Sun, 26 Nov 2023 22:53:22 -0500 Subject: [PATCH] lockstep creates its own rendertextures swapped button order on title screen added null checks to animation helpers disabled controller auto-search for now --- Assets/Resources/Games/lockstep.prefab | 34 ++++++------ .../SettingsMenu/ControllerSetup.prefab | 12 ++--- .../RenderTextures/SteppersNearBottom.asset | 54 ------------------- .../SteppersNearBottom.asset.meta | 8 --- .../RenderTextures/SteppersNearTop.asset | 54 ------------------- .../RenderTextures/SteppersNearTop.asset.meta | 8 --- .../RenderTextures/SteppersTileable.asset | 54 ------------------- .../SteppersTileable.asset.meta | 8 --- Assets/Scenes/Title.unity | 10 ++-- Assets/Scripts/Games/Lockstep/Lockstep.cs | 43 +++++++++++++-- Assets/Scripts/Util/AnimationHelpers.cs | 8 +++ 11 files changed, 76 insertions(+), 217 deletions(-) delete mode 100644 Assets/Resources/Sprites/Games/Lockstep/RenderTextures/SteppersNearBottom.asset delete mode 100644 Assets/Resources/Sprites/Games/Lockstep/RenderTextures/SteppersNearBottom.asset.meta delete mode 100644 Assets/Resources/Sprites/Games/Lockstep/RenderTextures/SteppersNearTop.asset delete mode 100644 Assets/Resources/Sprites/Games/Lockstep/RenderTextures/SteppersNearTop.asset.meta delete mode 100644 Assets/Resources/Sprites/Games/Lockstep/RenderTextures/SteppersTileable.asset delete mode 100644 Assets/Resources/Sprites/Games/Lockstep/RenderTextures/SteppersTileable.asset.meta diff --git a/Assets/Resources/Games/lockstep.prefab b/Assets/Resources/Games/lockstep.prefab index 243411060..5b4cada90 100644 --- a/Assets/Resources/Games/lockstep.prefab +++ b/Assets/Resources/Games/lockstep.prefab @@ -66,7 +66,7 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_Texture: {fileID: 8600000, guid: 7772de3e46eb44448b1d178755b3e627, type: 2} + m_Texture: {fileID: 0} m_UVRect: serializedVersion: 2 x: 0 @@ -138,7 +138,7 @@ Camera: serializedVersion: 2 m_Bits: 1024 m_RenderingPath: -1 - m_TargetTexture: {fileID: 8600000, guid: fc18082ae04938247a9aef9892d1ae5b, type: 2} + m_TargetTexture: {fileID: 0} m_TargetDisplay: 0 m_TargetEye: 3 m_HDR: 0 @@ -382,7 +382,7 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_Texture: {fileID: 8600000, guid: 7772de3e46eb44448b1d178755b3e627, type: 2} + m_Texture: {fileID: 0} m_UVRect: serializedVersion: 2 x: 0 @@ -997,9 +997,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: SoundSequences: [] - EligibleHits: [] scheduledInputs: [] - firstEnable: 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} stepswitcherPlayer: {fileID: 5548089329135658778} @@ -1031,10 +1029,16 @@ MonoBehaviour: - {fileID: 4532798257539804896} - {fileID: 3262450115413950937} - {fileID: 1533188956834819093} - renderTextures: - - {fileID: 8600000, guid: 6db82951191c9bb4a9433416ec4b8acd, type: 2} - - {fileID: 8600000, guid: fc18082ae04938247a9aef9892d1ae5b, type: 2} - - {fileID: 8600000, guid: 7772de3e46eb44448b1d178755b3e627, type: 2} + rtSize: {x: 1024, y: 1860} + cameraNear1: {fileID: 4375666065977025420} + cameraNear2: {fileID: 5999766133995784627} + cameraDV: {fileID: 1430771648366705456} + topT: {fileID: 828408474045052941} + topN: {fileID: 734131896781435878} + bottomL: {fileID: 5608916635847886312} + bottomC: {fileID: 4640860822531792563} + bottomR: {fileID: 1412824496340258240} + bottomN: {fileID: 2902868773272670157} background: {fileID: 6381378020296668381} stepperMaterial: {fileID: 2100000, guid: 471c4a2ed0684d24d9abb5c5aeffc0c4, type: 2} --- !u!1 &3794864692894715104 @@ -1988,7 +1992,7 @@ Camera: serializedVersion: 2 m_Bits: 1024 m_RenderingPath: -1 - m_TargetTexture: {fileID: 8600000, guid: 6db82951191c9bb4a9433416ec4b8acd, type: 2} + m_TargetTexture: {fileID: 0} m_TargetDisplay: 0 m_TargetEye: 3 m_HDR: 0 @@ -2401,7 +2405,7 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_Texture: {fileID: 8600000, guid: fc18082ae04938247a9aef9892d1ae5b, type: 2} + m_Texture: {fileID: 0} m_UVRect: serializedVersion: 2 x: 0 @@ -2924,7 +2928,7 @@ Camera: serializedVersion: 2 m_Bits: 3072 m_RenderingPath: -1 - m_TargetTexture: {fileID: 8600000, guid: 7772de3e46eb44448b1d178755b3e627, type: 2} + m_TargetTexture: {fileID: 0} m_TargetDisplay: 0 m_TargetEye: 3 m_HDR: 0 @@ -3242,7 +3246,7 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_Texture: {fileID: 8600000, guid: 7772de3e46eb44448b1d178755b3e627, type: 2} + m_Texture: {fileID: 0} m_UVRect: serializedVersion: 2 x: 0 @@ -3399,7 +3403,7 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_Texture: {fileID: 8600000, guid: 7772de3e46eb44448b1d178755b3e627, type: 2} + m_Texture: {fileID: 0} m_UVRect: serializedVersion: 2 x: 0 @@ -3578,7 +3582,7 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_Texture: {fileID: 8600000, guid: 6db82951191c9bb4a9433416ec4b8acd, type: 2} + m_Texture: {fileID: 0} m_UVRect: serializedVersion: 2 x: 0 diff --git a/Assets/Resources/Prefabs/Editor/SettingsMenu/ControllerSetup.prefab b/Assets/Resources/Prefabs/Editor/SettingsMenu/ControllerSetup.prefab index 8ff32654d..c327de5de 100644 --- a/Assets/Resources/Prefabs/Editor/SettingsMenu/ControllerSetup.prefab +++ b/Assets/Resources/Prefabs/Editor/SettingsMenu/ControllerSetup.prefab @@ -5468,7 +5468,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!224 &3918594455165826550 RectTransform: m_ObjectHideFlags: 0 @@ -5486,9 +5486,9 @@ RectTransform: m_Father: {fileID: 3918594455809915007} m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 0} - m_AnchorMax: {x: 0, y: 0} - m_AnchoredPosition: {x: 0, y: 0} + m_AnchorMin: {x: 0, y: 1} + m_AnchorMax: {x: 0, y: 1} + m_AnchoredPosition: {x: 500, y: -25} m_SizeDelta: {x: 206.38, y: 30} m_Pivot: {x: 0, y: 0.5} --- !u!222 &3918594455165826539 @@ -8025,8 +8025,8 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0} - m_AnchoredPosition: {x: 754, y: 0} - m_SizeDelta: {x: 1468, y: 0} + m_AnchoredPosition: {x: 951.5, y: 0} + m_SizeDelta: {x: 1863, y: 0} m_Pivot: {x: 0.5, y: 0.5} --- !u!222 &3918594456218978261 CanvasRenderer: diff --git a/Assets/Resources/Sprites/Games/Lockstep/RenderTextures/SteppersNearBottom.asset b/Assets/Resources/Sprites/Games/Lockstep/RenderTextures/SteppersNearBottom.asset deleted file mode 100644 index 4aa58648a..000000000 --- a/Assets/Resources/Sprites/Games/Lockstep/RenderTextures/SteppersNearBottom.asset +++ /dev/null @@ -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 diff --git a/Assets/Resources/Sprites/Games/Lockstep/RenderTextures/SteppersNearBottom.asset.meta b/Assets/Resources/Sprites/Games/Lockstep/RenderTextures/SteppersNearBottom.asset.meta deleted file mode 100644 index 6604a1621..000000000 --- a/Assets/Resources/Sprites/Games/Lockstep/RenderTextures/SteppersNearBottom.asset.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 6db82951191c9bb4a9433416ec4b8acd -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 8600000 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Resources/Sprites/Games/Lockstep/RenderTextures/SteppersNearTop.asset b/Assets/Resources/Sprites/Games/Lockstep/RenderTextures/SteppersNearTop.asset deleted file mode 100644 index 56964b227..000000000 --- a/Assets/Resources/Sprites/Games/Lockstep/RenderTextures/SteppersNearTop.asset +++ /dev/null @@ -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 diff --git a/Assets/Resources/Sprites/Games/Lockstep/RenderTextures/SteppersNearTop.asset.meta b/Assets/Resources/Sprites/Games/Lockstep/RenderTextures/SteppersNearTop.asset.meta deleted file mode 100644 index 41c8a303c..000000000 --- a/Assets/Resources/Sprites/Games/Lockstep/RenderTextures/SteppersNearTop.asset.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: fc18082ae04938247a9aef9892d1ae5b -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 8600000 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Resources/Sprites/Games/Lockstep/RenderTextures/SteppersTileable.asset b/Assets/Resources/Sprites/Games/Lockstep/RenderTextures/SteppersTileable.asset deleted file mode 100644 index 56482aa14..000000000 --- a/Assets/Resources/Sprites/Games/Lockstep/RenderTextures/SteppersTileable.asset +++ /dev/null @@ -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 diff --git a/Assets/Resources/Sprites/Games/Lockstep/RenderTextures/SteppersTileable.asset.meta b/Assets/Resources/Sprites/Games/Lockstep/RenderTextures/SteppersTileable.asset.meta deleted file mode 100644 index 1cf48d8ea..000000000 --- a/Assets/Resources/Sprites/Games/Lockstep/RenderTextures/SteppersTileable.asset.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 7772de3e46eb44448b1d178755b3e627 -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 8600000 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scenes/Title.unity b/Assets/Scenes/Title.unity index 2ded81a6a..dc5f00435 100644 --- a/Assets/Scenes/Title.unity +++ b/Assets/Scenes/Title.unity @@ -264,9 +264,9 @@ RectTransform: m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: - - {fileID: 2098364309} - - {fileID: 1433046563} - {fileID: 348029482} + - {fileID: 1433046563} + - {fileID: 2098364309} m_Father: {fileID: 551511482} m_RootOrder: 6 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -418,7 +418,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {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_Pivot: {x: 0.5, y: 1} --- !u!114 &75677143 @@ -810,7 +810,7 @@ RectTransform: m_Children: - {fileID: 1660460770} m_Father: {fileID: 39837708} - m_RootOrder: 2 + m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0} @@ -6889,7 +6889,7 @@ RectTransform: m_Children: - {fileID: 1867253428} m_Father: {fileID: 39837708} - m_RootOrder: 0 + m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0} diff --git a/Assets/Scripts/Games/Lockstep/Lockstep.cs b/Assets/Scripts/Games/Lockstep/Lockstep.cs index 1b467fe7a..d26a5862c 100644 --- a/Assets/Scripts/Games/Lockstep/Lockstep.cs +++ b/Assets/Scripts/Games/Lockstep/Lockstep.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Generic; using System.Linq; using UnityEngine; +using UnityEngine.UI; namespace HeavenStudio.Games.Loaders { @@ -197,13 +198,16 @@ namespace HeavenStudio.Games [SerializeField] SpriteRenderer[] slaveSteppers; // 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] Material stepperMaterial; [Header("Properties")] static List queuedInputs = new(); + RenderTexture[] renderTextures; Sprite masterSprite; HowMissed currentMissStage; bool lessSteppers = false; @@ -243,6 +247,31 @@ namespace HeavenStudio.Games } 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() @@ -320,6 +349,10 @@ namespace HeavenStudio.Games masterStepperAnim.gameObject.SetActive(!lessSteppers); UpdateAndRenderSlaves(); + + cameraNear1.Render(); + cameraNear2.Render(); + cameraDV.Render(); } void UpdateAndRenderSlaves() @@ -701,7 +734,7 @@ namespace HeavenStudio.Games private void JustOn(PlayerActionEvent caller, float state) { currentMissStage = HowMissed.NotMissed; - stepswitcherPlayer.DoScaledAnimationAsync("OnbeatMarch", 0.5f); + stepswitcherPlayer?.DoScaledAnimationAsync("OnbeatMarch", 0.5f); if (state >= 1f || state <= -1f) { SoundByte.PlayOneShot("nearMiss"); @@ -714,7 +747,7 @@ namespace HeavenStudio.Games private void JustOff(PlayerActionEvent caller, float state) { currentMissStage = HowMissed.NotMissed; - stepswitcherPlayer.DoScaledAnimationAsync("OffbeatMarch", 0.5f); + stepswitcherPlayer?.DoScaledAnimationAsync("OffbeatMarch", 0.5f); if (state >= 1f || state <= -1f) { SoundByte.PlayOneShot("nearMiss"); @@ -727,7 +760,7 @@ namespace HeavenStudio.Games private void MissOn(PlayerActionEvent caller) { if (currentMissStage == HowMissed.MissedOn) return; - stepswitcherPlayer.Play("OnbeatMiss", 0, 0); + stepswitcherPlayer?.Play("OnbeatMiss", 0, 0); SoundByte.PlayOneShotGame("lockstep/wayOff"); currentMissStage = HowMissed.MissedOn; } @@ -735,7 +768,7 @@ namespace HeavenStudio.Games private void MissOff(PlayerActionEvent caller) { if (currentMissStage == HowMissed.MissedOff) return; - stepswitcherPlayer.Play("OffbeatMiss", 0, 0); + stepswitcherPlayer?.Play("OffbeatMiss", 0, 0); SoundByte.PlayOneShotGame("lockstep/wayOff"); currentMissStage = HowMissed.MissedOff; } diff --git a/Assets/Scripts/Util/AnimationHelpers.cs b/Assets/Scripts/Util/AnimationHelpers.cs index 093c9329d..689a4da44 100644 --- a/Assets/Scripts/Util/AnimationHelpers.cs +++ b/Assets/Scripts/Util/AnimationHelpers.cs @@ -7,6 +7,7 @@ namespace HeavenStudio.Util { public static bool IsAnimationNotPlaying(this Animator anim) { + if (anim == null) return true; var stateInfo = anim.GetCurrentAnimatorStateInfo(0); return (stateInfo.normalizedTime >= stateInfo.speed || stateInfo.loop) && !anim.IsInTransition(0); } @@ -17,6 +18,7 @@ namespace HeavenStudio.Util /// name of animation to look out for public static bool IsPlayingAnimationName(this Animator anim, string animName) { + if (anim == null) return false; var stateInfo = anim.GetCurrentAnimatorStateInfo(0); return (stateInfo.normalizedTime < stateInfo.speed || stateInfo.loop) && stateInfo.IsName(animName); } @@ -33,6 +35,7 @@ namespace HeavenStudio.Util /// animator layer to play animation on 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; if (clamp) pos = Mathf.Clamp01(pos); anim.Play(animName, animLayer, pos); @@ -48,6 +51,7 @@ namespace HeavenStudio.Util /// animator layer to play animation on 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.speed = 1f; } @@ -63,6 +67,7 @@ namespace HeavenStudio.Util /// animator layer to play animation on 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; if (!double.IsNaN(startBeat)) { var cond = Conductor.instance; @@ -86,12 +91,14 @@ namespace HeavenStudio.Util /// animator layer to play animation on 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.speed = (1f / Conductor.instance.pitchedSecPerBeat) * timeScale; } public static void SetScaledAnimationSpeed(this Animator anim, float timeScale = 0.5f) { + if (anim == null) return; anim.speed = (1f / Conductor.instance.pitchedSecPerBeat) * timeScale; } @@ -105,6 +112,7 @@ namespace HeavenStudio.Util /// animator layer to play animation on 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.speed = 1f; }