246 lines
6.8 KiB
C#
246 lines
6.8 KiB
C#
using System;
|
|
using KINEMATION.MagicBlend.Runtime;
|
|
using Obvious.Soap;
|
|
using SoapCustomVariable;
|
|
using UnityEngine;
|
|
|
|
public class PlayerAnimator : MonoBehaviour
|
|
{
|
|
private static readonly int IsSwiming = Animator.StringToHash("Swim");
|
|
|
|
private static readonly int ThrowFar = Animator.StringToHash("ThrowFar");
|
|
|
|
private static readonly int BoatDriving = Animator.StringToHash("BoatDriving");
|
|
|
|
private static readonly int BaitInWater = Animator.StringToHash("BaitInWater");
|
|
|
|
private static readonly int HeldRod = Animator.StringToHash("HeldRod");
|
|
|
|
private static readonly int RodArming = Animator.StringToHash("RodArming");
|
|
|
|
private static readonly int Forward = Animator.StringToHash("Forward");
|
|
|
|
private static readonly int Turn = Animator.StringToHash("Turn");
|
|
|
|
private static readonly int OnGround = Animator.StringToHash("OnGround");
|
|
|
|
private static readonly int RodRight = Animator.StringToHash("rod right");
|
|
|
|
private static readonly int RodForward = Animator.StringToHash("rod forward");
|
|
|
|
private static readonly int PreciseCast = Animator.StringToHash("Precise Cast");
|
|
|
|
private static readonly int PreciseIdle = Animator.StringToHash("Precise Idle");
|
|
|
|
public FloatVariable RotationSpeed;
|
|
|
|
public BoolVariable IsThrowButtonPressed;
|
|
|
|
[SerializeField]
|
|
public Vector2Variable rodPosition;
|
|
|
|
[SerializeField]
|
|
public BoolVariable isGrounded;
|
|
|
|
[SerializeField]
|
|
public FloatVariable currentMoveSpeed;
|
|
|
|
[SerializeField]
|
|
public FSMVariable playerFSMState;
|
|
|
|
[SerializeField]
|
|
public ItemDataVariable currentRod;
|
|
|
|
[SerializeField]
|
|
public ScriptableEventItemData onGearUpdate;
|
|
|
|
[SerializeField]
|
|
public ScriptableEventFishData onFishCatched;
|
|
|
|
[SerializeField]
|
|
public ScriptableEventFishData onFishCollected;
|
|
|
|
[SerializeField]
|
|
public ScriptableEventFishData onFishRelease;
|
|
|
|
private Animator _Animator;
|
|
|
|
private PlayerIK _IK;
|
|
|
|
[SerializeField]
|
|
private PlayerFishingGearController _PlayerEquipment;
|
|
|
|
private MagicBlending _magicBlending;
|
|
|
|
private bool _IsInVehicle;
|
|
|
|
public Action OnBailOpen;
|
|
|
|
private bool _isTorsoLayerEnabled;
|
|
|
|
private void Awake()
|
|
{
|
|
_magicBlending = GetComponent<MagicBlending>();
|
|
_Animator = GetComponent<Animator>();
|
|
_Animator.keepAnimatorStateOnDisable = true;
|
|
_IK = GetComponent<PlayerIK>();
|
|
_PlayerEquipment.OnFishingSetEquiped += OnFishingSetEquiped_OnRaised;
|
|
_PlayerEquipment.OnFishingSetUnequip += OnFishingSetUnequip;
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
playerFSMState.OnValueChanged += PlayerFSMState_OnValueChanged;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
playerFSMState.OnValueChanged -= PlayerFSMState_OnValueChanged;
|
|
}
|
|
|
|
private void OnFishingSetUnequip()
|
|
{
|
|
_isTorsoLayerEnabled = false;
|
|
_IK.SetBipedLeftHandIK(enabled: false, null);
|
|
}
|
|
|
|
private void OnCastLure()
|
|
{
|
|
playerFSMState.Value = State.baitFlies;
|
|
SFXGameManagement.PlaySound("Cast Fishing Rod", base.transform);
|
|
}
|
|
|
|
private void OnBailUnnarm()
|
|
{
|
|
if (IsThrowButtonPressed.Value)
|
|
{
|
|
_Animator.SetBool(ThrowFar, value: true);
|
|
playerFSMState.Value = State.casting;
|
|
OnBailOpen?.Invoke();
|
|
}
|
|
}
|
|
|
|
private void OnFishingSetEquiped_OnRaised(FishingSetController set)
|
|
{
|
|
_isTorsoLayerEnabled = true;
|
|
_IK.SetBipedLeftHandIK(enabled: false, set.AttachedReel.FingersIKAnchor);
|
|
}
|
|
|
|
private void PlayAnimation(string state, string layer)
|
|
{
|
|
_Animator.CrossFade(state, 0.3f, _Animator.GetLayerIndex(layer));
|
|
}
|
|
|
|
public void PlayPreciseCastAnimation()
|
|
{
|
|
_Animator.SetBool(PreciseIdle, value: false);
|
|
_Animator.SetTrigger(PreciseCast);
|
|
}
|
|
|
|
public void SetLayerWeight(string layer, float weight)
|
|
{
|
|
_Animator.SetLayerWeight(_Animator.GetLayerIndex(layer), weight);
|
|
}
|
|
|
|
private void PlayerFSMState_OnValueChanged(State state)
|
|
{
|
|
switch (playerFSMState.PreviousValue)
|
|
{
|
|
case State.vehicle:
|
|
_IsInVehicle = false;
|
|
_Animator.SetBool(BoatDriving, value: false);
|
|
break;
|
|
case State.swiming:
|
|
_Animator.SetBool(IsSwiming, value: false);
|
|
break;
|
|
case State.preciseCastIdle:
|
|
_Animator.SetBool(PreciseIdle, value: false);
|
|
break;
|
|
case State.prepare:
|
|
_Animator.SetBool(RodArming, value: false);
|
|
break;
|
|
case State.casting:
|
|
_Animator.SetBool(ThrowFar, value: false);
|
|
break;
|
|
case State.collectFish:
|
|
_magicBlending.BlendAsset.globalWeight = 0f;
|
|
break;
|
|
}
|
|
switch (state)
|
|
{
|
|
case State.idle:
|
|
case State.move:
|
|
_Animator.SetBool(BaitInWater, value: false);
|
|
_Animator.SetBool(HeldRod, value: false);
|
|
_Animator.SetBool(ThrowFar, value: false);
|
|
_Animator.SetBool(RodArming, value: false);
|
|
break;
|
|
case State.prepare:
|
|
_Animator.SetBool(RodArming, value: true);
|
|
_Animator.SetBool(HeldRod, value: true);
|
|
break;
|
|
case State.fishing:
|
|
_Animator.SetBool(HeldRod, value: true);
|
|
_Animator.SetBool(BaitInWater, value: true);
|
|
break;
|
|
case State.vehicle:
|
|
_Animator.SetBool(BaitInWater, value: false);
|
|
_Animator.SetBool(HeldRod, value: false);
|
|
_Animator.SetBool(ThrowFar, value: false);
|
|
_Animator.SetBool(RodArming, value: false);
|
|
_Animator.SetBool(BoatDriving, value: true);
|
|
_IK.SetBipedLeftHandIK(enabled: true);
|
|
_IsInVehicle = true;
|
|
break;
|
|
case State.vehicleFishing:
|
|
_Animator.SetBool(BaitInWater, value: false);
|
|
_Animator.SetBool(HeldRod, value: false);
|
|
_Animator.SetBool(ThrowFar, value: false);
|
|
_Animator.SetBool(RodArming, value: false);
|
|
_IsInVehicle = true;
|
|
break;
|
|
case State.swiming:
|
|
_Animator.SetBool(IsSwiming, value: true);
|
|
break;
|
|
case State.collectFish:
|
|
_Animator.SetBool(BaitInWater, value: false);
|
|
_IK.SetAimIK(enabled: false);
|
|
_magicBlending.BlendAsset.globalWeight = 1f;
|
|
break;
|
|
case State.preciseCastIdle:
|
|
_Animator.SetBool(PreciseIdle, value: true);
|
|
break;
|
|
case State.casting:
|
|
case State.baitFlies:
|
|
case State.fight:
|
|
case State.fishView:
|
|
case State.throwFish:
|
|
case State.flyModeDebug:
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void LateUpdate()
|
|
{
|
|
if (playerFSMState.Value == State.swiming)
|
|
{
|
|
float value = Mathf.Lerp(_Animator.GetFloat(Forward), currentMoveSpeed.Value / 2.5f, Time.deltaTime * 5f);
|
|
float value2 = Mathf.Lerp(_Animator.GetFloat(Turn), RotationSpeed.Value, Time.deltaTime * 5f);
|
|
_Animator.SetFloat(Forward, Mathf.Clamp01(value));
|
|
_Animator.SetFloat(Turn, Mathf.Clamp(value2, -1f, 1f));
|
|
}
|
|
else
|
|
{
|
|
float value3 = Mathf.Lerp(_Animator.GetFloat(Forward), currentMoveSpeed.Value / 5f, Time.deltaTime * 20f);
|
|
float value4 = Mathf.Lerp(_Animator.GetFloat(Turn), RotationSpeed.Value, Time.deltaTime * 15f);
|
|
_Animator.SetFloat(Forward, Mathf.Clamp01(value3));
|
|
_Animator.SetFloat(Turn, Mathf.Clamp(value4, -1f, 1f));
|
|
}
|
|
_Animator.SetBool(OnGround, _IsInVehicle || isGrounded.Value);
|
|
_Animator.SetFloat(RodRight, rodPosition.Value.x);
|
|
_Animator.SetFloat(RodForward, rodPosition.Value.y);
|
|
float layerWeight = _Animator.GetLayerWeight(_Animator.GetLayerIndex("Torso"));
|
|
SetLayerWeight("Torso", Mathf.MoveTowards(layerWeight, _isTorsoLayerEnabled ? 1f : 0f, Time.deltaTime * 3f));
|
|
}
|
|
}
|