155 lines
4.4 KiB
C#
155 lines
4.4 KiB
C#
using System;
|
|
using Obvious.Soap;
|
|
using SoapCustomVariable;
|
|
using UnityEngine;
|
|
|
|
public class PlayerFishCatchController : MonoBehaviour
|
|
{
|
|
public PlayerProfile PlayerProfile;
|
|
|
|
public FSMVariable PlayerState;
|
|
|
|
public ScriptableEventFishData OnFishCatched;
|
|
|
|
public ScriptableEventFishData OnFishCollect;
|
|
|
|
public ScriptableEventFishData OnFishThrow;
|
|
|
|
public Vector2Variable MouseInput;
|
|
|
|
public ScriptableEventNoParam OnFishBarThrowApply;
|
|
|
|
public ScriptableEventNoParam OnFishBarCollectApply;
|
|
|
|
public FloatVariable Money;
|
|
|
|
public Waga waga;
|
|
|
|
public Vector3 ArmPosition = Vector3.zero;
|
|
|
|
public Vector3 ArmMinVec = Vector3.zero;
|
|
|
|
public Vector3 ArmMaxVec = Vector3.zero;
|
|
|
|
public Vector3 CatchFishAdditiveVec = Vector3.zero;
|
|
|
|
[SerializeField]
|
|
private Transform _HandCatchTarget;
|
|
|
|
[SerializeField]
|
|
private Transform _RigTarget;
|
|
|
|
[SerializeField]
|
|
private Transform _FishTarget;
|
|
|
|
[SerializeField]
|
|
private PlayerIK _PlayerIK;
|
|
|
|
private PlayerFishingGearController _PlayerGear;
|
|
|
|
private Vector3 _RigDefaultPosition;
|
|
|
|
private bool _IsInVehicle;
|
|
|
|
private FishController _FishOnHook;
|
|
|
|
private void Awake()
|
|
{
|
|
_PlayerGear = GetComponent<PlayerFishingGearController>();
|
|
_RigDefaultPosition = _RigTarget.localPosition;
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
PlayerState.OnValueChanged += PlayerStateOnOnValueChanged;
|
|
OnFishCatched.OnRaised += OnFishCatchedOnOnRaised;
|
|
OnFishBarThrowApply.OnRaised += OnFishBarThrowApplyOnOnRaised;
|
|
OnFishBarCollectApply.OnRaised += OnFishBarCollectApplyOnOnRaised;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
PlayerState.OnValueChanged -= PlayerStateOnOnValueChanged;
|
|
OnFishCatched.OnRaised -= OnFishCatchedOnOnRaised;
|
|
OnFishBarThrowApply.OnRaised -= OnFishBarThrowApplyOnOnRaised;
|
|
OnFishBarCollectApply.OnRaised -= OnFishBarCollectApplyOnOnRaised;
|
|
}
|
|
|
|
private void OnFishBarCollectApplyOnOnRaised()
|
|
{
|
|
OnFishCollect.Raise(_FishOnHook.FishData);
|
|
PlayerProfile.AddFish(_FishOnHook.FishData);
|
|
_PlayerGear.EquipedFishingSet.AttachedLure.SetKinematic(value: false);
|
|
_PlayerGear.EquipedFishingSet.UnwindLine(-1000f);
|
|
UnityEngine.Object.Destroy(_FishOnHook.gameObject);
|
|
Money.Value += (float)Math.Round(10f * _FishOnHook.Mass, 2);
|
|
_FishOnHook = null;
|
|
PlayerState.Value = (_IsInVehicle ? State.vehicleFishing : State.idle);
|
|
}
|
|
|
|
private void OnFishBarThrowApplyOnOnRaised()
|
|
{
|
|
OnFishThrow.Raise(_FishOnHook.FishData);
|
|
_PlayerGear.EquipedFishingSet.AttachedLure.SetKinematic(value: false);
|
|
_PlayerGear.EquipedFishingSet.UnwindLine(-1000f);
|
|
_FishOnHook.Throw(base.transform.forward * 15f);
|
|
_FishOnHook = null;
|
|
PlayerState.Value = (_IsInVehicle ? State.vehicleFishing : State.idle);
|
|
}
|
|
|
|
private void PlayerStateOnOnValueChanged(State newState)
|
|
{
|
|
if (PlayerState.PreviousValue == State.collectFish)
|
|
{
|
|
_PlayerIK.SetBipedLeftHandIK(enabled: false, _PlayerGear.EquipedFishingSet.AttachedReel.FingersIKAnchor);
|
|
if ((bool)_PlayerGear.EquipedFishingSet.attachedBobber)
|
|
{
|
|
_PlayerGear.EquipedFishingSet.UnwindLine(-3f);
|
|
_PlayerGear.EquipedFishingSet.attachedBobber.SetDetectCollisionEnabled(enabled: true);
|
|
}
|
|
}
|
|
switch (newState)
|
|
{
|
|
case State.idle:
|
|
_IsInVehicle = false;
|
|
break;
|
|
case State.vehicle:
|
|
case State.vehicleFishing:
|
|
_IsInVehicle = true;
|
|
break;
|
|
case State.collectFish:
|
|
if ((bool)_PlayerGear.EquipedFishingSet.attachedBobber)
|
|
{
|
|
_PlayerGear.EquipedFishingSet.attachedBobber.SetDetectCollisionEnabled(enabled: false);
|
|
}
|
|
_PlayerIK.SetFishingLeftArm(enabled: false);
|
|
_PlayerIK.SetBipedLeftHandIK(enabled: true, _HandCatchTarget);
|
|
_PlayerGear.EquipedFishingSet.HookedFish.CollectFish();
|
|
_PlayerGear.EquipedFishingSet.SetLineLength(0.5f);
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void OnFishCatchedOnOnRaised(FishData fishData)
|
|
{
|
|
PlayerProfile.CheckFishRecord(fishData);
|
|
_FishOnHook = _PlayerGear.EquipedFishingSet.HookedFish;
|
|
PlayerState.Value = State.collectFish;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (PlayerState.Value == State.collectFish)
|
|
{
|
|
Vector2 value = MouseInput.Value;
|
|
value = Vector2.ClampMagnitude(value, 0.1f);
|
|
Vector3 vector = new Vector3(value.x, value.y, 0f);
|
|
vector = (ArmPosition = Vector3.Slerp(ArmPosition, ArmPosition + vector, Time.deltaTime * 10f));
|
|
ArmPosition.x = Mathf.Clamp(vector.x, ArmMinVec.x, ArmMaxVec.x);
|
|
ArmPosition.y = Mathf.Clamp(vector.y, ArmMinVec.y, ArmMaxVec.y);
|
|
ArmPosition.z = Mathf.Clamp(vector.z, ArmMinVec.z, ArmMaxVec.z);
|
|
_RigTarget.localPosition = _RigDefaultPosition + ArmPosition;
|
|
}
|
|
}
|
|
}
|