From d0ba76ee3989572f2bbb1e0f1f849f9742109416 Mon Sep 17 00:00:00 2001 From: cyber-dream Date: Fri, 3 Jun 2022 12:26:41 +0300 Subject: [PATCH] delete obsolete scripts --- ldjam50/Assets/Scripts/Character_obsolete.cs | 248 ------------------ .../Assets/Scripts/Character_obsolete.cs.meta | 11 - ldjam50/Assets/Scripts/State.cs | 74 ------ ldjam50/Assets/Scripts/State.cs.meta | 11 - ldjam50/Assets/Scripts/StateMachine.cs | 51 ---- ldjam50/Assets/Scripts/StateMachine.cs.meta | 11 - ldjam50/Assets/Scripts/States/DuckingState.cs | 83 ------ .../Scripts/States/DuckingState.cs.meta | 11 - .../Assets/Scripts/States/GroundedState.cs | 72 ----- .../Scripts/States/GroundedState.cs.meta | 11 - ldjam50/Assets/Scripts/States/JumpingState.cs | 77 ------ .../Scripts/States/JumpingState.cs.meta | 11 - .../Assets/Scripts/States/StandingState.cs | 73 ------ 13 files changed, 744 deletions(-) delete mode 100644 ldjam50/Assets/Scripts/Character_obsolete.cs delete mode 100644 ldjam50/Assets/Scripts/Character_obsolete.cs.meta delete mode 100644 ldjam50/Assets/Scripts/State.cs delete mode 100644 ldjam50/Assets/Scripts/State.cs.meta delete mode 100644 ldjam50/Assets/Scripts/StateMachine.cs delete mode 100644 ldjam50/Assets/Scripts/StateMachine.cs.meta delete mode 100644 ldjam50/Assets/Scripts/States/DuckingState.cs delete mode 100644 ldjam50/Assets/Scripts/States/DuckingState.cs.meta delete mode 100644 ldjam50/Assets/Scripts/States/GroundedState.cs delete mode 100644 ldjam50/Assets/Scripts/States/GroundedState.cs.meta delete mode 100644 ldjam50/Assets/Scripts/States/JumpingState.cs delete mode 100644 ldjam50/Assets/Scripts/States/JumpingState.cs.meta delete mode 100644 ldjam50/Assets/Scripts/States/StandingState.cs diff --git a/ldjam50/Assets/Scripts/Character_obsolete.cs b/ldjam50/Assets/Scripts/Character_obsolete.cs deleted file mode 100644 index c700c32..0000000 --- a/ldjam50/Assets/Scripts/Character_obsolete.cs +++ /dev/null @@ -1,248 +0,0 @@ -/* - * Copyright (c) 2019 Razeware LLC - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * Notwithstanding the foregoing, you may not use, copy, modify, merge, publish, - * distribute, sublicense, create a derivative work, and/or sell copies of the - * Software in any work that is designed, intended, or marketed for pedagogical or - * instructional purposes related to programming, coding, application development, - * or information technology. Permission for such use, copying, modification, - * merger, publication, distribution, sublicensing, creation of derivative works, - * or sale is expressly withheld. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -using UnityEngine; - -namespace RayWenderlich.Unity.StatePatternInUnity -{ - - [RequireComponent(typeof(BoxCollider2D))] - public class Character : MonoBehaviour - { - #region Variables - - public StateMachine movementSM; - public StandingState standing; - public DuckingState ducking; - public JumpingState jumping; - -#pragma warning disable 0649 - [SerializeField] - private Transform handTransform; - [SerializeField] - private Transform sheathTransform; - [SerializeField] - private Transform shootTransform; - [SerializeField] - private CharacterData data; - [SerializeField] - private LayerMask whatIsGround; - [SerializeField] - private Collider hitBox; - [SerializeField] - private Animator anim; - [SerializeField] - private ParticleSystem shockWave; -#pragma warning restore 0649 - [SerializeField] - private float meleeRestThreshold = 10f; - [SerializeField] - private float diveThreshold = 1f; - [SerializeField] - private float collisionOverlapRadius = 0.1f; - - private GameObject currentWeapon; - private Quaternion currentRotation; - private int horizonalMoveParam = Animator.StringToHash("H_Speed"); - private int verticalMoveParam = Animator.StringToHash("V_Speed"); - private int shootParam = Animator.StringToHash("Shoot"); - private int hardLanding = Animator.StringToHash("HardLand"); - #endregion - - #region Properties - - public float NormalColliderHeight => data.normalColliderHeight; - public float CrouchColliderHeight => data.crouchColliderHeight; - public float DiveForce => data.diveForce; - public float JumpForce => data.jumpForce; - public float MovementSpeed => data.movementSpeed; - public float CrouchSpeed => data.crouchSpeed; - public float RotationSpeed => data.rotationSpeed; - public float CrouchRotationSpeed => data.crouchRotationSpeed; - public GameObject MeleeWeapon => data.meleeWeapon; - public GameObject ShootableWeapon => data.staticShootable; - public float DiveCooldownTimer => data.diveCooldownTimer; - public float CollisionOverlapRadius => collisionOverlapRadius; - public float DiveThreshold => diveThreshold; - public float MeleeRestThreshold => meleeRestThreshold; - public int isMelee => Animator.StringToHash("IsMelee"); - public int crouchParam => Animator.StringToHash("Crouch"); - - public float ColliderSize - { - get => GetComponent().height; - - set - { - GetComponent().height = value; - Vector3 center = GetComponent().center; - center.y = value / 2f; - GetComponent().center = center; - } - } - - #endregion - - #region Methods - - public void Move(float speed, float rotationSpeed) - {/* - Vector3 targetVelocity = speed * transform.forward * Time.deltaTime; - targetVelocity.y = GetComponent().velocity.y; - GetComponent().velocity = targetVelocity; - - GetComponent().angularVelocity = rotationSpeed * Vector3.up * Time.deltaTime; - - if (targetVelocity.magnitude > 0.01f || GetComponent().angularVelocity.magnitude > 0.01f) - { - SoundManager.Instance.PlayFootSteps(Mathf.Abs(speed)); - } - - anim.SetFloat(horizonalMoveParam, GetComponent().angularVelocity.y); - anim.SetFloat(verticalMoveParam, speed * Time.deltaTime);*/ - print(Input.GetAxis("Horizontal")); - print(Input.GetAxis("Vertical")); - } - - public void ResetMoveParams() - { - GetComponent().angularVelocity = Vector3.zero; - anim.SetFloat(horizonalMoveParam, 0f); - anim.SetFloat(verticalMoveParam, 0f); - } - - public void ApplyImpulse(Vector3 force) - { - GetComponent().AddForce(force, ForceMode.Impulse); - } - - public void SetAnimationBool(int param, bool value) - { - anim.SetBool(param, value); - } - - public void TriggerAnimation(int param) - { - anim.SetTrigger(param); - } - - public void Shoot() - { - TriggerAnimation(shootParam); - GameObject shootable = Instantiate(data.shootableObject, shootTransform.position, shootTransform.rotation); - shootable.GetComponent().velocity = shootable.transform.forward * data.bulletInitialSpeed; - SoundManager.Instance.PlaySound(SoundManager.Instance.shoot, true); - } - - public bool CheckCollisionOverlap(Vector3 point) - { - return Physics.OverlapSphere(point, CollisionOverlapRadius, whatIsGround).Length > 0; - } - - public void Equip(GameObject weapon = null) - { - if (weapon != null) - { - currentWeapon = Instantiate(weapon, handTransform.position, handTransform.rotation, handTransform); - } - else - { - ParentCurrentWeapon(handTransform); - } - } - - public void DiveBomb() - { - TriggerAnimation(hardLanding); - SoundManager.Instance.PlaySound(SoundManager.Instance.hardLanding); - shockWave.Play(); - } - - public void SheathWeapon() - { - ParentCurrentWeapon(sheathTransform); - } - - public void Unequip() - { - Destroy(currentWeapon); - } - - public void ActivateHitBox() - { - hitBox.enabled = true; - } - - public void DeactivateHitBox() - { - hitBox.enabled = false; - } - - private void ParentCurrentWeapon(Transform parent) - { - if (currentWeapon.transform.parent == parent) - { - return; - } - - currentWeapon.transform.SetParent(parent); - currentWeapon.transform.localPosition = Vector3.zero; - currentWeapon.transform.localRotation = Quaternion.identity; - } - #endregion - - #region MonoBehaviour Callbacks - - private void Start() - { - movementSM = new StateMachine(); - - standing = new StandingState(this, movementSM); - ducking = new DuckingState(this, movementSM); - jumping = new JumpingState(this, movementSM); - - movementSM.Initialize(standing); - } - - private void Update() - { - movementSM.CurrentState.HandleInput(); - - movementSM.CurrentState.LogicUpdate(); - } - - private void FixedUpdate() - { - movementSM.CurrentState.PhysicsUpdate(); - } - - #endregion - } -} diff --git a/ldjam50/Assets/Scripts/Character_obsolete.cs.meta b/ldjam50/Assets/Scripts/Character_obsolete.cs.meta deleted file mode 100644 index abb70a2..0000000 --- a/ldjam50/Assets/Scripts/Character_obsolete.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 1806a6cdb08623a428a4c40597e024b6 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ldjam50/Assets/Scripts/State.cs b/ldjam50/Assets/Scripts/State.cs deleted file mode 100644 index 7ecc213..0000000 --- a/ldjam50/Assets/Scripts/State.cs +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2019 Razeware LLC - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * Notwithstanding the foregoing, you may not use, copy, modify, merge, publish, - * distribute, sublicense, create a derivative work, and/or sell copies of the - * Software in any work that is designed, intended, or marketed for pedagogical or - * instructional purposes related to programming, coding, application development, - * or information technology. Permission for such use, copying, modification, - * merger, publication, distribution, sublicensing, creation of derivative works, - * or sale is expressly withheld. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -namespace RayWenderlich.Unity.StatePatternInUnity -{ - public abstract class State - { - protected Character character; - protected StateMachine stateMachine; - - protected State(Character character, StateMachine stateMachine) - { - this.character = character; - this.stateMachine = stateMachine; - } - - public virtual void Enter() - { - DisplayOnUI(UIManager.Alignment.Left); - } - - public virtual void HandleInput() - { - - } - - public virtual void LogicUpdate() - { - - } - - public virtual void PhysicsUpdate() - { - - } - - public virtual void Exit() - { - - } - - protected void DisplayOnUI(UIManager.Alignment alignment) - { - UIManager.Instance.Display(this, alignment); - } - } -} diff --git a/ldjam50/Assets/Scripts/State.cs.meta b/ldjam50/Assets/Scripts/State.cs.meta deleted file mode 100644 index 273762a..0000000 --- a/ldjam50/Assets/Scripts/State.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 743956073ee5c1f4a964111017dcc3dc -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ldjam50/Assets/Scripts/StateMachine.cs b/ldjam50/Assets/Scripts/StateMachine.cs deleted file mode 100644 index 6138cc8..0000000 --- a/ldjam50/Assets/Scripts/StateMachine.cs +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2019 Razeware LLC - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * Notwithstanding the foregoing, you may not use, copy, modify, merge, publish, - * distribute, sublicense, create a derivative work, and/or sell copies of the - * Software in any work that is designed, intended, or marketed for pedagogical or - * instructional purposes related to programming, coding, application development, - * or information technology. Permission for such use, copying, modification, - * merger, publication, distribution, sublicensing, creation of derivative works, - * or sale is expressly withheld. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -namespace RayWenderlich.Unity.StatePatternInUnity -{ - public class StateMachine - { - public State CurrentState { get; private set; } - - public void Initialize(State startingState) - { - CurrentState = startingState; - startingState.Enter(); - } - - public void ChangeState(State newState) - { - CurrentState.Exit(); - - CurrentState = newState; - newState.Enter(); - } - } -} diff --git a/ldjam50/Assets/Scripts/StateMachine.cs.meta b/ldjam50/Assets/Scripts/StateMachine.cs.meta deleted file mode 100644 index 42c2be5..0000000 --- a/ldjam50/Assets/Scripts/StateMachine.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 33f81286f0d29bc49985b946e8e4fccd -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ldjam50/Assets/Scripts/States/DuckingState.cs b/ldjam50/Assets/Scripts/States/DuckingState.cs deleted file mode 100644 index 15879ae..0000000 --- a/ldjam50/Assets/Scripts/States/DuckingState.cs +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2019 Razeware LLC - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * Notwithstanding the foregoing, you may not use, copy, modify, merge, publish, - * distribute, sublicense, create a derivative work, and/or sell copies of the - * Software in any work that is designed, intended, or marketed for pedagogical or - * instructional purposes related to programming, coding, application development, - * or information technology. Permission for such use, copying, modification, - * merger, publication, distribution, sublicensing, creation of derivative works, - * or sale is expressly withheld. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -using UnityEngine; - -namespace RayWenderlich.Unity.StatePatternInUnity -{ - public class DuckingState : GroundedState - { - private bool belowCeiling; - private bool crouchHeld; - - public DuckingState(Character character, StateMachine stateMachine) : base(character, stateMachine) - { - } - - public override void Enter() - { - base.Enter(); - character.SetAnimationBool(character.crouchParam, true); - speed = character.CrouchSpeed; - rotationSpeed = character.CrouchRotationSpeed; - character.ColliderSize = character.CrouchColliderHeight; - belowCeiling = false; - } - - public override void Exit() - { - base.Exit(); - character.SetAnimationBool(character.crouchParam, false); - character.ColliderSize = character.NormalColliderHeight; - } - - public override void HandleInput() - { - base.HandleInput(); - crouchHeld = Input.GetButton("Fire3"); - } - - public override void LogicUpdate() - { - base.LogicUpdate(); - if (!(crouchHeld || belowCeiling)) - { - stateMachine.ChangeState(character.standing); - } - } - - public override void PhysicsUpdate() - { - base.PhysicsUpdate(); - belowCeiling = character.CheckCollisionOverlap(character.transform.position + - Vector3.up * character.NormalColliderHeight); - } - } -} diff --git a/ldjam50/Assets/Scripts/States/DuckingState.cs.meta b/ldjam50/Assets/Scripts/States/DuckingState.cs.meta deleted file mode 100644 index f5276aa..0000000 --- a/ldjam50/Assets/Scripts/States/DuckingState.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 3386c88cab45c734ea00751e5eb343e1 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ldjam50/Assets/Scripts/States/GroundedState.cs b/ldjam50/Assets/Scripts/States/GroundedState.cs deleted file mode 100644 index acca39b..0000000 --- a/ldjam50/Assets/Scripts/States/GroundedState.cs +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2019 Razeware LLC - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * Notwithstanding the foregoing, you may not use, copy, modify, merge, publish, - * distribute, sublicense, create a derivative work, and/or sell copies of the - * Software in any work that is designed, intended, or marketed for pedagogical or - * instructional purposes related to programming, coding, application development, - * or information technology. Permission for such use, copying, modification, - * merger, publication, distribution, sublicensing, creation of derivative works, - * or sale is expressly withheld. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -using UnityEngine; - -namespace RayWenderlich.Unity.StatePatternInUnity -{ - public class GroundedState : State - { - protected float speed; - protected float rotationSpeed; - - private float horizontalInput; - private float verticalInput; - - public GroundedState(Character character, StateMachine stateMachine) : base(character, stateMachine) - { - } - - public override void Enter() - { - base.Enter(); - horizontalInput = verticalInput = 0.0f; - } - - public override void Exit() - { - base.Exit(); - character.ResetMoveParams(); - } - - public override void HandleInput() - { - base.HandleInput(); - verticalInput = Input.GetAxis("Vertical"); - horizontalInput = Input.GetAxis("Horizontal"); - } - - public override void PhysicsUpdate() - { - base.PhysicsUpdate(); - character.Move(verticalInput * speed, horizontalInput * rotationSpeed); - } - } -} \ No newline at end of file diff --git a/ldjam50/Assets/Scripts/States/GroundedState.cs.meta b/ldjam50/Assets/Scripts/States/GroundedState.cs.meta deleted file mode 100644 index 25a754c..0000000 --- a/ldjam50/Assets/Scripts/States/GroundedState.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: b2aff903c5b48cc4ab9582ecc9e369c3 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ldjam50/Assets/Scripts/States/JumpingState.cs b/ldjam50/Assets/Scripts/States/JumpingState.cs deleted file mode 100644 index 0d6c67e..0000000 --- a/ldjam50/Assets/Scripts/States/JumpingState.cs +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2019 Razeware LLC - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * Notwithstanding the foregoing, you may not use, copy, modify, merge, publish, - * distribute, sublicense, create a derivative work, and/or sell copies of the - * Software in any work that is designed, intended, or marketed for pedagogical or - * instructional purposes related to programming, coding, application development, - * or information technology. Permission for such use, copying, modification, - * merger, publication, distribution, sublicensing, creation of derivative works, - * or sale is expressly withheld. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -using UnityEngine; - -namespace RayWenderlich.Unity.StatePatternInUnity -{ - public class JumpingState : State - { - private bool grounded; - private int jumpParam = Animator.StringToHash("Jump"); - private int landParam = Animator.StringToHash("Land"); - - public JumpingState(Character character, StateMachine stateMachine) : base(character, stateMachine) - { - } - - public override void Enter() - { - base.Enter(); - SoundManager.Instance.PlaySound(SoundManager.Instance.jumpSounds); - grounded = false; - Jump(); - } - - public override void LogicUpdate() - { - base.LogicUpdate(); - if (grounded) - { - character.TriggerAnimation(landParam); - SoundManager.Instance.PlaySound(SoundManager.Instance.landing); - stateMachine.ChangeState(character.standing); - } - } - - public override void PhysicsUpdate() - { - base.PhysicsUpdate(); - grounded = character.CheckCollisionOverlap(character.transform.position); - } - - private void Jump() - { - character.transform.Translate(Vector3.up * (character.CollisionOverlapRadius + 0.1f)); - character.ApplyImpulse(Vector3.up * character.JumpForce); - character.TriggerAnimation(jumpParam); - } - } -} diff --git a/ldjam50/Assets/Scripts/States/JumpingState.cs.meta b/ldjam50/Assets/Scripts/States/JumpingState.cs.meta deleted file mode 100644 index f42f7c1..0000000 --- a/ldjam50/Assets/Scripts/States/JumpingState.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 6656e8a8e13da214da9fccdf8220a037 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ldjam50/Assets/Scripts/States/StandingState.cs b/ldjam50/Assets/Scripts/States/StandingState.cs deleted file mode 100644 index 315b309..0000000 --- a/ldjam50/Assets/Scripts/States/StandingState.cs +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2019 Razeware LLC - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * Notwithstanding the foregoing, you may not use, copy, modify, merge, publish, - * distribute, sublicense, create a derivative work, and/or sell copies of the - * Software in any work that is designed, intended, or marketed for pedagogical or - * instructional purposes related to programming, coding, application development, - * or information technology. Permission for such use, copying, modification, - * merger, publication, distribution, sublicensing, creation of derivative works, - * or sale is expressly withheld. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -using UnityEngine; - -namespace RayWenderlich.Unity.StatePatternInUnity -{ - public class StandingState : GroundedState - { - private bool jump; - private bool crouch; - - public StandingState(Character character, StateMachine stateMachine) : base(character, stateMachine) - { - } - - public override void Enter() - { - base.Enter(); - speed = character.MovementSpeed; - rotationSpeed = character.RotationSpeed; - crouch = false; - jump = false; - } - - public override void HandleInput() - { - base.HandleInput(); - crouch = Input.GetButtonDown("Fire3"); - jump = Input.GetButtonDown("Jump"); - } - - public override void LogicUpdate() - { - base.LogicUpdate(); - if (crouch) - { - stateMachine.ChangeState(character.ducking); - } - else if (jump) - { - stateMachine.ChangeState(character.jumping); - } - } - } -}