首次提交
This commit is contained in:
93
Assets/Scripts/Fishing/Player/FPlayer.Input.cs
Normal file
93
Assets/Scripts/Fishing/Player/FPlayer.Input.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
using NBC;
|
||||
using NBF.Utils;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public partial class FPlayer
|
||||
{
|
||||
#region Input
|
||||
|
||||
private void AddInputEvent()
|
||||
{
|
||||
InputManager.OnPlayerPerformed += OnPlayerCanceled;
|
||||
InputManager.OnPlayerPerformed += OnPlayerPerformed;
|
||||
|
||||
InputManager.OnPlayerValueCanceled += OnPlayerValueCanceled;
|
||||
InputManager.OnPlayerValuePerformed += OnPlayerValuePerformed;
|
||||
}
|
||||
|
||||
private void RemoveInputEvent()
|
||||
{
|
||||
InputManager.OnPlayerPerformed += OnPlayerCanceled;
|
||||
InputManager.OnPlayerPerformed += OnPlayerPerformed;
|
||||
|
||||
InputManager.OnPlayerValueCanceled += OnPlayerValueCanceled;
|
||||
InputManager.OnPlayerValuePerformed += OnPlayerValuePerformed;
|
||||
}
|
||||
|
||||
private void OnPlayerPerformed(string action)
|
||||
{
|
||||
if (action == InputDef.Player.Run)
|
||||
{
|
||||
Data.Run = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPlayerCanceled(string action)
|
||||
{
|
||||
if (action == InputDef.Player.Run)
|
||||
{
|
||||
Data.Run = false;
|
||||
}
|
||||
else if (action == InputDef.Player.ToBag)
|
||||
{
|
||||
//取消手持物品
|
||||
Log.Info($"取消手持物品");
|
||||
Game.Instance.StartCoroutine(UnUseItem());
|
||||
}
|
||||
else if (action.StartsWith(InputDef.Player.QuickStarts))
|
||||
{
|
||||
var index = int.Parse(action.Replace(InputDef.Player.QuickStarts, string.Empty));
|
||||
Log.Info($"快速使用===={index}");
|
||||
var item = RoleModel.Instance.GetSlotItem(index - 1);
|
||||
if (item != null)
|
||||
{
|
||||
Game.Instance.StartCoroutine(UseItem(item));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPlayerValueCanceled(InputAction.CallbackContext context)
|
||||
{
|
||||
var actionName = context.action.name;
|
||||
if (actionName == InputDef.Player.Move)
|
||||
{
|
||||
// var v2 = context.ReadValue<Vector2>();
|
||||
Data.MoveInput = Vector2.zero;
|
||||
// SendMoveMessage(v2, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPlayerValuePerformed(InputAction.CallbackContext context)
|
||||
{
|
||||
// var mapUnit = Parent as MapUnit;
|
||||
// Log.Info($"OnPlayerValuePerformed IsSelf={mapUnit.IsSelf()} id={mapUnit.Id}");
|
||||
var actionName = context.action.name;
|
||||
if (actionName == InputDef.Player.Move)
|
||||
{
|
||||
var v2 = context.ReadValue<Vector2>();
|
||||
Data.MoveInput = v2;
|
||||
// SendMoveMessage(v2, false);
|
||||
}
|
||||
else if (actionName == InputDef.Player.Look)
|
||||
{
|
||||
var v2 = context.ReadValue<Vector2>();
|
||||
// UpdatePlayerRotation(v2);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing/Player/FPlayer.Input.cs.meta
Normal file
3
Assets/Scripts/Fishing/Player/FPlayer.Input.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ea2c2e2d4b4344f0bc9d58ba0aeec6fd
|
||||
timeCreated: 1766505279
|
||||
146
Assets/Scripts/Fishing/Player/FPlayer.Move.cs
Normal file
146
Assets/Scripts/Fishing/Player/FPlayer.Move.cs
Normal file
@@ -0,0 +1,146 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public partial class FPlayer
|
||||
{
|
||||
#region Move
|
||||
|
||||
private Quaternion lastRotation;
|
||||
|
||||
private void UpdateMove()
|
||||
{
|
||||
UpdateGrounded();
|
||||
UpdateWater();
|
||||
ProcessMoveStates();
|
||||
UpdateLookInput();
|
||||
}
|
||||
|
||||
private void UpdateGrounded()
|
||||
{
|
||||
Data.IsGrounded = FirstPerson.IsGrounded();
|
||||
Data.Speed = FirstPerson.velocity.magnitude;
|
||||
|
||||
Quaternion rotation = FirstPerson.transform.rotation;
|
||||
|
||||
// 计算当前帧与上一帧的旋转差异
|
||||
Quaternion rotationDelta = rotation * Quaternion.Inverse(lastRotation);
|
||||
|
||||
// 将四元数转换为角度轴表示
|
||||
rotationDelta.ToAngleAxis(out float angle, out Vector3 axis);
|
||||
|
||||
// 确保角度在0-360范围内
|
||||
if (angle > 180f) angle -= 360f;
|
||||
|
||||
// 获取Y轴旋转分量(归一化处理)
|
||||
float yRotation = 0f;
|
||||
if (Mathf.Abs(angle) > 0.001f && Mathf.Abs(axis.y) > 0.1f)
|
||||
{
|
||||
// 计算Y轴方向的旋转角度(考虑旋转轴方向)
|
||||
yRotation = angle * Mathf.Sign(axis.y);
|
||||
}
|
||||
|
||||
float maxTurnSpeed = 180f; // 度/秒
|
||||
// 转换为角速度并归一化到[-1, 1]
|
||||
float angularSpeed = yRotation / Time.deltaTime;
|
||||
float turnValue = Mathf.Clamp(angularSpeed / maxTurnSpeed, -1f, 1f);
|
||||
|
||||
|
||||
Data.RotationSpeed = turnValue;
|
||||
|
||||
lastRotation = rotation;
|
||||
}
|
||||
|
||||
private void UpdateWater()
|
||||
{
|
||||
// SceneSettings.Instance.Water.w
|
||||
}
|
||||
|
||||
private void ProcessMoveStates()
|
||||
{
|
||||
// if (CameraView.Value == CameraViewType.TPP)
|
||||
// {
|
||||
// float num = (IsRunPressed.Value ? MovementSpeed.Value : (MovementSpeed.Value * 0.5f));
|
||||
// num = (IsFlyModeEnabled ? (num * (float)FlySpeed) : num);
|
||||
// Vector3 zero = Vector3.zero;
|
||||
// zero += Vector3.right * MovementDirection.Value.x;
|
||||
// zero += Vector3.forward * MovementDirection.Value.y;
|
||||
// zero = zero.relativeTo(_CameraTPPTarget, _Character.GetUpVector());
|
||||
// _Character.RotateTowards(zero, Time.deltaTime * _RotateTPPSpeed);
|
||||
// float value = Vector3.Dot(_Character.GetForwardVector(), zero);
|
||||
// Vector3 vector = _Character.GetForwardVector() * Mathf.Clamp01(value) * num;
|
||||
// if (checkWaterBound)
|
||||
// {
|
||||
// SetMovementDirectionWithRaycastCheck(vector);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// _Character.SetMovementDirection(vector);
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
{
|
||||
var num2 = Data.Run ? 7 : 5;
|
||||
//(IsRunPressed.Value ? MovementSpeed.Value : (MovementSpeed.Value * 0.5f));
|
||||
// num2 = (IsFlyModeEnabled ? (num2 * (float)FlySpeed) : num2);
|
||||
Vector3 vector2 = FirstPerson.GetRightVector() * Data.MoveInput.x * num2;
|
||||
vector2 += FirstPerson.GetForwardVector() * Data.MoveInput.y * num2;
|
||||
// if (checkWaterBound)
|
||||
// {
|
||||
// SetMovementDirectionWithRaycastCheck(vector2);
|
||||
// }
|
||||
// else
|
||||
{
|
||||
FirstPerson.SetMovementDirection(vector2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Look
|
||||
|
||||
public float MouseSensitivity = 0.1f;
|
||||
[Space(15f)] public bool invertLook = true;
|
||||
|
||||
public float minPitch = -60f;
|
||||
|
||||
public float maxPitch = 60f;
|
||||
|
||||
private void UpdateLookInput()
|
||||
{
|
||||
// TPPLookTarget.position = base.transform.position;
|
||||
// if (CameraView.Value == CameraViewType.TPP)
|
||||
// {
|
||||
// lookXRot -= MouseInput.Value.y;
|
||||
// lookXRot = Mathf.Clamp(lookXRot, -25f, 55f);
|
||||
// lookYRot += MouseInput.Value.x;
|
||||
// lookYRot = Mathf.Repeat(lookYRot, 360f);
|
||||
// TPPLookTarget.localEulerAngles = new Vector3(lookXRot, lookYRot, 0f);
|
||||
// }
|
||||
// else if (CameraView.Value == CameraViewType.FPP)
|
||||
{
|
||||
// if (_IsInVehicle && PlayerState.Value == State.vehicle)
|
||||
// {
|
||||
// lookXRot -= MouseInput.Value.y;
|
||||
// lookXRot = Mathf.Clamp(lookXRot, VehicleLookXMinMax.x, VehicleLookXMinMax.y);
|
||||
// lookYRot += MouseInput.Value.x;
|
||||
// lookYRot = Mathf.Clamp(lookYRot, VehicleLookYMinMax.x, VehicleLookYMinMax.y);
|
||||
// VehicleLookTargetParent.localEulerAngles = new Vector3(lookXRot, lookYRot, 0f);
|
||||
// _character.CameraPitch = 0f;
|
||||
// }
|
||||
// else
|
||||
{
|
||||
Vector2 value = InputManager.GetLookInput();
|
||||
FirstPerson.AddControlYawInput(value.x * (float)MouseSensitivity);
|
||||
FirstPerson.AddControlPitchInput((invertLook ? (0f - value.y) : value.y) * (float)MouseSensitivity,
|
||||
minPitch, maxPitch);
|
||||
// lookXRot = base.transform.eulerAngles.x;
|
||||
// lookYRot = base.transform.eulerAngles.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing/Player/FPlayer.Move.cs.meta
Normal file
3
Assets/Scripts/Fishing/Player/FPlayer.Move.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ae72860c045147af8022a3cbb30481ab
|
||||
timeCreated: 1766471468
|
||||
165
Assets/Scripts/Fishing/Player/FPlayer.cs
Normal file
165
Assets/Scripts/Fishing/Player/FPlayer.cs
Normal file
@@ -0,0 +1,165 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using ECM2;
|
||||
using ECM2.Examples.FirstPerson;
|
||||
using Fantasy;
|
||||
using NBC;
|
||||
using NBF.Fishing2;
|
||||
using NBF.Utils;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public partial class FPlayer : MonoService<FPlayer>
|
||||
{
|
||||
public Transform Root;
|
||||
public Transform Eye;
|
||||
public Transform FppLook;
|
||||
public Transform IK;
|
||||
public PlayerModelAsset ModelAsset;
|
||||
public CharacterMovement Character;
|
||||
public FirstPersonCharacter FirstPerson;
|
||||
public GameObject ModelGameObject { get; set; }
|
||||
|
||||
|
||||
public FPlayerData Data { get; private set; }
|
||||
|
||||
public readonly List<FRod> Tackles = new List<FRod>();
|
||||
public FRod Rod { get; private set; }
|
||||
public Fsm<FPlayer> Fsm { get; private set; }
|
||||
|
||||
public event Action<FHandItem> OnFishingSetEquiped;
|
||||
public event Action OnFishingSetUnequip;
|
||||
|
||||
protected override void OnAwake()
|
||||
{
|
||||
Character = gameObject.GetComponent<CharacterMovement>();
|
||||
FirstPerson = gameObject.GetComponent<FirstPersonCharacter>();
|
||||
Data = FPlayerData.Instance;
|
||||
transform.localPosition = new Vector3(484, 1, 422);
|
||||
// Data.NeedChangeRightArmAngle = true;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
InitFsm();
|
||||
AddInputEvent();
|
||||
CreatePlayerModel();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
UpdateMove();
|
||||
Fsm?.Update();
|
||||
|
||||
Data.EyeAngle = GameUtils.GetVerticalAngle(transform, FppLook);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
RemoveInputEvent();
|
||||
}
|
||||
|
||||
#region 状态机
|
||||
|
||||
private void InitFsm()
|
||||
{
|
||||
Fsm = new Fsm<FPlayer>("Player", this, true);
|
||||
Fsm.RegisterState<PlayerStateIdle>();
|
||||
Fsm.RegisterState<PlayerStateThrow>();
|
||||
Fsm.RegisterState<PlayerStateFishing>();
|
||||
Fsm.RegisterState<PlayerStateFight>();
|
||||
Fsm.RegisterState<PlayerStatePrepare>();
|
||||
Fsm.Start<PlayerStateIdle>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 角色模型
|
||||
|
||||
private void CreatePlayerModel()
|
||||
{
|
||||
var modelObject = PrefabsHelper.CreatePlayer(Root, "Human_Male");
|
||||
modelObject.transform.localPosition = Vector3.zero;
|
||||
ModelGameObject = modelObject;
|
||||
ModelAsset = modelObject.GetComponent<PlayerModelAsset>();
|
||||
ModelAsset.SetPlayer(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 使用物品
|
||||
|
||||
public IEnumerator UseItem(ItemInfo item)
|
||||
{
|
||||
if (Data.ChangeItem) yield break;
|
||||
Data.ChangeItem = true;
|
||||
var itemType = item?.ConfigId.GetItemType();
|
||||
if (itemType == ItemType.Rod)
|
||||
{
|
||||
//判断旧的是否要收回
|
||||
yield return UnUseItemConfirm();
|
||||
|
||||
Data.IsLureRod = true;
|
||||
var rodType = (ItemSubType)item.Config.Type;
|
||||
if (rodType == ItemSubType.RodTele)
|
||||
{
|
||||
Data.IsLureRod = false;
|
||||
}
|
||||
|
||||
Rod =
|
||||
item.Config.InstantiateAndComponent<FRod>(SceneSettings.Instance.GearNode, Vector3.zero,
|
||||
Quaternion.identity);
|
||||
yield return Rod.InitRod(this, item);
|
||||
Tackles.Add(Rod);
|
||||
OnFishingSetEquiped?.Invoke(Rod);
|
||||
}
|
||||
|
||||
Data.ChangeItem = false;
|
||||
}
|
||||
|
||||
public IEnumerator UnUseItem()
|
||||
{
|
||||
if (Data.ChangeItem) yield break;
|
||||
Data.ChangeItem = true;
|
||||
yield return UnUseItemConfirm();
|
||||
Data.ChangeItem = false;
|
||||
}
|
||||
|
||||
private IEnumerator UnUseItemConfirm()
|
||||
{
|
||||
if (Rod != null)
|
||||
{
|
||||
OnFishingSetUnequip?.Invoke();
|
||||
yield return Rod.Destroy();
|
||||
yield return new WaitForSeconds(0.35f);
|
||||
Destroy(Rod.gameObject);
|
||||
Tackles.Remove(Rod);
|
||||
Rod = null;
|
||||
yield return new WaitForSeconds(0.15f);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 线断了
|
||||
/// </summary>
|
||||
/// <param name="msg"></param>
|
||||
/// <param name="loseBaitChance"></param>
|
||||
public void LineBreak(string msg, float loseBaitChance)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing/Player/FPlayer.cs.meta
Normal file
3
Assets/Scripts/Fishing/Player/FPlayer.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 625346c970c542bab9f3a36f78720a77
|
||||
timeCreated: 1766419452
|
||||
116
Assets/Scripts/Fishing/Player/FPlayerData.cs
Normal file
116
Assets/Scripts/Fishing/Player/FPlayerData.cs
Normal file
@@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
// [Serializable]
|
||||
// public enum PlayerState
|
||||
// {
|
||||
// idle = 0,
|
||||
// move = 1,
|
||||
// prepare = 2,
|
||||
// casting = 3,
|
||||
// fishing = 4,
|
||||
// baitFlies = 5,
|
||||
// fight = 6,
|
||||
// fishView = 7,
|
||||
// collectFish = 8,
|
||||
// throwFish = 9,
|
||||
// vehicle = 10,
|
||||
// swiming = 11,
|
||||
// flyModeDebug = 12,
|
||||
// vehicleFishing = 13,
|
||||
// preciseCastIdle = 14,
|
||||
// preciseCastThrow = 15
|
||||
// }
|
||||
|
||||
[Serializable]
|
||||
public enum PlayerState : uint
|
||||
{
|
||||
None = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 闲置等待中
|
||||
/// </summary>
|
||||
Idle = 1,
|
||||
|
||||
/// <summary>
|
||||
/// 准备抛竿
|
||||
/// </summary>
|
||||
Prepare = 2,
|
||||
|
||||
/// <summary>
|
||||
/// 抛竿中
|
||||
/// </summary>
|
||||
Throw = 3,
|
||||
|
||||
/// <summary>
|
||||
/// 钓鱼中
|
||||
/// </summary>
|
||||
Fishing = 4,
|
||||
|
||||
/// <summary>
|
||||
/// 溜鱼中
|
||||
/// </summary>
|
||||
Fight = 5
|
||||
}
|
||||
|
||||
public class FPlayerData : MonoService<FPlayerData>
|
||||
{
|
||||
private PlayerState _previousPlayerState = PlayerState.Idle;
|
||||
private PlayerState _playerState;
|
||||
|
||||
public bool ChangeItem;
|
||||
public bool Run;
|
||||
public bool IsGrounded;
|
||||
public float Speed;
|
||||
public float RotationSpeed;
|
||||
public float ReelSpeed;
|
||||
public float LineTension;
|
||||
|
||||
/// <summary>
|
||||
/// 是否路亚竿
|
||||
/// </summary>
|
||||
public bool IsLureRod;
|
||||
|
||||
public Vector2 MoveInput;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public float EyeAngle;
|
||||
|
||||
|
||||
public PlayerState PreviousState => _previousPlayerState;
|
||||
|
||||
public PlayerState State
|
||||
{
|
||||
get => _playerState;
|
||||
set
|
||||
{
|
||||
_previousPlayerState = _playerState;
|
||||
_playerState = value;
|
||||
NextState = value;
|
||||
OnStateChange?.Invoke(_playerState);
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField] private PlayerState NextState;
|
||||
|
||||
public event Action<PlayerState> OnStateChange;
|
||||
|
||||
|
||||
private void Start()
|
||||
{
|
||||
NextState = State;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (NextState != State)
|
||||
{
|
||||
State = NextState;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing/Player/FPlayerData.cs.meta
Normal file
3
Assets/Scripts/Fishing/Player/FPlayerData.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 53629a9cec2b4caf9a739c21f7abdf3c
|
||||
timeCreated: 1766471002
|
||||
306
Assets/Scripts/Fishing/Player/PlayerAnimator.cs
Normal file
306
Assets/Scripts/Fishing/Player/PlayerAnimator.cs
Normal file
@@ -0,0 +1,306 @@
|
||||
using System;
|
||||
using KINEMATION.MagicBlend.Runtime;
|
||||
using NBC;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class PlayerAnimator : MonoBehaviour
|
||||
{
|
||||
public Animator _Animator;
|
||||
public FPlayer Player { get; private set; }
|
||||
|
||||
private bool _isRodLayerEnabled;
|
||||
private bool _isInit;
|
||||
private PlayerIK _IK;
|
||||
private MagicBlending _magicBlending;
|
||||
private bool _IsInVehicle;
|
||||
|
||||
#region 参数定义
|
||||
|
||||
// public static readonly int IsSwiming = Animator.StringToHash("Swim");
|
||||
//
|
||||
// public static readonly int ThrowFar = Animator.StringToHash("ThrowFar");
|
||||
//
|
||||
// public static readonly int BoatDriving = Animator.StringToHash("BoatDriving");
|
||||
//
|
||||
// public static readonly int BaitInWater = Animator.StringToHash("BaitInWater");
|
||||
//
|
||||
// public static readonly int HeldRod = Animator.StringToHash("HeldRod");
|
||||
//
|
||||
// public static readonly int RodArming = Animator.StringToHash("RodArming");
|
||||
|
||||
public static readonly int Forward = Animator.StringToHash("Forward");
|
||||
|
||||
public static readonly int Turn = Animator.StringToHash("Turn");
|
||||
|
||||
public static readonly int OnGroundHash = Animator.StringToHash("OnGround");
|
||||
public static readonly int PrepareThrowHash = Animator.StringToHash("PrepareThrow");
|
||||
public static readonly int StartThrowHash = Animator.StringToHash("StartThrow");
|
||||
public static readonly int BaitThrownHash = Animator.StringToHash("BaitThrown");
|
||||
private static readonly int FishingUpHash = Animator.StringToHash("FishingUp");
|
||||
|
||||
public static readonly string LureRodLayer = "LureRod";
|
||||
public static readonly string HandRodLayer = "HandRod";
|
||||
|
||||
|
||||
public float FishingUp
|
||||
{
|
||||
get => _Animator.GetFloat(FishingUpHash);
|
||||
set => _Animator.SetFloat(FishingUpHash, value);
|
||||
}
|
||||
|
||||
public bool OnGround
|
||||
{
|
||||
get => _Animator.GetBool(OnGroundHash);
|
||||
set => _Animator.SetBool(OnGroundHash, value);
|
||||
}
|
||||
|
||||
public bool StartThrow
|
||||
{
|
||||
get => _Animator.GetBool(StartThrowHash);
|
||||
set => _Animator.SetBool(StartThrowHash, value);
|
||||
}
|
||||
|
||||
public bool BaitThrown
|
||||
{
|
||||
get => _Animator.GetBool(BaitThrownHash);
|
||||
set => _Animator.SetBool(BaitThrownHash, value);
|
||||
}
|
||||
|
||||
public bool PrepareThrow
|
||||
{
|
||||
get => _Animator.GetBool(PrepareThrowHash);
|
||||
set => _Animator.SetBool(PrepareThrowHash, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Player = GetComponentInParent<FPlayer>();
|
||||
_magicBlending = GetComponent<MagicBlending>();
|
||||
_Animator = GetComponent<Animator>();
|
||||
_Animator.keepAnimatorStateOnDisable = true;
|
||||
_IK = GetComponent<PlayerIK>();
|
||||
_isInit = true;
|
||||
Player.OnFishingSetEquiped += OnFishingSetEquiped_OnRaised;
|
||||
Player.OnFishingSetUnequip += OnFishingSetUnequip;
|
||||
Player.Data.OnStateChange += PlayerFSMState_OnValueChanged;
|
||||
}
|
||||
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
Player.OnFishingSetEquiped -= OnFishingSetEquiped_OnRaised;
|
||||
Player.OnFishingSetUnequip -= OnFishingSetUnequip;
|
||||
Player.Data.OnStateChange += PlayerFSMState_OnValueChanged;
|
||||
}
|
||||
|
||||
|
||||
private void OnFishingSetUnequip()
|
||||
{
|
||||
_isRodLayerEnabled = false;
|
||||
// _IK.SetBipedLeftHandIK(enabled: false, null);
|
||||
}
|
||||
|
||||
|
||||
private void OnFishingSetEquiped_OnRaised(FHandItem item)
|
||||
{
|
||||
if (item is FRod rod)
|
||||
{
|
||||
_isRodLayerEnabled = true;
|
||||
// var reel = Player.Rod.Reel;
|
||||
// _IK.SetBipedLeftHandIK(enabled: false, reel.FingersIKAnchor);
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void SetLayerWeight(string layer, float weight)
|
||||
{
|
||||
_Animator.SetLayerWeight(_Animator.GetLayerIndex(layer), weight);
|
||||
}
|
||||
|
||||
private void PlayerFSMState_OnValueChanged(PlayerState state)
|
||||
{
|
||||
// switch (Player.Data.PreviousState)
|
||||
// {
|
||||
// case PlayerState.vehicle:
|
||||
// _IsInVehicle = false;
|
||||
// _Animator.SetBool(BoatDriving, value: false);
|
||||
// break;
|
||||
// case PlayerState.swiming:
|
||||
// _Animator.SetBool(IsSwiming, value: false);
|
||||
// break;
|
||||
// case PlayerState.preciseCastIdle:
|
||||
// _Animator.SetBool(PreciseIdle, value: false);
|
||||
// break;
|
||||
// case PlayerState.prepare:
|
||||
// _Animator.SetBool(RodArming, value: false);
|
||||
// break;
|
||||
// case PlayerState.casting:
|
||||
// _Animator.SetBool(ThrowFar, value: false);
|
||||
// break;
|
||||
// case PlayerState.collectFish:
|
||||
// _magicBlending.BlendAsset.globalWeight = 0f;
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// switch (state)
|
||||
// {
|
||||
// switch (Player.Data.PreviousState)
|
||||
// {
|
||||
// case PlayerState.vehicle:
|
||||
// _IsInVehicle = false;
|
||||
// _Animator.SetBool(BoatDriving, value: false);
|
||||
// break;
|
||||
// case PlayerState.swiming:
|
||||
// _Animator.SetBool(IsSwiming, value: false);
|
||||
// break;
|
||||
// case PlayerState.preciseCastIdle:
|
||||
// _Animator.SetBool(PreciseIdle, value: false);
|
||||
// break;
|
||||
// case PlayerState.prepare:
|
||||
// _Animator.SetBool(RodArming, value: false);
|
||||
// break;
|
||||
// case PlayerState.casting:
|
||||
// _Animator.SetBool(ThrowFar, value: false);
|
||||
// break;
|
||||
// case PlayerState.collectFish:
|
||||
// _magicBlending.BlendAsset.globalWeight = 0f;
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// switch (state)
|
||||
// {
|
||||
// case PlayerState.idle:
|
||||
// case PlayerState.move:
|
||||
// _Animator.SetBool(BaitInWater, value: false);
|
||||
// _Animator.SetBool(HeldRod, value: false);
|
||||
// _Animator.SetBool(ThrowFar, value: false);
|
||||
// _Animator.SetBool(RodArming, value: false);
|
||||
// break;
|
||||
// case PlayerState.prepare:
|
||||
// _Animator.SetBool(RodArming, value: true);
|
||||
// _Animator.SetBool(HeldRod, value: true);
|
||||
// break;
|
||||
// case PlayerState.fishing:
|
||||
// _Animator.SetBool(HeldRod, value: true);
|
||||
// _Animator.SetBool(BaitInWater, value: true);
|
||||
// break;
|
||||
// case PlayerState.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 PlayerState.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 PlayerState.swiming:
|
||||
// _Animator.SetBool(IsSwiming, value: true);
|
||||
// break;
|
||||
// case PlayerState.collectFish:
|
||||
// _Animator.SetBool(BaitInWater, value: false);
|
||||
// _IK.SetAimIK(enabled: false);
|
||||
// _magicBlending.BlendAsset.globalWeight = 1f;
|
||||
// break;
|
||||
// case PlayerState.preciseCastIdle:
|
||||
// _Animator.SetBool(PreciseIdle, value: true);
|
||||
// break;
|
||||
// case PlayerState.casting:
|
||||
// case PlayerState.baitFlies:
|
||||
// case PlayerState.fight:
|
||||
// case PlayerState.fishView:
|
||||
// case PlayerState.throwFish:
|
||||
// case PlayerState.flyModeDebug:
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
// if (Player.Data.State == PlayerState.swiming)
|
||||
// {
|
||||
// float value = Mathf.Lerp(_Animator.GetFloat(Forward), Player.Data.Speed / 2.5f,
|
||||
// Time.deltaTime * 5f);
|
||||
// float value2 = Mathf.Lerp(_Animator.GetFloat(Turn), Player.Data.RotationSpeed, 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), Player.Data.Speed / 5f,
|
||||
Time.deltaTime * 20f);
|
||||
float value4 = Mathf.Lerp(_Animator.GetFloat(Turn), Player.Data.RotationSpeed, Time.deltaTime * 15f);
|
||||
_Animator.SetFloat(Forward, Mathf.Clamp01(value3));
|
||||
_Animator.SetFloat(Turn, Mathf.Clamp(value4, -1f, 1f));
|
||||
}
|
||||
|
||||
// var rod = Vector3.zero;
|
||||
// if (Player.Rod)
|
||||
// {
|
||||
// rod = Player.Rod.transform.position;
|
||||
// }
|
||||
|
||||
_Animator.SetBool(OnGroundHash, _IsInVehicle || Player.Data.IsGrounded);
|
||||
|
||||
|
||||
var isHandRodLayerEnabled = _isRodLayerEnabled && !Player.Data.IsLureRod ? 1 : 0;
|
||||
|
||||
float handRodLayerWeight = _Animator.GetLayerWeight(_Animator.GetLayerIndex(HandRodLayer));
|
||||
SetLayerWeight(HandRodLayer,
|
||||
Mathf.MoveTowards(handRodLayerWeight, isHandRodLayerEnabled, Time.deltaTime * 3f));
|
||||
|
||||
|
||||
var isLureRodLayerEnabled = _isRodLayerEnabled && Player.Data.IsLureRod ? 1 : 0;
|
||||
float lureRodLayerWeight = _Animator.GetLayerWeight(_Animator.GetLayerIndex(LureRodLayer));
|
||||
SetLayerWeight(LureRodLayer,
|
||||
Mathf.MoveTowards(lureRodLayerWeight, isLureRodLayerEnabled, Time.deltaTime * 3f));
|
||||
}
|
||||
|
||||
#region 动画事件
|
||||
|
||||
/// <summary>
|
||||
/// 抬杆到底动画事件
|
||||
/// </summary>
|
||||
public void OnRodPowerUp()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开始抛出动画事件
|
||||
/// </summary>
|
||||
public void OnRodThrowStart()
|
||||
{
|
||||
if (Player.Fsm.CurrentState is PlayerStateThrow playerStateThrow)
|
||||
{
|
||||
playerStateThrow.OnRodThrowStart();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 抛竿结束动画事件
|
||||
/// </summary>
|
||||
public void OnRodThrownEnd()
|
||||
{
|
||||
if (Player.Fsm.CurrentState is PlayerStateThrow playerStateThrow)
|
||||
{
|
||||
playerStateThrow.OnRodThrownEnd();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing/Player/PlayerAnimator.cs.meta
Normal file
3
Assets/Scripts/Fishing/Player/PlayerAnimator.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0fc336a939c4416db623f3b4ae855265
|
||||
timeCreated: 1766470716
|
||||
29
Assets/Scripts/Fishing/Player/PlayerArm.cs
Normal file
29
Assets/Scripts/Fishing/Player/PlayerArm.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using RootMotion.FinalIK;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class PlayerArm : MonoBehaviour
|
||||
{
|
||||
public bool FixLowerArm;
|
||||
public bool IsLeft;
|
||||
public LimbIK IK;
|
||||
public Transform LowerArm;
|
||||
public Transform RodContainer;
|
||||
public FingerRig FingerRig;
|
||||
|
||||
|
||||
[HideInInspector] public float interactionTargetWeight;
|
||||
|
||||
private const int MaxFixEyeAngle = 15;
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing/Player/PlayerArm.cs.meta
Normal file
3
Assets/Scripts/Fishing/Player/PlayerArm.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 01ef40348d8b4d4da250acf0a921fc2a
|
||||
timeCreated: 1768660096
|
||||
25
Assets/Scripts/Fishing/Player/PlayerChest.cs
Normal file
25
Assets/Scripts/Fishing/Player/PlayerChest.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class PlayerChest : MonoBehaviour
|
||||
{
|
||||
private const int MaxFixEyeAngle = 15;
|
||||
private const int MinFixEyeAngle = -10;
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
FixArmAngle();
|
||||
}
|
||||
|
||||
private void FixArmAngle()
|
||||
{
|
||||
var angle = FPlayerData.Instance.EyeAngle;
|
||||
|
||||
if (angle > MaxFixEyeAngle) angle = MaxFixEyeAngle;
|
||||
else if (angle < MinFixEyeAngle) angle = MinFixEyeAngle;
|
||||
var val = transform.localEulerAngles;
|
||||
transform.localEulerAngles = new Vector3(val.x, val.y, val.z - angle);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing/Player/PlayerChest.cs.meta
Normal file
3
Assets/Scripts/Fishing/Player/PlayerChest.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e152a74e74b54d17ace5403a1570e12a
|
||||
timeCreated: 1768668096
|
||||
156
Assets/Scripts/Fishing/Player/PlayerIK.cs
Normal file
156
Assets/Scripts/Fishing/Player/PlayerIK.cs
Normal file
@@ -0,0 +1,156 @@
|
||||
using System;
|
||||
using RootMotion.FinalIK;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class PlayerIK : MonoBehaviour
|
||||
{
|
||||
public enum UpdateType
|
||||
{
|
||||
Update = 0,
|
||||
FixedUpdate = 1,
|
||||
LateUpdate = 2,
|
||||
Default = 3
|
||||
}
|
||||
|
||||
public UpdateType UpdateSelected;
|
||||
|
||||
// [SerializeField] private Transform _LeftHandTransform;
|
||||
|
||||
private LookAtIK _LookAtIK;
|
||||
|
||||
// private AimIK _AimIK;
|
||||
|
||||
// private FullBodyBipedIK _FullBodyIK;
|
||||
|
||||
// private ArmIK _ArmIK;
|
||||
|
||||
// private bool _isLeftHandEnabled;
|
||||
|
||||
// private bool _isRightHandEnabled;
|
||||
|
||||
// public bool isAimEnabled;
|
||||
|
||||
private bool _isFishingLeftArmEnabled;
|
||||
|
||||
[SerializeField] private float transitionWeightTimeScale = 1f;
|
||||
|
||||
// public Transform CurrentTarget => _FullBodyIK.solver.leftHandEffector.target;
|
||||
|
||||
// public Transform LeftHandTransform => _LeftHandTransform;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_LookAtIK = GetComponent<LookAtIK>();
|
||||
// _AimIK = GetComponent<AimIK>();
|
||||
// _FullBodyIK = GetComponent<FullBodyBipedIK>();
|
||||
// _ArmIK = GetComponent<ArmIK>();
|
||||
// SetAimIK(enabled: false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void SetBipedIK(bool enabled)
|
||||
{
|
||||
}
|
||||
|
||||
public void SetFishingLeftArm(bool enabled)
|
||||
{
|
||||
_isFishingLeftArmEnabled = enabled;
|
||||
}
|
||||
|
||||
// public void SetFishingLeftArm(bool enabled, Transform target)
|
||||
// {
|
||||
// _isFishingLeftArmEnabled = enabled;
|
||||
// _ArmIK.solver.arm.target = target;
|
||||
// }
|
||||
|
||||
// public void SetBipedLeftHandIK(bool enabled, bool instant = false)
|
||||
// {
|
||||
// _isLeftHandEnabled = enabled;
|
||||
// if (instant)
|
||||
// {
|
||||
// _FullBodyIK.solver.leftArmMapping.weight = (enabled ? 1f : 0f);
|
||||
// }
|
||||
// }
|
||||
|
||||
// public void SetBipedRightHandIK(bool enabled, bool instant = false)
|
||||
// {
|
||||
// _isRightHandEnabled = enabled;
|
||||
// if (instant)
|
||||
// {
|
||||
// _FullBodyIK.solver.rightArmMapping.weight = (enabled ? 1f : 0f);
|
||||
// }
|
||||
// }
|
||||
|
||||
// public void SetBipedLeftHandIK(bool enabled, Transform target, bool instant = false)
|
||||
// {
|
||||
// _isLeftHandEnabled = enabled;
|
||||
// _FullBodyIK.solver.leftHandEffector.target = target;
|
||||
// if (instant)
|
||||
// {
|
||||
// _FullBodyIK.solver.leftArmMapping.weight = (enabled ? 1f : 0f);
|
||||
// }
|
||||
// }
|
||||
|
||||
// public void SetBipedRightHandIK(bool enabled, Transform target, bool instant = false)
|
||||
// {
|
||||
// _isRightHandEnabled = enabled;
|
||||
// _FullBodyIK.solver.rightHandEffector.target = target;
|
||||
// if (instant)
|
||||
// {
|
||||
// _FullBodyIK.solver.rightArmMapping.weight = (enabled ? 1f : 0f);
|
||||
// }
|
||||
// }
|
||||
|
||||
// public void SetAimIK(bool enabled)
|
||||
// {
|
||||
// isAimEnabled = enabled;
|
||||
// }
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (UpdateSelected == UpdateType.Update)
|
||||
{
|
||||
IKUpdateHandler();
|
||||
}
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (UpdateSelected == UpdateType.FixedUpdate)
|
||||
{
|
||||
IKUpdateHandler();
|
||||
}
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
if (UpdateSelected == UpdateType.LateUpdate)
|
||||
{
|
||||
IKUpdateHandler();
|
||||
}
|
||||
}
|
||||
|
||||
private void IKUpdateHandler()
|
||||
{
|
||||
// _AimIK.UpdateSolverExternal();
|
||||
_LookAtIK.UpdateSolverExternal();
|
||||
// _FullBodyIK.UpdateSolverExternal();
|
||||
// _FullBodyIK.solver.Update();
|
||||
// _AimIK.solver.IKPositionWeight = Mathf.MoveTowards(_AimIK.solver.IKPositionWeight, isAimEnabled ? 1f : 0f,
|
||||
// Time.deltaTime * transitionWeightTimeScale);
|
||||
// _FullBodyIK.solver.leftArmMapping.weight = Mathf.MoveTowards(_FullBodyIK.solver.leftArmMapping.weight,
|
||||
// _isLeftHandEnabled ? 1f : 0f, Time.deltaTime * transitionWeightTimeScale);
|
||||
// _FullBodyIK.solver.rightArmMapping.weight = Mathf.MoveTowards(_FullBodyIK.solver.rightArmMapping.weight,
|
||||
// _isRightHandEnabled ? 1f : 0f, Time.deltaTime * transitionWeightTimeScale);
|
||||
// _FullBodyIK.solver.IKPositionWeight = Mathf.MoveTowards(_FullBodyIK.solver.IKPositionWeight,
|
||||
// _isLeftHandEnabled ? 1f : 0f, Time.deltaTime * transitionWeightTimeScale);
|
||||
// _ArmIK.solver.IKPositionWeight = Mathf.MoveTowards(_ArmIK.solver.IKPositionWeight,
|
||||
// _isFishingLeftArmEnabled ? 1f : 0f, Time.deltaTime * transitionWeightTimeScale);
|
||||
// _ArmIK.solver.IKRotationWeight = Mathf.MoveTowards(_ArmIK.solver.IKRotationWeight,
|
||||
// _isFishingLeftArmEnabled ? 1f : 0f, Time.deltaTime * transitionWeightTimeScale);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing/Player/PlayerIK.cs.meta
Normal file
3
Assets/Scripts/Fishing/Player/PlayerIK.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cb36ecc5b1784d948837600cf18808cd
|
||||
timeCreated: 1765121426
|
||||
3
Assets/Scripts/Fishing/Player/States.meta
Normal file
3
Assets/Scripts/Fishing/Player/States.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a3b57223c7f94237869524280afe1672
|
||||
timeCreated: 1768138483
|
||||
21
Assets/Scripts/Fishing/Player/States/PlayerStateBase.cs
Normal file
21
Assets/Scripts/Fishing/Player/States/PlayerStateBase.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using NBC;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public abstract class PlayerStateBase : FsmBaseState<FPlayer>
|
||||
{
|
||||
protected FPlayer Player => _owner;
|
||||
|
||||
/// <summary>
|
||||
/// 检查状态超时
|
||||
/// </summary>
|
||||
public void CheckStateTimeout(float time)
|
||||
{
|
||||
if (Time.time - EnterTime >= time)
|
||||
{
|
||||
Root.Start<PlayerStateIdle>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 080f1176c3ac4eefa37f615b22cac7ed
|
||||
timeCreated: 1768138530
|
||||
20
Assets/Scripts/Fishing/Player/States/PlayerStateFight.cs
Normal file
20
Assets/Scripts/Fishing/Player/States/PlayerStateFight.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
namespace NBF
|
||||
{
|
||||
public class PlayerStateFight : PlayerStateBase
|
||||
{
|
||||
public override uint StateId => (uint)PlayerState.Fight;
|
||||
|
||||
protected override void onEnter()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void onExit()
|
||||
{
|
||||
}
|
||||
|
||||
protected override uint onUpdate()
|
||||
{
|
||||
return States.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0720dd0d400641bea639e36f169aafde
|
||||
timeCreated: 1768138922
|
||||
102
Assets/Scripts/Fishing/Player/States/PlayerStateFishing.cs
Normal file
102
Assets/Scripts/Fishing/Player/States/PlayerStateFishing.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
using NBC;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
/// <summary>
|
||||
/// 钓鱼中
|
||||
/// </summary>
|
||||
public class PlayerStateFishing : PlayerStateBase
|
||||
{
|
||||
public override uint StateId => (uint)PlayerState.Fishing;
|
||||
|
||||
protected override void onEnter()
|
||||
{
|
||||
Debug.LogError("enter PlayerStateFishing");
|
||||
_owner.ModelAsset.PlayerAnimator.BaitThrown = true;
|
||||
}
|
||||
|
||||
protected override void onExit()
|
||||
{
|
||||
_owner.ModelAsset.PlayerAnimator.BaitThrown = false;
|
||||
}
|
||||
|
||||
protected override uint onUpdate()
|
||||
{
|
||||
var ret = States.None;
|
||||
var isUpRod = false;
|
||||
var isSubLine = false;
|
||||
|
||||
if (InputManager.IsOp1)
|
||||
{
|
||||
if (!Player.Data.IsLureRod)
|
||||
{
|
||||
//抬杆
|
||||
isUpRod = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//收线
|
||||
isSubLine = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (InputManager.IsOp2)
|
||||
{
|
||||
if (Player.Data.IsLureRod)
|
||||
{
|
||||
//抬杆
|
||||
isUpRod = true;
|
||||
}
|
||||
}
|
||||
|
||||
//Player.ModelAsset.PlayerAnimator.FishingUp = 0;
|
||||
|
||||
if (isUpRod || Player.ModelAsset.PlayerAnimator.FishingUp > 0)
|
||||
{
|
||||
var upForce = 1;
|
||||
var addNum = upForce * Time.deltaTime;
|
||||
if (!isUpRod)
|
||||
{
|
||||
addNum *= -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
addNum *= 0.5f;
|
||||
}
|
||||
|
||||
// Debug.Log($"addNum={addNum}");
|
||||
Player.ModelAsset.PlayerAnimator.FishingUp += addNum;
|
||||
// Debug.LogError($"ishingFinal={Player.ModelAsset.PlayerAnimator.FishingUp}");
|
||||
if (Player.ModelAsset.PlayerAnimator.FishingUp >= 1)
|
||||
{
|
||||
Player.ModelAsset.PlayerAnimator.FishingUp = 1;
|
||||
}
|
||||
else if (Player.ModelAsset.PlayerAnimator.FishingUp < 0)
|
||||
{
|
||||
Player.ModelAsset.PlayerAnimator.FishingUp = 0;
|
||||
}
|
||||
|
||||
if (Player.ModelAsset.PlayerAnimator.FishingUp >= 0.8f)
|
||||
{
|
||||
ret = CheckTackFish();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Player.ModelAsset.PlayerAnimator.FishingUp = 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#region 检查上鱼或者返回待机
|
||||
|
||||
private uint CheckTackFish()
|
||||
{
|
||||
return (uint)PlayerState.Idle;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6953fd92b2c54c6e846a0363520a9010
|
||||
timeCreated: 1768138900
|
||||
44
Assets/Scripts/Fishing/Player/States/PlayerStateIdle.cs
Normal file
44
Assets/Scripts/Fishing/Player/States/PlayerStateIdle.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using NBC;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
/// <summary>
|
||||
/// 闲置中
|
||||
/// </summary>
|
||||
public class PlayerStateIdle : PlayerStateBase
|
||||
{
|
||||
public override uint StateId => (uint)PlayerState.Idle;
|
||||
private bool _nextState = false;
|
||||
|
||||
protected override void onEnter()
|
||||
{
|
||||
Log.Info("enter PlayerStateIdle");
|
||||
_nextState = false;
|
||||
InputManager.OnOp1Action += OnOp1Action;
|
||||
}
|
||||
|
||||
private void OnOp1Action(bool performed)
|
||||
{
|
||||
if (!Player.Rod) return;
|
||||
if (performed)
|
||||
{
|
||||
_nextState = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void onExit()
|
||||
{
|
||||
InputManager.OnOp1Action -= OnOp1Action;
|
||||
}
|
||||
|
||||
protected override uint onUpdate()
|
||||
{
|
||||
if (_nextState)
|
||||
{
|
||||
return (uint)PlayerState.Prepare;
|
||||
}
|
||||
|
||||
return States.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a6146dcfbaf54972ac75c8115041ed3e
|
||||
timeCreated: 1768138510
|
||||
76
Assets/Scripts/Fishing/Player/States/PlayerStatePrepare.cs
Normal file
76
Assets/Scripts/Fishing/Player/States/PlayerStatePrepare.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using NBC;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
/// <summary>
|
||||
/// 准备抛竿中
|
||||
/// </summary>
|
||||
public class PlayerStatePrepare : PlayerStateBase
|
||||
{
|
||||
public override uint StateId => (uint)PlayerState.Prepare;
|
||||
|
||||
public enum Phase
|
||||
{
|
||||
/// <summary>
|
||||
/// 蓄力
|
||||
/// </summary>
|
||||
Charged,
|
||||
|
||||
/// <summary>
|
||||
/// 确认蓄力结果
|
||||
/// </summary>
|
||||
Confirm,
|
||||
}
|
||||
|
||||
public Phase Stage = Phase.Charged;
|
||||
public float ChargedProgress;
|
||||
|
||||
protected override void onEnter()
|
||||
{
|
||||
Log.Info("enter PlayerStatePrepare");
|
||||
Stage = Phase.Charged;
|
||||
Player.ModelAsset.PlayerAnimator.PrepareThrow = true;
|
||||
Player.ModelAsset.PlayerAnimator.FishingUp = 0;
|
||||
}
|
||||
|
||||
protected override uint onUpdate()
|
||||
{
|
||||
if (Stage == Phase.Charged)
|
||||
{
|
||||
ThrowPowerCharged();
|
||||
}
|
||||
else if (Stage == Phase.Confirm)
|
||||
{
|
||||
//确认蓄力结果,
|
||||
Debug.Log($"确认蓄力结果,ChargedProgress={ChargedProgress}");
|
||||
Params.Add(ChargedProgress);
|
||||
return (uint)PlayerState.Throw;
|
||||
}
|
||||
|
||||
return base.onUpdate();
|
||||
}
|
||||
|
||||
|
||||
#region 蓄力中
|
||||
|
||||
private void ThrowPowerCharged()
|
||||
{
|
||||
if (ChargedProgress < 1)
|
||||
{
|
||||
ChargedProgress += Time.deltaTime;
|
||||
}
|
||||
else if (ChargedProgress > 1)
|
||||
{
|
||||
ChargedProgress = 1;
|
||||
}
|
||||
|
||||
if (!InputManager.IsOp1)
|
||||
{
|
||||
Stage = Phase.Confirm;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1301b70435cd44c8ba3cc6085f35a782
|
||||
timeCreated: 1768138823
|
||||
100
Assets/Scripts/Fishing/Player/States/PlayerStateThrow.cs
Normal file
100
Assets/Scripts/Fishing/Player/States/PlayerStateThrow.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
using NBC;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
/// <summary>
|
||||
/// 抛竿中
|
||||
/// </summary>
|
||||
public class PlayerStateThrow : PlayerStateBase
|
||||
{
|
||||
public override uint StateId => (uint)PlayerState.Throw;
|
||||
|
||||
// public enum Phase
|
||||
// {
|
||||
// /// <summary>
|
||||
// /// 等待动画事件回调
|
||||
// /// </summary>
|
||||
// Waiting,
|
||||
//
|
||||
// /// <summary>
|
||||
// /// 前摇动画
|
||||
// /// </summary>
|
||||
// AnimBegin,
|
||||
//
|
||||
// /// <summary>
|
||||
// /// 抛线动画
|
||||
// /// </summary>
|
||||
// ThrowAnim,
|
||||
//
|
||||
// /// <summary>
|
||||
// /// 结束
|
||||
// /// </summary>
|
||||
// Done,
|
||||
// ErrorDone
|
||||
// }
|
||||
//
|
||||
// public Phase Stage = Phase.Waiting;
|
||||
private bool _nextState = false;
|
||||
public float ChargedProgress;
|
||||
|
||||
protected override void onEnter()
|
||||
{
|
||||
Log.Info("enter PlayerStateThrow");
|
||||
_owner.ModelAsset.PlayerAnimator.StartThrow = true;
|
||||
|
||||
ChargedProgress = (float)Params.Get(0);
|
||||
Debug.Log($"PlayerThrow ChargedProgress={ChargedProgress}");
|
||||
_nextState = false;
|
||||
// Stage = Phase.Waiting;
|
||||
|
||||
// _owner.Gears.Reel?.Unlock();
|
||||
}
|
||||
|
||||
protected override uint onUpdate()
|
||||
{
|
||||
CheckStateTimeout(10);
|
||||
if (_nextState)
|
||||
{
|
||||
return (uint)PlayerState.Fishing;
|
||||
}
|
||||
|
||||
return base.onUpdate();
|
||||
}
|
||||
|
||||
// IEnumerator ThrowCoroutine(float distance)
|
||||
// {
|
||||
// float startLength = 0.5f;
|
||||
// Debug.Log($"REST LENGTH : {rope.restLength}");
|
||||
// do
|
||||
// {
|
||||
// float a = Vector3.Distance(rodTipTarget.position, attachedBody.transform.position);
|
||||
// attachedBody.RBody.AddForce(playerForward.Value, ForceMode.VelocityChange);
|
||||
// startLength = Mathf.Max(a, startLength);
|
||||
// UnwindLine(attachedBody.RBody.linearVelocity.magnitude * Time.deltaTime);
|
||||
// yield return null;
|
||||
// }
|
||||
// while ((bool)isBailOpen);
|
||||
// }
|
||||
|
||||
#region 动画回调
|
||||
|
||||
/// <summary>
|
||||
/// 抛竿动画事件
|
||||
/// </summary>
|
||||
public void OnRodThrowStart()
|
||||
{
|
||||
Debug.LogError("OnRodThrowStart");
|
||||
_owner.ModelAsset.PlayerAnimator.PrepareThrow = false;
|
||||
_owner.ModelAsset.PlayerAnimator.StartThrow = false;
|
||||
}
|
||||
|
||||
public void OnRodThrownEnd()
|
||||
{
|
||||
Debug.LogError("OnRodThrownEnd");
|
||||
_nextState = true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a0b4bc6f668446cab7baf752da60477
|
||||
timeCreated: 1768138870
|
||||
Reference in New Issue
Block a user