提交修改
This commit is contained in:
@@ -172,6 +172,7 @@ GameObject:
|
||||
- component: {fileID: 2059248182290203691}
|
||||
- component: {fileID: 8101446342893690422}
|
||||
- component: {fileID: 2923025939212586282}
|
||||
- component: {fileID: 644643694351368293}
|
||||
m_Layer: 14
|
||||
m_Name: Player
|
||||
m_TagString: Untagged
|
||||
@@ -259,6 +260,14 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 7c69e72330154a86b756d89e82d276e9, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Assembly-CSharp::NBF.Player
|
||||
PreviousState: 0
|
||||
State: 0
|
||||
StateParams:
|
||||
_keys: []
|
||||
_intValues:
|
||||
_floatValues: []
|
||||
_vector3Values: []
|
||||
_quaternionValues: []
|
||||
EyeAngle: 0
|
||||
IsGrounded: 0
|
||||
Speed: 0
|
||||
@@ -277,6 +286,7 @@ MonoBehaviour:
|
||||
minPitch: -75
|
||||
maxPitch: 60
|
||||
IsSelf: 0
|
||||
TrajectoryPoints: []
|
||||
--- !u!114 &8101446342893690422
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -372,6 +382,18 @@ MonoBehaviour:
|
||||
_standingDownwardForceScale: 1
|
||||
_camera: {fileID: 0}
|
||||
cameraParent: {fileID: 6835675132305341997}
|
||||
--- !u!114 &644643694351368293
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8172838236951268422}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: df8de819db7747ddad97ff39505814a4, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Assembly-CSharp::NBF.PlayerFSM
|
||||
--- !u!1 &8378981416044742488
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
80
Assets/Scripts/Fishing/Player/Player.State.cs
Normal file
80
Assets/Scripts/Fishing/Player/Player.State.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public partial class Player
|
||||
{
|
||||
#region 状态
|
||||
|
||||
/// <summary>
|
||||
/// 上一个状态
|
||||
/// </summary>
|
||||
public PlayerState PreviousState;
|
||||
|
||||
/// <summary>
|
||||
/// 当前状态
|
||||
/// </summary>
|
||||
public PlayerState State;
|
||||
|
||||
/// <summary>
|
||||
/// 状态参数
|
||||
/// </summary>
|
||||
public StateEnterParams StateParams;
|
||||
|
||||
private readonly Dictionary<PlayerState, PlayerStageViewBase> _stageViews =
|
||||
new Dictionary<PlayerState, PlayerStageViewBase>();
|
||||
|
||||
private PlayerStageViewBase _currentStateView;
|
||||
|
||||
private void InitState()
|
||||
{
|
||||
_stageViews.Add(PlayerState.Idle, new PlayerStageViewIdle());
|
||||
_stageViews.Add(PlayerState.Prepare, new PlayerStageViewPrepare());
|
||||
_stageViews.Add(PlayerState.Throw, new PlayerStageViewThrow());
|
||||
_stageViews.Add(PlayerState.Fishing, new PlayerStageViewFishing());
|
||||
_stageViews.Add(PlayerState.Fight, new PlayerStageViewFight());
|
||||
foreach (var playerStageView in _stageViews.Values)
|
||||
{
|
||||
playerStageView.Init(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateState()
|
||||
{
|
||||
_currentStateView?.Update();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 切换状态
|
||||
/// </summary>
|
||||
/// <param name="state"></param>
|
||||
/// <param name="stateParams"></param>
|
||||
public void ChangeState(PlayerState state, StateEnterParams stateParams = null)
|
||||
{
|
||||
if (state == State)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
PreviousState = State;
|
||||
State = state;
|
||||
StateParams = stateParams;
|
||||
|
||||
OnStageChange();
|
||||
}
|
||||
|
||||
|
||||
public void OnStageChange()
|
||||
{
|
||||
if (_currentStateView != null)
|
||||
{
|
||||
_currentStateView.Exit();
|
||||
}
|
||||
|
||||
_currentStateView = _stageViews.GetValueOrDefault(State);
|
||||
_currentStateView?.Enter(StateParams, PreviousState);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing/Player/Player.State.cs.meta
Normal file
3
Assets/Scripts/Fishing/Player/Player.State.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4eda3ea2fee445de99d96eefc3acdb85
|
||||
timeCreated: 1777453996
|
||||
@@ -7,7 +7,7 @@ using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class Player : MonoBehaviour
|
||||
public partial class Player : MonoBehaviour
|
||||
{
|
||||
[Header("角色参数")] public float EyeAngle;
|
||||
public bool IsGrounded;
|
||||
@@ -37,6 +37,11 @@ namespace NBF
|
||||
|
||||
public bool IsSelf;
|
||||
|
||||
/// <summary>
|
||||
/// 抛物线轨迹
|
||||
/// </summary>
|
||||
public List<Vector3> TrajectoryPoints = new List<Vector3>();
|
||||
|
||||
#region 生命周期
|
||||
|
||||
private void Awake()
|
||||
@@ -50,10 +55,13 @@ namespace NBF
|
||||
{
|
||||
gameObject.AddComponent<PlayerInput>();
|
||||
}
|
||||
|
||||
InitState();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
UpdateState();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
@@ -61,10 +69,11 @@ namespace NBF
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region 手持物品
|
||||
|
||||
private FHandItem HandItem;
|
||||
public FHandItem HandItem { get; private set; }
|
||||
private bool IsChangeItemIng;
|
||||
|
||||
public async FTask UseItem(int configId, List<int> bindItems)
|
||||
|
||||
32
Assets/Scripts/Fishing/Player/PlayerFSM.cs
Normal file
32
Assets/Scripts/Fishing/Player/PlayerFSM.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class PlayerFSM : PlayerMonoBehaviour
|
||||
{
|
||||
private readonly Dictionary<PlayerState, PlayerStageViewBase> _stageViews =
|
||||
new Dictionary<PlayerState, PlayerStageViewBase>();
|
||||
|
||||
private PlayerState _currentState;
|
||||
private PlayerStageViewBase _currentStateView;
|
||||
|
||||
protected override void OnAwake()
|
||||
{
|
||||
_stageViews.Add(PlayerState.Idle, new PlayerStageViewIdle());
|
||||
_stageViews.Add(PlayerState.Prepare, new PlayerStageViewPrepare());
|
||||
_stageViews.Add(PlayerState.Throw, new PlayerStageViewThrow());
|
||||
_stageViews.Add(PlayerState.Fishing, new PlayerStageViewFishing());
|
||||
_stageViews.Add(PlayerState.Fight, new PlayerStageViewFight());
|
||||
foreach (var playerStageView in _stageViews.Values)
|
||||
{
|
||||
playerStageView.Init(Player);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
_currentStateView?.Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing/Player/PlayerFSM.cs.meta
Normal file
3
Assets/Scripts/Fishing/Player/PlayerFSM.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: df8de819db7747ddad97ff39505814a4
|
||||
timeCreated: 1777454838
|
||||
@@ -36,7 +36,6 @@ namespace NBF
|
||||
public abstract class PlayerStageViewBase
|
||||
{
|
||||
public Player Player { get; private set; }
|
||||
public PlayerView PlayerView { get; private set; }
|
||||
protected float EnterTime { get; set; }
|
||||
|
||||
protected PlayerState PreviousState { get; private set; }
|
||||
@@ -45,7 +44,6 @@ namespace NBF
|
||||
public void Init(Player player)
|
||||
{
|
||||
Player = player;
|
||||
PlayerView = player.GetComponent<PlayerView>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -95,18 +93,13 @@ namespace NBF
|
||||
public void TakeLine()
|
||||
{
|
||||
if (Player == null) return;
|
||||
var view = Player.GetComponent<PlayerView>();
|
||||
if (view != null)
|
||||
if (Player.HandItem is FRod rod)
|
||||
{
|
||||
var handItemView = Player.HandItem.GetComponent<PlayerItemView>();
|
||||
if (handItemView != null && handItemView.Rod != null)
|
||||
var endNode = rod.Line.EndNode;
|
||||
var pinch = endNode.GetComponent<JointPinchController>();
|
||||
if (pinch != null)
|
||||
{
|
||||
var endNode = handItemView.Rod.Line.EndNode;
|
||||
var pinch = endNode.GetComponent<JointPinchController>();
|
||||
if (pinch != null)
|
||||
{
|
||||
pinch.StartPinch(view.Unity.ModelAsset.Pinch);
|
||||
}
|
||||
pinch.StartPinch(Player.ModelAsset.Pinch);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -114,18 +107,13 @@ namespace NBF
|
||||
public void UnTakeLine()
|
||||
{
|
||||
if (Player == null) return;
|
||||
var view = Player.GetComponent<PlayerView>();
|
||||
if (view != null)
|
||||
if (Player.HandItem is FRod rod)
|
||||
{
|
||||
var handItemView = Player.HandItem.GetComponent<PlayerItemView>();
|
||||
if (handItemView != null && handItemView.Rod != null)
|
||||
var endNode = rod.Line.EndNode;
|
||||
var pinch = endNode.GetComponent<JointPinchController>();
|
||||
if (pinch != null)
|
||||
{
|
||||
var endNode = handItemView.Rod.Line.EndNode;
|
||||
var pinch = endNode.GetComponent<JointPinchController>();
|
||||
if (pinch != null)
|
||||
{
|
||||
pinch.ReleasePinch();
|
||||
}
|
||||
pinch.ReleasePinch();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -163,7 +151,7 @@ namespace NBF
|
||||
}
|
||||
}
|
||||
|
||||
if (isUpRod || PlayerView.Unity.ModelAsset.PlayerAnimator.FishingUp > 0)
|
||||
if (isUpRod || Player.ModelAsset.PlayerAnimator.FishingUp > 0)
|
||||
{
|
||||
var upForce = 1;
|
||||
var addNum = upForce * Time.deltaTime;
|
||||
@@ -176,20 +164,20 @@ namespace NBF
|
||||
addNum *= 0.5f;
|
||||
}
|
||||
|
||||
PlayerView.Unity.ModelAsset.PlayerAnimator.FishingUp += addNum;
|
||||
Debug.Log($"addNum={addNum} ishingFinal={PlayerView.Unity.ModelAsset.PlayerAnimator.FishingUp}");
|
||||
if (PlayerView.Unity.ModelAsset.PlayerAnimator.FishingUp >= 1)
|
||||
Player.ModelAsset.PlayerAnimator.FishingUp += addNum;
|
||||
Debug.Log($"addNum={addNum} ishingFinal={Player.ModelAsset.PlayerAnimator.FishingUp}");
|
||||
if (Player.ModelAsset.PlayerAnimator.FishingUp >= 1)
|
||||
{
|
||||
PlayerView.Unity.ModelAsset.PlayerAnimator.FishingUp = 1;
|
||||
Player.ModelAsset.PlayerAnimator.FishingUp = 1;
|
||||
}
|
||||
else if (PlayerView.Unity.ModelAsset.PlayerAnimator.FishingUp < 0)
|
||||
else if (Player.ModelAsset.PlayerAnimator.FishingUp < 0)
|
||||
{
|
||||
PlayerView.Unity.ModelAsset.PlayerAnimator.FishingUp = 0;
|
||||
Player.ModelAsset.PlayerAnimator.FishingUp = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PlayerView.Unity.ModelAsset.PlayerAnimator.FishingUp = 0;
|
||||
Player.ModelAsset.PlayerAnimator.FishingUp = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,14 +185,18 @@ namespace NBF
|
||||
|
||||
public FRod GetRod()
|
||||
{
|
||||
var view = Player.GetComponent<PlayerView>();
|
||||
if (view != null)
|
||||
// var view = Player.GetComponent<PlayerView>();
|
||||
// if (view != null)
|
||||
// {
|
||||
// var handItemView = Player.HandItem.GetComponent<PlayerItemView>();
|
||||
// if (handItemView != null && handItemView.Rod != null)
|
||||
// {
|
||||
// return handItemView.Rod;
|
||||
// }
|
||||
// }
|
||||
if (Player != null)
|
||||
{
|
||||
var handItemView = Player.HandItem.GetComponent<PlayerItemView>();
|
||||
if (handItemView != null && handItemView.Rod != null)
|
||||
{
|
||||
return handItemView.Rod;
|
||||
}
|
||||
return Player.HandItem as FRod;
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -15,7 +15,7 @@
|
||||
PlayerState ret = PlayerState.None;
|
||||
RodUpDown();
|
||||
|
||||
if (PlayerView.Unity.ModelAsset.PlayerAnimator.FishingUp >= 0.8f)
|
||||
if (Player.ModelAsset.PlayerAnimator.FishingUp >= 0.8f)
|
||||
{
|
||||
// ret = CheckTackFish();
|
||||
}
|
||||
@@ -7,7 +7,7 @@ namespace NBF
|
||||
protected override void OnEnter()
|
||||
{
|
||||
Debug.LogError("enter PlayerStateFishing");
|
||||
PlayerView.Unity.ModelAsset.PlayerAnimator.BaitThrown = true;
|
||||
Player.ModelAsset.PlayerAnimator.BaitThrown = true;
|
||||
}
|
||||
|
||||
protected override void OnExit()
|
||||
@@ -20,7 +20,7 @@ namespace NBF
|
||||
PlayerState ret = PlayerState.None;
|
||||
RodUpDown();
|
||||
|
||||
if (PlayerView.Unity.ModelAsset.PlayerAnimator.FishingUp >= 0.8f)
|
||||
if (Player.ModelAsset.PlayerAnimator.FishingUp >= 0.8f)
|
||||
{
|
||||
ret = CheckTackFish();
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
{
|
||||
protected override void OnEnter()
|
||||
{
|
||||
PlayerView.Unity.ModelAsset.PlayerAnimator.BaitThrown = false;
|
||||
Player.ModelAsset.PlayerAnimator.BaitThrown = false;
|
||||
InputManager.OnOp1Action += OnOp1Action;
|
||||
TakeLine();
|
||||
}
|
||||
@@ -28,8 +28,8 @@ namespace NBF
|
||||
Log.Info("enter PlayerStatePrepare");
|
||||
ChargedProgress = 0;
|
||||
Stage = Phase.Charged;
|
||||
PlayerView.Unity.ModelAsset.PlayerAnimator.PrepareThrow = true;
|
||||
PlayerView.Unity.ModelAsset.PlayerAnimator.FishingUp = 0;
|
||||
Player.ModelAsset.PlayerAnimator.PrepareThrow = true;
|
||||
Player.ModelAsset.PlayerAnimator.FishingUp = 0;
|
||||
}
|
||||
|
||||
protected override void OnUpdate()
|
||||
@@ -14,7 +14,7 @@ namespace NBF
|
||||
protected override void OnEnter()
|
||||
{
|
||||
Log.Info("enter PlayerStateThrow");
|
||||
PlayerView.Unity.ModelAsset.PlayerAnimator.StartThrow = true;
|
||||
Player.ModelAsset.PlayerAnimator.StartThrow = true;
|
||||
|
||||
ChargedProgress = 0;
|
||||
if (Params != null)
|
||||
@@ -57,8 +57,8 @@ namespace NBF
|
||||
{
|
||||
Debug.LogError("OnRodThrowStart");
|
||||
UnTakeLine();
|
||||
PlayerView.Unity.ModelAsset.PlayerAnimator.PrepareThrow = false;
|
||||
PlayerView.Unity.ModelAsset.PlayerAnimator.StartThrow = false;
|
||||
Player.ModelAsset.PlayerAnimator.PrepareThrow = false;
|
||||
Player.ModelAsset.PlayerAnimator.StartThrow = false;
|
||||
|
||||
var rod = GetRod();
|
||||
if (rod == null || rod.Line == null)
|
||||
@@ -71,9 +71,9 @@ namespace NBF
|
||||
_throwAnimation?.Play(new ThrowAnimationRequest
|
||||
{
|
||||
EndNode = rod.Line.EndNode,
|
||||
ThrowOriginPosition = PlayerView.Unity.transform.position,
|
||||
ThrowOriginPosition = Player.transform.position,
|
||||
StartPosition = rod.Line.EndNode.Rigidbody.position,
|
||||
Forward = PlayerView.Unity.transform.forward,
|
||||
Forward = Player.transform.forward,
|
||||
ChargedProgress = ChargedProgress
|
||||
});
|
||||
}
|
||||
@@ -108,4 +108,4 @@ namespace NBF
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace NBC
|
||||
{
|
||||
public class FsmTransmit
|
||||
{
|
||||
private readonly List<object> _queue = new List<object>();
|
||||
|
||||
public List<object> AllParam => _queue;
|
||||
|
||||
public void Add(object o)
|
||||
{
|
||||
_queue.Add(o);
|
||||
}
|
||||
|
||||
public void AddRange(FsmTransmit transmit)
|
||||
{
|
||||
_queue.AddRange(transmit.AllParam);
|
||||
}
|
||||
|
||||
public void AddRange(IEnumerable<object> o)
|
||||
{
|
||||
_queue.AddRange(o);
|
||||
}
|
||||
|
||||
public object Get(int index)
|
||||
{
|
||||
if (index >= 0 && index < _queue.Count)
|
||||
{
|
||||
return _queue[index];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_queue.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ namespace NBC
|
||||
public void EnterState(uint stateId, FsmBaseState<TOwnerClass> sourceState = null)
|
||||
{
|
||||
uint prevState = 0;
|
||||
FsmTransmit param = null;
|
||||
StateEnterParams param = null;
|
||||
if (_currentState != null)
|
||||
{
|
||||
prevState = _currentState.StateId;
|
||||
@@ -74,7 +74,7 @@ namespace NBC
|
||||
_currentState.PrevState = prevState;
|
||||
if (param != null)
|
||||
{
|
||||
_currentState.Params.AddRange(param);
|
||||
_currentState.Params = param;
|
||||
param.Clear();
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace NBC
|
||||
protected TOwnerClass _owner;
|
||||
protected Fsm<TOwnerClass> Root;
|
||||
|
||||
public FsmTransmit Params = new FsmTransmit();
|
||||
public StateEnterParams Params = new FsmTransmit();
|
||||
|
||||
public abstract uint StateId { get; }
|
||||
|
||||
42
Assets/Scripts/NBC/FSM~/FsmTransmit.cs
Normal file
42
Assets/Scripts/NBC/FSM~/FsmTransmit.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
// using System.Collections.Generic;
|
||||
// using System.Linq;
|
||||
//
|
||||
// namespace NBC
|
||||
// {
|
||||
// public class FsmTransmit
|
||||
// {
|
||||
// private readonly List<object> _queue = new List<object>();
|
||||
//
|
||||
// public List<object> AllParam => _queue;
|
||||
//
|
||||
// public void Add(object o)
|
||||
// {
|
||||
// _queue.Add(o);
|
||||
// }
|
||||
//
|
||||
// public void AddRange(FsmTransmit transmit)
|
||||
// {
|
||||
// _queue.AddRange(transmit.AllParam);
|
||||
// }
|
||||
//
|
||||
// public void AddRange(IEnumerable<object> o)
|
||||
// {
|
||||
// _queue.AddRange(o);
|
||||
// }
|
||||
//
|
||||
// public object Get(int index)
|
||||
// {
|
||||
// if (index >= 0 && index < _queue.Count)
|
||||
// {
|
||||
// return _queue[index];
|
||||
// }
|
||||
//
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// public void Clear()
|
||||
// {
|
||||
// _queue.Clear();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
Reference in New Issue
Block a user