首次提交
This commit is contained in:
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