修改提交

This commit is contained in:
Bob.Song
2026-03-09 17:50:20 +08:00
parent 68beeb3417
commit 27b85fd875
228 changed files with 30829 additions and 1509 deletions

View File

@@ -44,9 +44,9 @@ namespace NBF
PlayerAnimator = GetComponent<PlayerAnimator>();
}
public void SetPlayer(FPlayer player)
public void SetPlayer(Transform FppLook)
{
LookIk.solver.target = player.FppLook;
LookIk.solver.target = FppLook;
}
}
}

View File

@@ -17,6 +17,8 @@ namespace NBF
[SerializeField] private CameraAsset _cameraAsset;
private CameraShowMode _lastMode = CameraShowMode.None;
private PlayerUnityComponent FollowPlayer;
private void Update()
{
if (_lastMode == Mode) return;
@@ -43,27 +45,26 @@ namespace NBF
private void SetFPPCam()
{
var player = FPlayer.Instance;
if (player != null)
if (FollowPlayer != null)
{
_cameraAsset.fppVCam.LookAt = player.FppLook;
_cameraAsset.fppVCam.Follow = player.ModelAsset.NeckTransform;
_cameraAsset.fppVCam.LookAt = FollowPlayer.FppLook;
_cameraAsset.fppVCam.Follow = FollowPlayer.ModelAsset.NeckTransform;
}
_cameraAsset.fppVCam.Priority = 10;
_cameraAsset.tppVCam.Priority = 0;
// StartCoroutine(SnapToTarget());
}
public void SetFppLook(Transform fppCamLook)
public void SetFppLook(PlayerUnityComponent playerUnityComponent)
{
_cameraAsset.fppVCam.LookAt = fppCamLook;
FollowPlayer = playerUnityComponent;
_cameraAsset.fppVCam.LookAt = FollowPlayer.FppLook;
Mode = CameraShowMode.FPP;
}
public void SetFppFollow(Transform fppCamFollow)
public void SetFppFollow(PlayerUnityComponent playerUnityComponent)
{
_cameraAsset.fppVCam.Follow = fppCamFollow;
_cameraAsset.fppVCam.Follow = FollowPlayer.ModelAsset.NeckTransform;
}
}
}

View File

@@ -1,10 +0,0 @@
namespace NBF
{
public enum SelectorRodSetting
{
Speed = 0,
Drag = 1,
Leeder = 2
}
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: ca512e729d2e4ef290f30f075bcdd698
timeCreated: 1744039906

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,94 @@
// // 新文件D:\myself\Fishing2\Assets\Scripts\Fishing\Data\LocalDataManager.cs
//
// using System.Collections.Generic;
// using UnityEngine;
//
// namespace NBF
// {
// /// <summary>
// /// 本地单机模式的数据管理器(模拟服务器转发)
// /// </summary>
// public class LocalDataManager : PlayerDataManager
// {
// public override bool IsLocalMode => true;
//
// private Dictionary<int, FPlayerData> _localPlayers = new();
// private uint _sequenceCounter;
//
// protected void Awake()
// {
// Instance = this;
// }
//
// public void RegisterPlayer(FPlayerData player)
// {
// if (!_localPlayers.ContainsKey(player.PlayerID))
// {
// _localPlayers.Add(player.PlayerID, player);
// player.IsLocalPlayer = true;
// }
// }
//
// public override void OnPlayerStateChanged(FPlayerData player, PlayerState newState)
// {
// // 本地模式下,广播给其他本地玩家(分屏)
// foreach (var kvp in _localPlayers)
// {
// if (kvp.Value != player)
// {
// // 直接应用状态(或者加入简单的延迟模拟)
// kvp.Value.State = newState;
// }
// }
// }
//
// public override void OnHeldItemChanged(FPlayerData player, HeldItemInfo newItem)
// {
// foreach (var kvp in _localPlayers)
// {
// if (kvp.Value != player)
// {
// kvp.Value.CurrentHeldItem = newItem;
// }
// }
// }
//
// public override void SendStateSnapshot(FPlayerData player)
// {
// _sequenceCounter++;
// var snapshot = player.ToNetworkSnapshot(_sequenceCounter);
//
// // 本地广播
// foreach (var kvp in _localPlayers)
// {
// if (kvp.Value != player)
// {
// ReceiveStateSnapshot(kvp.Key, snapshot);
// }
// }
// }
//
// public override void ReceiveStateSnapshot(int playerID, PlayerStateSnapshot snapshot)
// {
// if (_localPlayers.TryGetValue(playerID, out var player))
// {
// player.ApplyFromNetworkSnapshot(snapshot);
// }
// }
//
// // 定时同步(例如每秒 10 次)
// private float _syncTimer;
// private void Update()
// {
// _syncTimer += Time.deltaTime;
// if (_syncTimer >= 0.1f) // 10Hz
// {
// _syncTimer = 0;
// foreach (var player in _localPlayers.Values)
// {
// SendStateSnapshot(player);
// }
// }
// }
// }
// }

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ec2bd63eb6c143fdb528da693a8c6969
timeCreated: 1773028161

View File

@@ -0,0 +1,60 @@
// using UnityEngine;
//
// namespace NBF
// {
// /// <summary>
// /// 网络模式的数据管理器
// /// </summary>
// public class NetworkDataManager : PlayerDataManager
// {
// public override bool IsLocalMode => false;
//
// // TODO: 这里集成你的网络库Steamworks、Photon、Mirror 等)
// // public SteamNetworkClient NetworkClient;
//
// protected void Awake()
// {
// Instance = this;
// }
//
// public override void OnPlayerStateChanged(FPlayerData player, PlayerState newState)
// {
// // 如果是本地玩家,发送到服务器
// if (player.IsLocalPlayer)
// {
// SendStateSnapshot(player);
// }
// }
//
// public override void OnHeldItemChanged(FPlayerData player, HeldItemInfo newItem)
// {
// if (player.IsLocalPlayer)
// {
// // TODO: 发送物品切换消息到服务器
// Debug.Log($"发送物品切换:{newItem.ItemType}, ConfigID={newItem.ConfigID}");
// }
// }
//
// public override void SendStateSnapshot(FPlayerData player)
// {
// if (!player.IsLocalPlayer) return;
//
// // TODO: 通过 Steam 或其他网络库发送
// // NetworkClient.SendStateSnapshot(player.ToNetworkSnapshot());
// }
//
// public override void ReceiveStateSnapshot(int playerID, PlayerStateSnapshot snapshot)
// {
// // TODO: 从网络接收其他玩家的状态
// // 找到或创建对应的玩家对象
// var player = FindOrCreatePlayer(playerID);
// player.ApplyFromNetworkSnapshot(snapshot);
// }
//
// private FPlayerData FindOrCreatePlayer(int playerID)
// {
// // TODO: 实现玩家对象池或动态生成
// return FindObjectOfType<FPlayerData>();
// }
// }
// }

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f1a06ba516ea46f0920729b2af6484c1
timeCreated: 1773028213

View File

@@ -0,0 +1,56 @@
// using System;
// using System.Collections.Generic;
// using UnityEngine;
//
// namespace NBF
// {
// public interface IDataSource
// {
// }
//
// /// <summary>
// /// 数据管理器基类(本地和网络共享接口)
// /// </summary>
// public class PlayerDataManager : MonoBehaviour
// {
// public static PlayerDataManager Instance { get; private set; }
//
// public FPlayerData Self { get; set; }
//
// private Dictionary<int, FPlayerData> _players = new Dictionary<int, FPlayerData>();
//
// protected void Awake()
// {
// Instance = this;
// }
//
//
// /// <summary>
// /// 玩家状态变更时调用
// /// </summary>
// public void OnPlayerStateChanged(FPlayerData player, PlayerState newState)
// {
// }
//
// /// <summary>
// /// 手持物品变更时调用
// /// </summary>
// public void OnHeldItemChanged(FPlayerData player, HeldItemInfo newItem)
// {
// }
//
// /// <summary>
// /// 发送玩家状态快照
// /// </summary>
// public void SendStateSnapshot(FPlayerData player)
// {
// }
//
// /// <summary>
// /// 接收并应用网络快照
// /// </summary>
// public void ReceiveStateSnapshot(int playerID, PlayerStateSnapshot snapshot)
// {
// }
// }
// }

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0478bf9a256a46beb65fd0307c7b5b9b
timeCreated: 1773028149

View File

@@ -0,0 +1,234 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace NBF
{
/// <summary>
/// 状态进入参数(用于网络同步和动画/表现播放)
/// </summary>
[Serializable]
public class StateEnterParams
{
// 序列化友好的数据存储
[SerializeField] private List<string> _keys = new();
[SerializeField] private List<int> _intValues = new();
[SerializeField] private List<float> _floatValues = new();
[SerializeField] private List<Vector3> _vector3Values = new();
[SerializeField] private List<Quaternion> _quaternionValues = new();
// 快速访问缓存
private Dictionary<string, int> _intCache;
private Dictionary<string, int> _floatCache;
private Dictionary<string, int> _vector3Cache;
private Dictionary<string, int> _quaternionCache;
public StateEnterParams()
{
InitializeCaches();
}
private void InitializeCaches()
{
_intCache = new Dictionary<string, int>();
_floatCache = new Dictionary<string, int>();
_vector3Cache = new Dictionary<string, int>();
_quaternionCache = new Dictionary<string, int>();
}
/// <summary>
/// 清空所有参数
/// </summary>
public void Clear()
{
_keys.Clear();
_intValues.Clear();
_floatValues.Clear();
_vector3Values.Clear();
_quaternionValues.Clear();
_intCache.Clear();
_floatCache.Clear();
_vector3Cache.Clear();
_quaternionCache.Clear();
}
/// <summary>
/// 设置 int 参数
/// </summary>
public void SetInt(string key, int value)
{
if (_intCache.TryGetValue(key, out int index))
{
_intValues[index] = value;
}
else
{
_keys.Add(key);
_intValues.Add(value);
_intCache[key] = _intValues.Count - 1;
}
}
/// <summary>
/// 设置 float 参数
/// </summary>
public void SetFloat(string key, float value)
{
if (_floatCache.TryGetValue(key, out int index))
{
_floatValues[index] = value;
}
else
{
_keys.Add(key);
_floatValues.Add(value);
_floatCache[key] = _floatValues.Count - 1;
}
}
/// <summary>
/// 设置 Vector3 参数
/// </summary>
public void SetVector3(string key, Vector3 value)
{
if (_vector3Cache.TryGetValue(key, out int index))
{
_vector3Values[index] = value;
}
else
{
_keys.Add(key);
_vector3Values.Add(value);
_vector3Cache[key] = _vector3Values.Count - 1;
}
}
/// <summary>
/// 设置 Quaternion 参数
/// </summary>
public void SetQuaternion(string key, Quaternion value)
{
if (_quaternionCache.TryGetValue(key, out int index))
{
_quaternionValues[index] = value;
}
else
{
_keys.Add(key);
_quaternionValues.Add(value);
_quaternionCache[key] = _quaternionValues.Count - 1;
}
}
/// <summary>
/// 设置 bool 参数
/// </summary>
public void SetBool(string key, bool value)
{
if (_intCache.TryGetValue(key, out int index))
{
_intValues[index] = value ? 1 : 0;
}
else
{
_keys.Add(key);
_intValues.Add(value ? 1 : 0);
_intCache[key] = _intValues.Count - 1;
}
}
/// <summary>
/// 获取 int 参数
/// </summary>
public int GetInt(string key, int defaultValue = 0)
{
if (_intCache.TryGetValue(key, out int index) && index < _intValues.Count)
{
return _intValues[index];
}
return defaultValue;
}
/// <summary>
/// 获取 float 参数
/// </summary>
public float GetFloat(string key, float defaultValue = 0f)
{
if (_floatCache.TryGetValue(key, out int index) && index < _floatValues.Count)
{
return _floatValues[index];
}
return defaultValue;
}
/// <summary>
/// 获取 Vector3 参数
/// </summary>
public Vector3 GetVector3(string key, Vector3 defaultValue = default)
{
if (_vector3Cache.TryGetValue(key, out int index) && index < _vector3Values.Count)
{
return _vector3Values[index];
}
return defaultValue;
}
/// <summary>
/// 获取 Quaternion 参数
/// </summary>
public Quaternion GetQuaternion(string key, Quaternion defaultValue = default)
{
if (_quaternionCache.TryGetValue(key, out int index) && index < _quaternionValues.Count)
{
return _quaternionValues[index];
}
return defaultValue;
}
/// <summary>
/// 获取 bool 参数
/// </summary>
public bool GetBool(string key, bool defaultValue = false)
{
if (_intCache.TryGetValue(key, out int index) && index < _intValues.Count)
{
return _intValues[index] == 1;
}
return defaultValue;
}
/// <summary>
/// 是否包含某个参数
/// </summary>
public bool HasKey(string key)
{
return _intCache.ContainsKey(key) ||
_floatCache.ContainsKey(key) ||
_vector3Cache.ContainsKey(key) ||
_quaternionCache.ContainsKey(key);
}
/// <summary>
/// 复制当前参数
/// </summary>
public StateEnterParams Clone()
{
var copy = new StateEnterParams
{
_keys = new List<string>(_keys),
_intValues = new List<int>(_intValues),
_floatValues = new List<float>(_floatValues),
_vector3Values = new List<Vector3>(_vector3Values),
_quaternionValues = new List<Quaternion>(_quaternionValues)
};
copy.InitializeCaches();
return copy;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a0ff43bbc7dd46b387e62f574ceb2523
timeCreated: 1773029210

View File

@@ -1,6 +1,7 @@
using System.Collections.Generic;
using Fantasy;
using Fantasy.Async;
using Fantasy.Entitas;
using NBF.Fishing2;
using RootMotion.FinalIK;
using Log = NBC.Log;
@@ -9,7 +10,6 @@ namespace NBF
{
public class Fishing
{
public FPlayer Player { get; private set; }
private static Fishing _instance;
public static Fishing Instance
@@ -22,6 +22,10 @@ namespace NBF
}
}
public MapRoom OldMap { get; private set; }
public MapRoom Map { get; private set; }
public async FTask<bool> Go(int mapId, string roomCode = "")
{
@@ -37,6 +41,11 @@ namespace NBF
RoomCode = roomCode
});
Log.Info($"进入地图请求返回={response.ErrorCode}");
if (response.ErrorCode != 0)
{
Notices.Error("enter room error");
return false;
}
LoadingPanel.Show();
await ChangeMap(response.MapId, response.RoomCode, response.Units);
LoadingPanel.Hide();
@@ -46,18 +55,17 @@ namespace NBF
public async FTask ChangeMap(int mapId, string roomCode, List<MapUnitInfo> units)
{
OldMap = Map;
Map = Entity.Create<MapRoom>(Game.Main,true, true);
Map.Code = roomCode;
Map.Map = mapId;
var sceneName = "Map1";
//加载场景==
await SceneHelper.LoadScene(sceneName);
CreateUnit();
}
private void CreateUnit()
{
var gameObject = PrefabsHelper.CreatePlayer(SceneSettings.Instance.Node);
Player = gameObject.GetComponent<FPlayer>();
CameraManager.Instance.Mode = CameraShowMode.FPP;
foreach (var mapUnitInfo in units)
{
Map.AddUnit(mapUnitInfo);
}
}
}
}

View File

@@ -1,7 +0,0 @@
namespace NBF
{
public class FishingMap
{
}
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: c361da1bcda647eb96fa27af894d2a7a
timeCreated: 1766417823

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b727e6041c1e459aabd0d5c41752dd8e
timeCreated: 1773036926

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0b61ff9bc02946a287bd0cca1aa2b6cb
timeCreated: 1773037834

View File

@@ -0,0 +1,63 @@
using System.Collections.Generic;
using Fantasy;
using Fantasy.Entitas;
namespace NBF
{
/// <summary>
/// 地图房间
/// </summary>
public class MapRoom : Entity
{
/// <summary>
/// 是否本地房间
/// </summary>
public bool IsLocalRoom;
/// <summary>
/// 房间序号id
/// </summary>
public int RoomId;
/// <summary>
/// 房间代码
/// </summary>
public string Code = string.Empty;
/// <summary>
/// 房间玩家
/// </summary>
public Dictionary<long, Player> Units = new Dictionary<long, Player>();
/// <summary>
/// 房主
/// </summary>
public long Owner;
/// <summary>
/// 创建时间
/// </summary>
public long CreateTime;
/// <summary>
/// 房间地图
/// </summary>
public int Map;
public void AddUnit(MapUnitInfo unit)
{
var player = Create<Player>(Game.Main, unit.Id, true, true);
Units[unit.Id] = player;
player.InitPlayer(unit);
}
public void RemoveUnit(long id)
{
if (Units.Remove(id, out var player))
{
player.Dispose();
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 41009853ac444d87809e98fae2d1c597
timeCreated: 1773036879

View File

@@ -0,0 +1,97 @@
using System.Collections.Generic;
using Fantasy;
using Fantasy.Entitas;
using UnityEngine;
namespace NBF
{
public class Player : Entity
{
/// <summary>
/// 是否本地玩家
/// </summary>
public bool IsLocalPlayer;
public bool IsLureRod => false;
public bool IsSelf => RoleModel.Instance.Id == Id;
// ========== 物理状态(高频同步) ==========
public Vector3 position;
public Quaternion rotation;
public Vector2 MoveInput;
public float Speed;
public float RotationSpeed;
public bool IsGrounded;
public bool Run;
// ========== 钓鱼相关状态(中频同步) ==========
public float currentReelingSpeed;
public float lineLength;
public float reelSpeed;
public float EyeAngle;
/// <summary>
/// 标志量
/// </summary>
public long TagValue;
// ========== 状态机 ==========
private PlayerState _previousPlayerState = PlayerState.Idle;
private PlayerState _playerState;
public PlayerState PreviousState => _previousPlayerState;
/// <summary>
/// 当前状态的进入参数(本地和远程都适用)
/// </summary>
public StateEnterParams CurrentStateParams { get; private set; } = new StateEnterParams();
public PlayerState State
{
get => _playerState;
set
{
if (_playerState != value)
{
_previousPlayerState = _playerState;
_playerState = value;
}
}
}
/// <summary>
/// 玩家的物品
/// </summary>
public Dictionary<long, PlayerItem> Items = new Dictionary<long, PlayerItem>();
/// <summary>
/// 当前手持物品id
/// </summary>
public long HandItemId;
/// <summary>
/// 当前手持物品
/// </summary>
public PlayerItem HandItem => Items[HandItemId];
public void InitPlayer(MapUnitInfo unitInfo)
{
AddComponent<PlayerViewComponent>();
if (unitInfo.Id == RoleModel.Instance.Id)
{
//自己
AddComponent<PlayerInputComponent>();
}
}
public void UnUseItem()
{
}
public void UseItem(ItemInfo item)
{
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8f7d8cb1b2cd4e25913e17e2b54e7ad9
timeCreated: 1773036936

View File

@@ -0,0 +1,12 @@
using Fantasy.Entitas;
namespace NBF
{
public class PlayerItem : Entity
{
/// <summary>
/// 配置id
/// </summary>
public int ConfigID;
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6649b122db2f46aea8147228c674a38c
timeCreated: 1773037313

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a6965e70ae1742089580926e5b1adabf
timeCreated: 1773037850

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c38d17daa1164359ad9f9466be692b7c
timeCreated: 1773038185

View File

@@ -0,0 +1,185 @@
using System;
using KINEMATION.MagicBlend.Runtime;
using NBC;
using UnityEngine;
namespace NBF
{
public class PlayerAnimator : PlayerMonoBehaviour
{
public Animator _Animator;
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
protected override void OnAwake()
{
_magicBlending = GetComponent<MagicBlending>();
_Animator = GetComponent<Animator>();
_Animator.keepAnimatorStateOnDisable = true;
_IK = GetComponent<PlayerIK>();
_isInit = true;
// Player.OnFishingSetEquiped += OnFishingSetEquiped_OnRaised;
// Player.OnFishingSetUnequip += OnFishingSetUnequip;
}
private void OnDestroy()
{
// Player.OnFishingSetEquiped -= OnFishingSetEquiped_OnRaised;
// Player.OnFishingSetUnequip -= OnFishingSetUnequip;
}
private void OnFishingSetUnequip()
{
_isRodLayerEnabled = false;
}
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 LateUpdate()
{
{
float value3 = Mathf.Lerp(_Animator.GetFloat(Forward), Player.Speed / 5f,
Time.deltaTime * 20f);
float value4 = Mathf.Lerp(_Animator.GetFloat(Turn), Player.RotationSpeed,
Time.deltaTime * 15f);
_Animator.SetFloat(Forward, Mathf.Clamp01(value3));
_Animator.SetFloat(Turn, Mathf.Clamp(value4, -1f, 1f));
}
_Animator.SetBool(OnGroundHash, _IsInVehicle || Player.IsGrounded);
var isHandRodLayerEnabled = _isRodLayerEnabled && !Player.IsLureRod ? 1 : 0;
float handRodLayerWeight = _Animator.GetLayerWeight(_Animator.GetLayerIndex(HandRodLayer));
SetLayerWeight(HandRodLayer,
Mathf.MoveTowards(handRodLayerWeight, isHandRodLayerEnabled, Time.deltaTime * 3f));
var isLureRodLayerEnabled = _isRodLayerEnabled && Player.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.State is PlayerStateThrow playerStateThrow)
// {
// playerStateThrow.OnRodThrowStart();
// }
}
/// <summary>
/// 抛竿结束动画事件
/// </summary>
public void OnRodThrownEnd()
{
// if (Player.Fsm.CurrentState is PlayerStateThrow playerStateThrow)
// {
// playerStateThrow.OnRodThrownEnd();
// }
}
#endregion
}
}

View File

@@ -4,7 +4,7 @@ using UnityEngine;
namespace NBF
{
public class PlayerArm : MonoBehaviour
public class PlayerArm : PlayerMonoBehaviour
{
public bool FixLowerArm;
public bool IsLeft;
@@ -18,7 +18,7 @@ namespace NBF
private const int MaxFixEyeAngle = 15;
public void Awake()
protected override void OnAwake()
{
}

View File

@@ -2,7 +2,7 @@
namespace NBF
{
public class PlayerChest : MonoBehaviour
public class PlayerChest : PlayerMonoBehaviour
{
private const int MaxFixEyeAngle = 15;
private const int MinFixEyeAngle = -10;
@@ -14,8 +14,7 @@ namespace NBF
private void FixArmAngle()
{
var angle = FPlayerData.Instance.EyeAngle;
var angle = Player.EyeAngle;
if (angle > MaxFixEyeAngle) angle = MaxFixEyeAngle;
else if (angle < MinFixEyeAngle) angle = MinFixEyeAngle;
var val = transform.localEulerAngles;

View File

@@ -0,0 +1,58 @@
using System;
using RootMotion.FinalIK;
using UnityEngine;
namespace NBF
{
public class PlayerIK : PlayerMonoBehaviour
{
public enum UpdateType
{
Update = 0,
FixedUpdate = 1,
LateUpdate = 2,
Default = 3
}
public UpdateType UpdateSelected;
private LookAtIK _LookAtIK;
[SerializeField] private float transitionWeightTimeScale = 1f;
protected override void OnAwake()
{
_LookAtIK = GetComponent<LookAtIK>();
}
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()
{
_LookAtIK.UpdateSolverExternal();
}
}
}

View File

@@ -0,0 +1,22 @@
using UnityEngine;
namespace NBF
{
public abstract class PlayerMonoBehaviour : MonoBehaviour
{
public Player Player { get; private set; }
public PlayerUnityComponent UnityComponent { get; private set; }
protected void Awake()
{
UnityComponent = GetComponentInParent<PlayerUnityComponent>();
Player = UnityComponent.Player;
OnAwake();
}
protected virtual void OnAwake()
{
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7fbde40efe5345cd8c05ea6c1f1914cf
timeCreated: 1773040970

View File

@@ -0,0 +1,25 @@
using ECM2;
using ECM2.Examples.FirstPerson;
using UnityEngine;
namespace NBF
{
public class PlayerUnityComponent : MonoBehaviour
{
public Player Player { get; set; }
public Transform Root;
public Transform Eye;
public Transform FppLook;
public Transform IK;
public PlayerModelAsset ModelAsset;
public CharacterMovement Character;
public FirstPersonCharacter FirstPerson;
[Header("视角相关")] public float MouseSensitivity = 0.1f;
[Space(15f)] public bool invertLook = true;
public float minPitch = -60f;
public float maxPitch = 60f;
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a25908f34e4e4464a922b88337a5b733
timeCreated: 1773038189

View File

@@ -0,0 +1,200 @@
using Fantasy.Entitas;
using Fantasy.Entitas.Interface;
using NBC;
using UnityEngine;
using UnityEngine.InputSystem;
namespace NBF
{
public class PlayerInputComponent : Entity
{
public Player Player { get; private set; }
public PlayerViewComponent View { get; private set; }
#region
public class PlayerViewAwakeSystem : AwakeSystem<PlayerInputComponent>
{
protected override void Awake(PlayerInputComponent self)
{
self.Player = self.GetParent<Player>();
self.View = self.Player.GetComponent<PlayerViewComponent>();
self.AddInputEvent();
}
}
public class PlayerViewUpdateSystem : UpdateSystem<PlayerInputComponent>
{
protected override void Update(PlayerInputComponent self)
{
self.UpdateMove();
}
}
public class PlayerViewDestroySystem : DestroySystem<PlayerInputComponent>
{
protected override void Destroy(PlayerInputComponent self)
{
self.RemoveInputEvent();
}
}
#endregion
#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)
{
Player.Run = true;
}
}
private void OnPlayerCanceled(string action)
{
if (action == InputDef.Player.Run)
{
Player.Run = false;
}
else if (action == InputDef.Player.ToBag)
{
//取消手持物品
Log.Info($"取消手持物品");
Player.UnUseItem();
// 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)
{
Player.UseItem(item);
// Game.Instance.StartCoroutine(UseItem(item));
}
}
}
private void OnPlayerValueCanceled(InputAction.CallbackContext context)
{
var actionName = context.action.name;
if (actionName == InputDef.Player.Move)
{
Player.MoveInput = Vector2.zero;
}
}
private void OnPlayerValuePerformed(InputAction.CallbackContext context)
{
var actionName = context.action.name;
if (actionName == InputDef.Player.Move)
{
var v2 = context.ReadValue<Vector2>();
Player.MoveInput = v2;
}
else if (actionName == InputDef.Player.Look)
{
}
}
#endregion
#region Move
private Quaternion lastRotation;
private void UpdateMove()
{
UpdateGrounded();
ProcessMoveStates();
UpdateLookInput();
}
private void ProcessMoveStates()
{
{
var num2 = Player.Run ? 7 : 5;
Vector3 vector2 = View.Unity.FirstPerson.GetRightVector() * Player.MoveInput.x * num2;
vector2 += View.Unity.FirstPerson.GetForwardVector() * Player.MoveInput.y * num2;
// if (checkWaterBound)
// {
// SetMovementDirectionWithRaycastCheck(vector2);
// }
// else
{
View.Unity.FirstPerson.SetMovementDirection(vector2);
}
}
}
private void UpdateGrounded()
{
Player.IsGrounded = View.Unity.FirstPerson.IsGrounded();
Player.Speed = View.Unity.FirstPerson.velocity.magnitude;
Quaternion rotation = View.Unity.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);
Player.RotationSpeed = turnValue;
lastRotation = rotation;
}
#endregion
#region Look
private void UpdateLookInput()
{
Vector2 value = InputManager.GetLookInput();
var u3d = View.Unity;
u3d.FirstPerson.AddControlYawInput(value.x * u3d.MouseSensitivity);
u3d.FirstPerson.AddControlPitchInput((u3d.invertLook ? 0f - value.y : value.y) * u3d.MouseSensitivity,
u3d.minPitch, u3d.maxPitch);
}
#endregion
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2d74cb6e741243478aeb0a3053211fcd
timeCreated: 1773039193

View File

@@ -0,0 +1,89 @@
using Fantasy.Entitas;
using Fantasy.Entitas.Interface;
using NBF.Fishing2;
using UnityEngine;
namespace NBF
{
public class PlayerViewComponent : Entity
{
public Player Player { get; private set; }
public PlayerUnityComponent Unity { get; private set; }
#region
public void Awake()
{
Player = GetParent<Player>();
var gameObject = PrefabsHelper.CreatePlayer(SceneSettings.Instance.Node);
Unity = gameObject.GetComponent<PlayerUnityComponent>();
Unity.Player = Player;
CreatePlayerModel();
if (Player.IsSelf)
{
CameraManager.Instance.SetFppLook(Unity);
}
Unity.transform.localPosition = new Vector3(484, 1, 422);
}
public void Update()
{
}
public void LateUpdate()
{
Player.EyeAngle = GameUtils.GetVerticalAngle(Unity.transform, Unity.FppLook);
}
public void Destroy()
{
}
#endregion
#region
private void CreatePlayerModel()
{
var modelObject = PrefabsHelper.CreatePlayer(Unity.Root, "Human_Male");
modelObject.transform.localPosition = Vector3.zero;
Unity.ModelAsset = modelObject.GetComponent<PlayerModelAsset>();
Unity.ModelAsset.SetPlayer(Unity.FppLook);
}
#endregion
}
public class PlayerViewAwakeSystem : AwakeSystem<PlayerViewComponent>
{
protected override void Awake(PlayerViewComponent self)
{
self.Awake();
}
}
public class PlayerViewDestroySystem : DestroySystem<PlayerViewComponent>
{
protected override void Destroy(PlayerViewComponent self)
{
self.Destroy();
}
}
public class PlayerViewUpdateSystem : UpdateSystem<PlayerViewComponent>
{
protected override void Update(PlayerViewComponent self)
{
self.Update();
}
}
public class PlayerViewLateUpdateSystem : LateUpdateSystem<PlayerViewComponent>
{
protected override void LateUpdate(PlayerViewComponent self)
{
self.LateUpdate();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 418da378516646cdb672fa05c2066432
timeCreated: 1773037811

View File

@@ -1,93 +0,0 @@
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
}
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: ea2c2e2d4b4344f0bc9d58ba0aeec6fd
timeCreated: 1766505279

View File

@@ -1,146 +0,0 @@
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
}
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: ae72860c045147af8022a3cbb30481ab
timeCreated: 1766471468

View File

@@ -1,165 +1,142 @@
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)
{
}
}
}
// 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 = PlayerDataManager.Instance.Self;
// transform.localPosition = new Vector3(484, 1, 422);
// // Data.NeedChangeRightArmAngle = true;
// }
//
// private void Start()
// {
// InitFsm();
// CreatePlayerModel();
// }
//
//
// private void LateUpdate()
// {
// Fsm?.Update();
// }
//
// #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;
// yield return null;
// }
//
// public IEnumerator UnUseItem()
// {
// // if (Data.ChangeItem) yield break;
// // Data.ChangeItem = true;
// // yield return UnUseItemConfirm();
// // Data.ChangeItem = false;
// yield return null;
// }
//
// 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
// }
// }

View File

@@ -1,87 +0,0 @@
// 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
// // }
//
//
// 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;
// }
// }
// }
// }

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 53629a9cec2b4caf9a739c21f7abdf3c
timeCreated: 1766471002

View File

@@ -1,306 +0,0 @@
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
}
}

View File

@@ -1,156 +0,0 @@
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);
}
}
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: a3b57223c7f94237869524280afe1672
timeCreated: 1768138483

View File

@@ -3,9 +3,9 @@ using UnityEngine;
namespace NBF
{
public abstract class PlayerStateBase : FsmBaseState<FPlayer>
public abstract class PlayerStateBase : FsmBaseState<Player>
{
protected FPlayer Player => _owner;
protected Player Player => _owner;
/// <summary>
/// 检查状态超时

View File

@@ -29,25 +29,25 @@ namespace NBF
if (InputManager.IsOp1)
{
if (!Player.Data.IsLureRod)
{
//抬杆
isUpRod = true;
}
else
{
//收线
isSubLine = true;
}
// if (!Player.Data.IsLureRod)
// {
// //抬杆
// isUpRod = true;
// }
// else
// {
// //收线
// isSubLine = true;
// }
}
if (InputManager.IsOp2)
{
if (Player.Data.IsLureRod)
{
//抬杆
isUpRod = true;
}
// if (Player.Data.IsLureRod)
// {
// //抬杆
// isUpRod = true;
// }
}
//Player.ModelAsset.PlayerAnimator.FishingUp = 0;

View File

@@ -3,16 +3,14 @@ using UnityEngine;
namespace NBF
{
public abstract class FGearBase : MonoBehaviour
public abstract class FGearBase : PlayerMonoBehaviour
{
public FPlayer Player { get; protected set; }
public FRod Rod { get; protected set; }
public ItemInfo ItemInfo;
public virtual void Init(FPlayer player, FRod rod)
public virtual void Init(FRod rod)
{
Player = player;
Rod = rod;
OnInit();
}

View File

@@ -2,8 +2,7 @@
namespace NBF
{
public class FHandItem : MonoBehaviour
public class FHandItem : PlayerMonoBehaviour
{
}
}

View File

@@ -12,7 +12,7 @@ namespace NBF
public class FRod : FHandItem
{
private float _tension;
/// <summary>
/// 可用的
/// </summary>
@@ -20,7 +20,6 @@ namespace NBF
public RodAsset Asset;
public FPlayer Player { get; protected set; }
public ItemInfo ItemInfo;
public FReel Reel;
@@ -61,7 +60,7 @@ namespace NBF
}
}
}
private void Awake()
{
@@ -125,22 +124,26 @@ namespace NBF
yield return 1;
}
public IEnumerator InitRod(FPlayer player, ItemInfo itemInfo)
public IEnumerator InitRod(ItemInfo itemInfo)
{
ItemInfo = itemInfo;
Player = player;
// Player = player;
var playerView = Player.GetComponent<PlayerViewComponent>();
var playerViewUnity = playerView.Unity;
transform.localPosition = Vector3.zero;
transform.localRotation = Quaternion.identity;
transform.localScale = Vector3.one;
SceneSettings.Instance.GearNode.position = Player.transform.position;
SceneSettings.Instance.GearNode.position = playerViewUnity.transform.position;
yield return 1;
var obj = new GameObject($"rod_{itemInfo.Id}_{itemInfo.ConfigId}");
obj.transform.SetParent(SceneSettings.Instance.GearNode);
// obj.transform.SetParent(player.transform);
// obj.transform.localPosition = Vector3.zero;
obj.transform.position = player.transform.position;
obj.transform.rotation = player.transform.rotation;
obj.transform.position = playerViewUnity.transform.position;
obj.transform.rotation = playerViewUnity.transform.rotation;
obj.transform.localScale = Vector3.one;
GearRoot = obj.transform;
@@ -205,39 +208,39 @@ namespace NBF
Reel.transform.SetParent(Asset.ReelConnector);
Reel.transform.localPosition = Vector3.zero;
Reel.transform.localEulerAngles = Vector3.zero;
Reel.Init(player, this);
Reel.Init(this);
}
if (Bobber)
{
Bobber.Init(Player, this);
Bobber.Init(this);
}
if (Hook)
{
Hook.Init(Player, this);
Hook.Init(this);
}
if (Bait)
{
Bait.Init(Player, this);
Bait.Init(this);
}
if (Lure)
{
Lure.Init(Player, this);
Lure.Init(this);
}
if (Weight)
{
Weight.Init(Player, this);
Weight.Init(this);
}
yield return 1; //等待1帧
transform.SetParent(Player.ModelAsset.RodRoot);
transform.SetParent(playerViewUnity.ModelAsset.RodRoot);
transform.localPosition = Vector3.zero;
transform.rotation = Player.ModelAsset.RodRoot.rotation;
transform.rotation = playerViewUnity.ModelAsset.RodRoot.rotation;
Usable = true;
}
@@ -281,7 +284,7 @@ namespace NBF
Line = obj.GetComponent<FLine>();
Line.transform.position = Asset.lineConnector.position;
Line.Init(this.Player, this);
Line.Init(this);
// var obiSolver = solver.GetComponent<ObiSolver>();
// obiSolver.parameters.ambientWind = Vector3.zero;

View File

@@ -32,9 +32,9 @@ namespace NBF
{
await LoginHelper.Login(InputAccount.text);
// await Fishing.Instance.Go(RoleModel.Instance.Info.MapId);
await Fishing.Instance.Go(RoleModel.Instance.Info.MapId);
ChatTestPanel.Show();
// ChatTestPanel.Show();
// FishingShopPanel.Show();