RiftMayhem/Assets/Scripts/CharacterAnimatorController.cs
Pedro Gomes 81f2ac424e Insane update
Abilities:

- area of effect ability with impact event/chain reaction type added
- melee slash timing bugfix
- melee slash VFX added
- blizzard (second mage ability) added
- holy circle (ultimate priest ability) added
- consecration (ultimate knight ability) added
- whirling axes (second barbarian ability) added
- glacial bomb (ultimate mage ability) added
- ice shard (first mage ability) added

Others:

- aoe location snapshot on cast mechanic added
- reduced realtime shadows on rifthunters inn
2024-07-04 21:27:15 +01:00

117 lines
3.2 KiB
C#

using Photon.Pun;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class CharacterAnimatorController : MonoBehaviour
{
Animator anim;
NavMeshAgent agent;
PhotonView photonView;
CharacterAnimatorParent parentController;
bool isCasting;
private void Awake()
{
anim = GetComponent<Animator>();
agent = GetComponentInParent<NavMeshAgent>();
photonView = GetComponentInParent<PhotonView>();
parentController = GetComponentInParent<CharacterAnimatorParent>();
}
// Start is called before the first frame update
void Start()
{
if (!photonView.IsMine)
{
return;
}
}
private void OnEnable()
{
parentController = GetComponentInParent<CharacterAnimatorParent>();
Debug.Log("OnEnable: parentController is " + (parentController != null ? "not null" : "null"));
if (photonView.IsMine)
CastBarHandler.Instance.OnCastingStateChanged.AddListener(UpdateIsCastingState);
}
private void OnDisable()
{
if (photonView.IsMine)
CastBarHandler.Instance.OnCastingStateChanged.RemoveListener(UpdateIsCastingState);
}
// Update is called once per frame
void Update()
{
if (!photonView.IsMine) return;
anim.SetFloat("movementSpeed", agent.velocity.magnitude);
}
private void UpdateIsCastingState(bool isCasting)
{
this.isCasting = isCasting;
if (isCasting)
{
anim.SetFloat("throwingTime", (1 / CastBarHandler.Instance.currentCastTime));
SetTriggerBasedOnAbility(CastBarHandler.Instance.currentAbility.animationType);
if (parentController == null)
{
parentController = GetComponentInParent<CharacterAnimatorParent>();
Debug.Log("OnEnable: parentController is " + (parentController != null ? "not null" : "null"));
}
Debug.Log("NULL: " + parentController);
parentController.SetRemoteTriggerBasedOnAbility((int)CastBarHandler.Instance.currentAbility.animationType);
}
}
public void OnAnimationEvent()
{
if (!photonView.IsMine) return;
Debug.Log("$$melee Animation event");
//if (!isCasting) return;
Debug.Log("$$melee Animation event casting true");
if(CastBarHandler.Instance.currentAbility.animationType == AbilityAnimationType.Melee)
{
CastBarHandler.Instance.ExecuteQueuedCastOnAnimationEvent();
parentController.castingStateController.ResetCastingOnMeleeAnimationEvent();
}
}
public void SetTriggerBasedOnAbility(AbilityAnimationType animationType)
{
switch (animationType)
{
case AbilityAnimationType.Throw:
anim.SetTrigger("throw");
break;
case AbilityAnimationType.Spell:
anim.SetTrigger("cast");
break;
case AbilityAnimationType.Melee:
anim.SetTrigger("melee");
break;
default:
break;
}
}
}
public enum AbilityAnimationType
{
Throw,
Spell,
Melee
}