From 3c687b5b2945396b0da0e7efb725d0cc57d6fbce Mon Sep 17 00:00:00 2001 From: jreason Date: Sun, 30 Jan 2022 16:05:49 +1100 Subject: [PATCH] Added Animations --- .../Art Assets/Animations/Player/Death.anim | 53 +++++++++++++++++++ .../Animations/Player/Death.anim.meta | 8 +++ Assets/Art Assets/Animations/Player/Land.anim | 53 +++++++++++++++++++ .../Animations/Player/Land.anim.meta | 8 +++ .../Art Assets/Animations/Player/Respawn.anim | 53 +++++++++++++++++++ .../Animations/Player/Respawn.anim.meta | 8 +++ Assets/Prefabs/Player.prefab | 39 +++++++++++++- Assets/Scenes/Official Levels/Level 1.unity | 4 +- .../Character/CharacterController2D.cs | 10 +++- .../Character/CharacterInputController.cs | 47 ++++++++++++++-- Assets/Scripts/Character/CharacterReset.cs | 4 +- Assets/Scripts/ChestController.cs | 8 +-- Assets/Scripts/IntroController.cs | 9 ++-- Assets/Scripts/LevelManager.cs | 2 + 14 files changed, 287 insertions(+), 19 deletions(-) create mode 100644 Assets/Art Assets/Animations/Player/Death.anim create mode 100644 Assets/Art Assets/Animations/Player/Death.anim.meta create mode 100644 Assets/Art Assets/Animations/Player/Land.anim create mode 100644 Assets/Art Assets/Animations/Player/Land.anim.meta create mode 100644 Assets/Art Assets/Animations/Player/Respawn.anim create mode 100644 Assets/Art Assets/Animations/Player/Respawn.anim.meta diff --git a/Assets/Art Assets/Animations/Player/Death.anim b/Assets/Art Assets/Animations/Player/Death.anim new file mode 100644 index 0000000..b45b930 --- /dev/null +++ b/Assets/Art Assets/Animations/Player/Death.anim @@ -0,0 +1,53 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!74 &7400000 +AnimationClip: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: Death + serializedVersion: 6 + m_Legacy: 0 + m_Compressed: 0 + m_UseHighQualityCurve: 1 + m_RotationCurves: [] + m_CompressedRotationCurves: [] + m_EulerCurves: [] + m_PositionCurves: [] + m_ScaleCurves: [] + m_FloatCurves: [] + m_PPtrCurves: [] + m_SampleRate: 60 + m_WrapMode: 0 + m_Bounds: + m_Center: {x: 0, y: 0, z: 0} + m_Extent: {x: 0, y: 0, z: 0} + m_ClipBindingConstant: + genericBindings: [] + pptrCurveMapping: [] + m_AnimationClipSettings: + serializedVersion: 2 + m_AdditiveReferencePoseClip: {fileID: 0} + m_AdditiveReferencePoseTime: 0 + m_StartTime: 0 + m_StopTime: 1 + m_OrientationOffsetY: 0 + m_Level: 0 + m_CycleOffset: 0 + m_HasAdditiveReferencePose: 0 + m_LoopTime: 1 + m_LoopBlend: 0 + m_LoopBlendOrientation: 0 + m_LoopBlendPositionY: 0 + m_LoopBlendPositionXZ: 0 + m_KeepOriginalOrientation: 0 + m_KeepOriginalPositionY: 1 + m_KeepOriginalPositionXZ: 0 + m_HeightFromFeet: 0 + m_Mirror: 0 + m_EditorCurves: [] + m_EulerEditorCurves: [] + m_HasGenericRootTransform: 0 + m_HasMotionFloatCurves: 0 + m_Events: [] diff --git a/Assets/Art Assets/Animations/Player/Death.anim.meta b/Assets/Art Assets/Animations/Player/Death.anim.meta new file mode 100644 index 0000000..92ff6fc --- /dev/null +++ b/Assets/Art Assets/Animations/Player/Death.anim.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: de457e59ca99d9440a3e448860144a88 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 7400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Art Assets/Animations/Player/Land.anim b/Assets/Art Assets/Animations/Player/Land.anim new file mode 100644 index 0000000..00bed87 --- /dev/null +++ b/Assets/Art Assets/Animations/Player/Land.anim @@ -0,0 +1,53 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!74 &7400000 +AnimationClip: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: Land + serializedVersion: 6 + m_Legacy: 0 + m_Compressed: 0 + m_UseHighQualityCurve: 1 + m_RotationCurves: [] + m_CompressedRotationCurves: [] + m_EulerCurves: [] + m_PositionCurves: [] + m_ScaleCurves: [] + m_FloatCurves: [] + m_PPtrCurves: [] + m_SampleRate: 60 + m_WrapMode: 0 + m_Bounds: + m_Center: {x: 0, y: 0, z: 0} + m_Extent: {x: 0, y: 0, z: 0} + m_ClipBindingConstant: + genericBindings: [] + pptrCurveMapping: [] + m_AnimationClipSettings: + serializedVersion: 2 + m_AdditiveReferencePoseClip: {fileID: 0} + m_AdditiveReferencePoseTime: 0 + m_StartTime: 0 + m_StopTime: 1 + m_OrientationOffsetY: 0 + m_Level: 0 + m_CycleOffset: 0 + m_HasAdditiveReferencePose: 0 + m_LoopTime: 1 + m_LoopBlend: 0 + m_LoopBlendOrientation: 0 + m_LoopBlendPositionY: 0 + m_LoopBlendPositionXZ: 0 + m_KeepOriginalOrientation: 0 + m_KeepOriginalPositionY: 1 + m_KeepOriginalPositionXZ: 0 + m_HeightFromFeet: 0 + m_Mirror: 0 + m_EditorCurves: [] + m_EulerEditorCurves: [] + m_HasGenericRootTransform: 0 + m_HasMotionFloatCurves: 0 + m_Events: [] diff --git a/Assets/Art Assets/Animations/Player/Land.anim.meta b/Assets/Art Assets/Animations/Player/Land.anim.meta new file mode 100644 index 0000000..c7b7c96 --- /dev/null +++ b/Assets/Art Assets/Animations/Player/Land.anim.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5a26a046d2fbfac4fb272dfb1eaf4773 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 7400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Art Assets/Animations/Player/Respawn.anim b/Assets/Art Assets/Animations/Player/Respawn.anim new file mode 100644 index 0000000..6a4867b --- /dev/null +++ b/Assets/Art Assets/Animations/Player/Respawn.anim @@ -0,0 +1,53 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!74 &7400000 +AnimationClip: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: Respawn + serializedVersion: 6 + m_Legacy: 0 + m_Compressed: 0 + m_UseHighQualityCurve: 1 + m_RotationCurves: [] + m_CompressedRotationCurves: [] + m_EulerCurves: [] + m_PositionCurves: [] + m_ScaleCurves: [] + m_FloatCurves: [] + m_PPtrCurves: [] + m_SampleRate: 60 + m_WrapMode: 0 + m_Bounds: + m_Center: {x: 0, y: 0, z: 0} + m_Extent: {x: 0, y: 0, z: 0} + m_ClipBindingConstant: + genericBindings: [] + pptrCurveMapping: [] + m_AnimationClipSettings: + serializedVersion: 2 + m_AdditiveReferencePoseClip: {fileID: 0} + m_AdditiveReferencePoseTime: 0 + m_StartTime: 0 + m_StopTime: 1 + m_OrientationOffsetY: 0 + m_Level: 0 + m_CycleOffset: 0 + m_HasAdditiveReferencePose: 0 + m_LoopTime: 1 + m_LoopBlend: 0 + m_LoopBlendOrientation: 0 + m_LoopBlendPositionY: 0 + m_LoopBlendPositionXZ: 0 + m_KeepOriginalOrientation: 0 + m_KeepOriginalPositionY: 1 + m_KeepOriginalPositionXZ: 0 + m_HeightFromFeet: 0 + m_Mirror: 0 + m_EditorCurves: [] + m_EulerEditorCurves: [] + m_HasGenericRootTransform: 0 + m_HasMotionFloatCurves: 0 + m_Events: [] diff --git a/Assets/Art Assets/Animations/Player/Respawn.anim.meta b/Assets/Art Assets/Animations/Player/Respawn.anim.meta new file mode 100644 index 0000000..0c34870 --- /dev/null +++ b/Assets/Art Assets/Animations/Player/Respawn.anim.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ad9e15950709a444795a50d271f72b81 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 7400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/Player.prefab b/Assets/Prefabs/Player.prefab index 9cfe513..57590fd 100644 --- a/Assets/Prefabs/Player.prefab +++ b/Assets/Prefabs/Player.prefab @@ -216,9 +216,36 @@ MonoBehaviour: m_CeilingCheck: {fileID: 4668322656710469013} m_WallCheck: {fileID: 4668322655870949457} m_CrouchDisableCollider: {fileID: 0} + OnJumpEvent: + m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 4668322654876184624} + m_TargetAssemblyTypeName: CharacterInputController, Assembly-CSharp + m_MethodName: OnJumpHappened + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 OnLandEvent: m_PersistentCalls: - m_Calls: [] + m_Calls: + - m_Target: {fileID: 4668322654876184624} + m_TargetAssemblyTypeName: CharacterInputController, Assembly-CSharp + m_MethodName: OnLandHappened + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 OnCrouchEvent: m_PersistentCalls: m_Calls: [] @@ -243,6 +270,15 @@ MonoBehaviour: Variable: {fileID: 11400000, guid: 4644ea58ce4d81544b22caddc5e66c86, type: 2} m_useLocal: 0 m_localValue: 0 + m_isPlayerDead: + Variable: {fileID: 11400000, guid: a1586014535831a4e80b30178ff5ced4, type: 2} + m_useLocal: 0 + m_localValue: 0 + m_isVictory: + Variable: {fileID: 11400000, guid: f1d9845714eccd24bafc361e7f23c030, type: 2} + m_useLocal: 0 + m_localValue: 0 + m_animator: {fileID: 4668322655423991002} m_speed: 2 --- !u!95 &4668322654876184631 Animator: @@ -279,6 +315,7 @@ MonoBehaviour: Variable: {fileID: 11400000, guid: a1586014535831a4e80b30178ff5ced4, type: 2} m_useLocal: 0 m_localValue: 0 + m_playerAnimator: {fileID: 4668322655423991002} --- !u!1 &4668322655423990996 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/Official Levels/Level 1.unity b/Assets/Scenes/Official Levels/Level 1.unity index 0615b86..dabd8bc 100644 --- a/Assets/Scenes/Official Levels/Level 1.unity +++ b/Assets/Scenes/Official Levels/Level 1.unity @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:63c0ed5eaf32aba0f5271388122c2d3cc51a2c0ebe9612ddb48066b1cafcdfd6 -size 171848 +oid sha256:9fb0e1bc7b30c3f3142173c049d247b636f99714d9f89f1645cff5f034778790 +size 173708 diff --git a/Assets/Scripts/Character/CharacterController2D.cs b/Assets/Scripts/Character/CharacterController2D.cs index ad2f0b0..785acf2 100644 --- a/Assets/Scripts/Character/CharacterController2D.cs +++ b/Assets/Scripts/Character/CharacterController2D.cs @@ -14,6 +14,7 @@ public class CharacterController2D : MonoBehaviour [SerializeField] private Transform m_WallCheck; [SerializeField] private Collider2D m_CrouchDisableCollider; // A collider that will be disabled when crouching + const float k_GroundedRadius = .2f; // Radius of the overlap circle to determine if grounded private bool m_Grounded; // Whether or not the player is grounded. private bool m_TouchingWall; @@ -27,6 +28,7 @@ public class CharacterController2D : MonoBehaviour [Header("Events")] [Space] + public UnityEvent OnJumpEvent; public UnityEvent OnLandEvent; [System.Serializable] @@ -150,6 +152,8 @@ public class CharacterController2D : MonoBehaviour // Add a vertical force to the player. m_Grounded = false; m_Rigidbody2D.AddForce(new Vector2(0f, m_JumpForce)); + OnJumpEvent.Invoke(); + // Reset wall jump switch m_LastWallJumpDirection = move > 0 ? Direction.R : Direction.L; @@ -159,14 +163,16 @@ public class CharacterController2D : MonoBehaviour if (m_FacingRight && m_LastWallJumpDirection == Direction.L) { m_Rigidbody2D.AddForce(new Vector2(m_JumpForce * m_WallJumpMultiplier * (m_FacingRight ? 1f : -1f), m_JumpForce * m_WallJumpMultiplier)); + OnJumpEvent.Invoke(); - m_LastWallJumpDirection = Direction.R; + m_LastWallJumpDirection = Direction.R; } else if (!m_FacingRight && m_LastWallJumpDirection == Direction.R) { m_Rigidbody2D.AddForce(new Vector2(m_JumpForce * m_WallJumpMultiplier * (m_FacingRight ? 1f : -1f), m_JumpForce * m_WallJumpMultiplier)); + OnJumpEvent.Invoke(); - m_LastWallJumpDirection = Direction.L; + m_LastWallJumpDirection = Direction.L; } } diff --git a/Assets/Scripts/Character/CharacterInputController.cs b/Assets/Scripts/Character/CharacterInputController.cs index 447e926..941e320 100644 --- a/Assets/Scripts/Character/CharacterInputController.cs +++ b/Assets/Scripts/Character/CharacterInputController.cs @@ -8,7 +8,7 @@ using NaughtyAttributes; public class CharacterInputController : MonoBehaviour { - [SerializeField,Header("References")] + [SerializeField, Header("References")] private CharacterController2D m_characterController; [SerializeField] @@ -17,7 +17,16 @@ public class CharacterInputController : MonoBehaviour [SerializeField] private Reference m_noInputAllowed; - [SerializeField,BoxGroup("Settings")] + [SerializeField] + private Reference m_isPlayerDead; + + [SerializeField] + private Reference m_isVictory; + + [SerializeField] + private Animator m_animator; + + [SerializeField, BoxGroup("Settings")] private float m_speed = 2.0f; [ShowNonSerializedField] @@ -28,6 +37,12 @@ public class CharacterInputController : MonoBehaviour + private void OnEnable() + { + m_isPlayerDead.OnValueChanged += OnDeath; + m_isVictory.OnValueChanged += OnVictory; + } + public void OnMove(InputAction.CallbackContext context) { m_movement = context.ReadValue(); @@ -45,12 +60,38 @@ public class CharacterInputController : MonoBehaviour { m_characterController.Move(m_movement.x * m_speed, false, m_jump); m_playerInput.Value = m_movement.magnitude != 0 || m_jump; + } else { m_characterController.Move(0, false, false); - m_playerInput.Value = false ; + m_playerInput.Value = false; } + m_animator.SetBool("isMoving", m_playerInput); + } + + + public void OnLandHappened() + { + m_animator.SetTrigger("Land"); + } + + public void OnJumpHappened() + { + m_animator.SetTrigger("Land"); + } + public void OnDeath(bool value) + { + if (value) + m_animator.SetTrigger("Death"); + else + m_animator.SetTrigger("Respawn"); + } + + public void OnVictory(bool value) + { + if (value) + m_animator.SetTrigger("Victory"); } diff --git a/Assets/Scripts/Character/CharacterReset.cs b/Assets/Scripts/Character/CharacterReset.cs index ab56992..fa07514 100644 --- a/Assets/Scripts/Character/CharacterReset.cs +++ b/Assets/Scripts/Character/CharacterReset.cs @@ -10,6 +10,7 @@ public class CharacterReset : MonoBehaviour, IResettable Reference m_isPlayerDead; + private Vector3 m_startPosition; private Quaternion m_startRotation; @@ -23,7 +24,7 @@ public class CharacterReset : MonoBehaviour, IResettable public void OnResetEnd() { - + } public IEnumerator OnResetStart(float time) @@ -32,6 +33,7 @@ public class CharacterReset : MonoBehaviour, IResettable transform.rotation = m_startRotation; m_isPlayerDead.Value = false; + yield break; } } diff --git a/Assets/Scripts/ChestController.cs b/Assets/Scripts/ChestController.cs index d03be2f..79df4db 100644 --- a/Assets/Scripts/ChestController.cs +++ b/Assets/Scripts/ChestController.cs @@ -10,9 +10,6 @@ public class ChestController : MonoBehaviour [SerializeField, Header("References")] private Animator m_chestAnimator; - [SerializeField] - private Animator m_playerAnimator; - [SerializeField] private Reference m_freezePlayer; @@ -21,12 +18,9 @@ public class ChestController : MonoBehaviour private void OnTriggerEnter2D(Collider2D collision) { - Animator[] animators = collision.GetComponentsInChildren().Concat(collision.GetComponentsInParent()).ToArray(); - - if (animators.Contains(m_playerAnimator)) + if (collision.CompareTag("Player")) { m_chestAnimator.SetBool("Open", true); - m_playerAnimator.SetTrigger("Victory"); m_freezePlayer.Value = true; m_isVictory.Value = true; } diff --git a/Assets/Scripts/IntroController.cs b/Assets/Scripts/IntroController.cs index 3728d85..f189f44 100644 --- a/Assets/Scripts/IntroController.cs +++ b/Assets/Scripts/IntroController.cs @@ -154,15 +154,18 @@ public class IntroController : MonoBehaviour, IResettable public IEnumerator OnResetStart(float time) { + yield break; + } - yield return new WaitForSeconds(time - gotime); - + private IEnumerator ResetRoutine(float time) + { m_goText.gameObject.SetActive(true); - yield return new WaitForSeconds(gotime); + yield return new WaitForSeconds(time); m_goText.gameObject.SetActive(false); } public void OnResetEnd() { + StartCoroutine(ResetRoutine(gotime)); } } diff --git a/Assets/Scripts/LevelManager.cs b/Assets/Scripts/LevelManager.cs index 78000b1..feb5a66 100644 --- a/Assets/Scripts/LevelManager.cs +++ b/Assets/Scripts/LevelManager.cs @@ -96,6 +96,8 @@ public class LevelManager : MonoBehaviour { m_freezePlayer.Value = true; + yield return new WaitForSeconds(1); + m_timer.Value = m_timeInLevel;