delete obsolete scripts
This commit is contained in:
parent
a27511b6f5
commit
d0ba76ee39
@ -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<CapsuleCollider>().height;
|
|
||||||
|
|
||||||
set
|
|
||||||
{
|
|
||||||
GetComponent<CapsuleCollider>().height = value;
|
|
||||||
Vector3 center = GetComponent<CapsuleCollider>().center;
|
|
||||||
center.y = value / 2f;
|
|
||||||
GetComponent<CapsuleCollider>().center = center;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Methods
|
|
||||||
|
|
||||||
public void Move(float speed, float rotationSpeed)
|
|
||||||
{/*
|
|
||||||
Vector3 targetVelocity = speed * transform.forward * Time.deltaTime;
|
|
||||||
targetVelocity.y = GetComponent<Rigidbody>().velocity.y;
|
|
||||||
GetComponent<Rigidbody>().velocity = targetVelocity;
|
|
||||||
|
|
||||||
GetComponent<Rigidbody>().angularVelocity = rotationSpeed * Vector3.up * Time.deltaTime;
|
|
||||||
|
|
||||||
if (targetVelocity.magnitude > 0.01f || GetComponent<Rigidbody>().angularVelocity.magnitude > 0.01f)
|
|
||||||
{
|
|
||||||
SoundManager.Instance.PlayFootSteps(Mathf.Abs(speed));
|
|
||||||
}
|
|
||||||
|
|
||||||
anim.SetFloat(horizonalMoveParam, GetComponent<Rigidbody>().angularVelocity.y);
|
|
||||||
anim.SetFloat(verticalMoveParam, speed * Time.deltaTime);*/
|
|
||||||
print(Input.GetAxis("Horizontal"));
|
|
||||||
print(Input.GetAxis("Vertical"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ResetMoveParams()
|
|
||||||
{
|
|
||||||
GetComponent<Rigidbody>().angularVelocity = Vector3.zero;
|
|
||||||
anim.SetFloat(horizonalMoveParam, 0f);
|
|
||||||
anim.SetFloat(verticalMoveParam, 0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ApplyImpulse(Vector3 force)
|
|
||||||
{
|
|
||||||
GetComponent<Rigidbody>().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<Rigidbody>().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
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 1806a6cdb08623a428a4c40597e024b6
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 743956073ee5c1f4a964111017dcc3dc
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 33f81286f0d29bc49985b946e8e4fccd
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 3386c88cab45c734ea00751e5eb343e1
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: b2aff903c5b48cc4ab9582ecc9e369c3
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 6656e8a8e13da214da9fccdf8220a037
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user