207 lines
5.1 KiB
C#
207 lines
5.1 KiB
C#
using DG.Tweening;
|
|
using Obvious.Soap;
|
|
using RootMotion.FinalIK;
|
|
using SoapCustomVariable;
|
|
using UnityEngine;
|
|
|
|
namespace UFS3.Old
|
|
{
|
|
public class PlayerAnimatorController : MonoBehaviourExtended
|
|
{
|
|
[SerializeField]
|
|
private Vector3Variable rotateVector;
|
|
|
|
[SerializeField]
|
|
private Vector2Variable rodPosition;
|
|
|
|
[SerializeField]
|
|
private BoolVariable isGrounded;
|
|
|
|
[SerializeField]
|
|
private FloatVariable currentMoveSpeed;
|
|
|
|
[SerializeField]
|
|
private BoolVariable isBailOpen;
|
|
|
|
[SerializeField]
|
|
private float mouseSensivity = 3f;
|
|
|
|
[SerializeField]
|
|
private FSMVariable playerFSMState;
|
|
|
|
[SerializeField]
|
|
private ItemDataVariable currentRod;
|
|
|
|
[SerializeField]
|
|
private ScriptableEventItemData onGearUpdate;
|
|
|
|
[SerializeField]
|
|
private ScriptableEventFishData onFishCatched;
|
|
|
|
[SerializeField]
|
|
private ScriptableEventFishData onFishCollected;
|
|
|
|
[SerializeField]
|
|
private ScriptableEventFishData onFishRelease;
|
|
|
|
[OwnComponent(0)]
|
|
private Animator animator;
|
|
|
|
[OwnComponent(0)]
|
|
private FullBodyBipedIK fullBodyIK;
|
|
|
|
[OwnComponent(0)]
|
|
private BipedIK bipedIK;
|
|
|
|
[OwnComponent(0)]
|
|
private LookAtIK lookAtIK;
|
|
|
|
[OwnComponent(0)]
|
|
private AimIK aimIK;
|
|
|
|
[SerializeField]
|
|
private Transform fishCatchTarget;
|
|
|
|
private Transform previousLeftHandTarget;
|
|
|
|
private void OnEnable()
|
|
{
|
|
playerFSMState.OnValueChanged += PlayerFSMState_OnValueChanged;
|
|
isBailOpen.OnValueChanged += IsBailOpen_OnValueChanged;
|
|
currentRod.OnValueChanged += CurrentRod_OnValueChanged;
|
|
onGearUpdate.OnRaised += OnGearUpdate_OnRaised;
|
|
onFishCatched.OnRaised += OnFishCatched_OnRaised;
|
|
onFishCollected.OnRaised += OnFishCollected_OnRaised;
|
|
onFishRelease.OnRaised += OnFishRelease_OnRaised;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
playerFSMState.OnValueChanged -= PlayerFSMState_OnValueChanged;
|
|
isBailOpen.OnValueChanged -= IsBailOpen_OnValueChanged;
|
|
currentRod.OnValueChanged -= CurrentRod_OnValueChanged;
|
|
onGearUpdate.OnRaised -= OnGearUpdate_OnRaised;
|
|
onFishCatched.OnRaised -= OnFishCatched_OnRaised;
|
|
onFishCollected.OnRaised -= OnFishCollected_OnRaised;
|
|
onFishRelease.OnRaised -= OnFishRelease_OnRaised;
|
|
}
|
|
|
|
private void OnFishRelease_OnRaised(FishData obj)
|
|
{
|
|
bipedIK.solvers.leftHand.target = previousLeftHandTarget;
|
|
}
|
|
|
|
private void OnFishCollected_OnRaised(FishData obj)
|
|
{
|
|
bipedIK.solvers.leftHand.target = previousLeftHandTarget;
|
|
}
|
|
|
|
private void OnFishCatched_OnRaised(FishData obj)
|
|
{
|
|
if (previousLeftHandTarget != fishCatchTarget.transform)
|
|
{
|
|
previousLeftHandTarget = bipedIK.solvers.leftHand.target;
|
|
bipedIK.solvers.leftHand.target = fishCatchTarget.transform;
|
|
}
|
|
}
|
|
|
|
private void OnGearUpdate_OnRaised(BaseItemData obj)
|
|
{
|
|
if (obj != null)
|
|
{
|
|
fullBodyIK.enabled = true;
|
|
aimIK.enabled = true;
|
|
bipedIK.enabled = true;
|
|
}
|
|
else
|
|
{
|
|
fullBodyIK.enabled = false;
|
|
aimIK.enabled = false;
|
|
bipedIK.enabled = false;
|
|
}
|
|
}
|
|
|
|
private void CurrentRod_OnValueChanged(BaseItemData item)
|
|
{
|
|
if (item != null)
|
|
{
|
|
SetLayerWeight("R Arm", 1f);
|
|
}
|
|
else
|
|
{
|
|
SetLayerWeight("R Arm", 0f);
|
|
}
|
|
}
|
|
|
|
private void IsBailOpen_OnValueChanged(bool isOpen)
|
|
{
|
|
if (playerFSMState.Value == State.prepare)
|
|
{
|
|
string state = (isOpen ? "Hands" : "Idle");
|
|
PlayAnimation(state, "R Arm");
|
|
}
|
|
}
|
|
|
|
private void PlayAnimation(string state, string layer)
|
|
{
|
|
animator.CrossFade(state, 0.3f, animator.GetLayerIndex(layer));
|
|
}
|
|
|
|
private void SetLayerWeight(string layer, float weight)
|
|
{
|
|
animator.SetLayerWeight(animator.GetLayerIndex(layer), weight);
|
|
}
|
|
|
|
private void PlayerFSMState_OnValueChanged(State state)
|
|
{
|
|
switch (state)
|
|
{
|
|
case State.prepare:
|
|
case State.casting:
|
|
case State.fishing:
|
|
case State.fight:
|
|
return;
|
|
}
|
|
PlayAnimation("Idle", "R Arm");
|
|
}
|
|
|
|
private void DoLeftHandIK(bool enabled)
|
|
{
|
|
IKEffector leftHand = fullBodyIK.solver.leftHandEffector;
|
|
IKMappingLimb leftHandMapping = fullBodyIK.solver.leftArmMapping;
|
|
IKEffector leftShoulder = fullBodyIK.solver.leftShoulderEffector;
|
|
float duration = 0.15f;
|
|
DOTween.To(() => leftHand.positionWeight, delegate(float x)
|
|
{
|
|
leftHand.positionWeight = x;
|
|
}, enabled ? 1f : 0f, duration);
|
|
DOTween.To(() => leftHandMapping.weight, delegate(float x)
|
|
{
|
|
leftHandMapping.weight = x;
|
|
}, enabled ? 1f : 0f, duration);
|
|
DOTween.To(() => leftShoulder.positionWeight, delegate(float x)
|
|
{
|
|
leftShoulder.positionWeight = x;
|
|
}, enabled ? 0.081f : 0f, duration);
|
|
}
|
|
|
|
private void LateUpdate()
|
|
{
|
|
float value = Mathf.Lerp(animator.GetFloat("Forward"), currentMoveSpeed.Value / 5f, Time.deltaTime * 25f);
|
|
animator.SetFloat("Forward", Mathf.Clamp01(value));
|
|
float target = 0f;
|
|
if (Mathf.Abs(rotateVector.Value.y) > 0.4f)
|
|
{
|
|
target = Mathf.Clamp(rotateVector.Value.y / 2f, -1f, 1f);
|
|
}
|
|
float value2 = Mathf.MoveTowards(animator.GetFloat("Turn"), target, Time.deltaTime * 2f);
|
|
animator.SetFloat("Turn", value2);
|
|
animator.SetBool("OnGround", isGrounded);
|
|
animator.SetFloat("RodRight", rodPosition.Value.x);
|
|
animator.SetFloat("RodFront", rodPosition.Value.y);
|
|
aimIK.UpdateSolverExternal();
|
|
fullBodyIK.UpdateSolverExternal();
|
|
}
|
|
}
|
|
}
|