Files
beyond/Assets/Scripts/InvectorDerivatives/bThirdPersonController.cs

215 lines
5.9 KiB
C#

using System.Collections;
using System.Collections.Generic;
using Invector;
using Invector.vCharacterController;
using Invector.vEventSystems;
using UnityEngine;
namespace Beyond
{
public class bThirdPersonController : vThirdPersonController
{
//public bool triggerDieBehaviour = false;
protected bool m_isDashing;
protected bool m_GodMode = false;
public bool m_ignoreTriggers = true;
public bool GodMode
{
get => m_GodMode;
set
{
m_GodMode = value;
isImmortal = m_GodMode;
}
}
public bool IsDashingOrRolling()
{
return m_isDashing || isRolling;
}
protected override void Start()
{
base.Start();
//var receiver = GetComponent<vAnimatorEventReceiver>();
//var ev = new vAnimatorEvent();
// ev.
}
public void OnEvadeStart()
{
if (m_GodMode)
return;
isImmortal = true;
}
public void OnEvadeEnd()
{
if (m_GodMode)
return;
isImmortal = false;
}
public override void ActionsControl()
{
base.ActionsControl();
m_isDashing = IsAnimatorTag("IsDashing");
}
public override void Roll()
{
OnRoll.Invoke();
isRolling = true;
animator.CrossFadeInFixedTime("Roll", rollTransition, baseLayer);
ReduceStamina(rollStamina, false);
currentStaminaRecoveryDelay = 2f;
}
public virtual void Dash()
{
// OnRoll.Invoke();
// isRolling = true;
animator.CrossFadeInFixedTime("Dash", rollTransition, baseLayer);
ReduceStamina(rollStamina, false);
currentStaminaRecoveryDelay = 2f;
}
protected override void DeadAnimation()
{
if (!isDead)
{
return;
}
if (!triggerDieBehaviour)
{
triggerDieBehaviour = true;
DeathBehaviour();
}
// death by animation
if (deathBy == DeathBy.Animation)
{
int deadLayer = 0;
var info = animatorStateInfos.GetStateInfoUsingTag("Dead");
if (info != null)
{
if (!animator.IsInTransition(deadLayer) && info.normalizedTime >= 0.99f && groundDistance <= 0.15f)
{
RemoveComponents();
}
}
}
// death by animation & ragdoll after a time
else if (deathBy == DeathBy.AnimationWithRagdoll)
{
int deadLayer = 0;
var info = animatorStateInfos.GetStateInfoUsingTag("Dead");
if (info != null)
{
if (!animator.IsInTransition(deadLayer) && info.normalizedTime >= 0.8f)
{
onActiveRagdoll.Invoke(null);
}
}
}
// death by ragdoll
else if (deathBy == DeathBy.Ragdoll)
{
onActiveRagdoll.Invoke(null);
}
}
public void RemoveAnimatorTags()
{
animatorStateInfos.stateInfos.vToList().ForEach(infos => infos.tags.Clear());
}
public override void ControlAnimatorRootMotion()
{
if (!this.enabled)
{
return;
}
if (isRolling)
{
RollBehavior();
return;
}
if (customAction || lockAnimMovement)
{
StopCharacterWithLerp();
transform.position = animator.rootPosition;
transform.rotation = animator.rootRotation;
}
else if (IsAnimatorTag("Attack"))
{
StopCharacterWithLerp();
transform.position = animator.rootPosition;
}
// commented for test
//else if (inputSmooth.magnitude == 0 && isGrounded && !isSliding)
//{
// if (!ignoreAnimatorMovement)
// {
// animator.ApplyBuiltinRootMotion();
// transform.position = animator.rootPosition;
// transform.rotation = animator.rootRotation;
// }
//}
if (useRootMotion)
{
MoveCharacter(moveDirection);
}
}
protected override void OnTriggerEnter(Collider other)
{
if (!m_ignoreTriggers)
onActionEnter.Invoke(other);
}
/// <summary>
/// Call this in OnTriggerEnter or OnTriggerStay to check if enter in triggerActions
/// </summary>
/// <param name="other">collider trigger</param>
protected override void OnTriggerStay(Collider other)
{
try
{
CheckForAutoCrouch(other);
}
catch (UnityException e)
{
Debug.LogWarning(e.Message);
}
if (!m_ignoreTriggers)
base.OnTriggerStay(other);
}
/// <summary>
/// Call this in OnTriggerExit to check if exit of triggerActions
/// </summary>
/// <param name="other"></param>
protected override void OnTriggerExit(Collider other)
{
AutoCrouchExit(other);
if (!m_ignoreTriggers)
base.OnTriggerExit(other);
}
//animation event handling
void DrawWeaponLowLeft() { }
}
}