修改
This commit is contained in:
3
Assets/Scripts/Fishing/New/Data/Item.meta
Normal file
3
Assets/Scripts/Fishing/New/Data/Item.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c67e0c4e3e30462d88970a3c0b4569e8
|
||||
timeCreated: 1773123725
|
||||
33
Assets/Scripts/Fishing/New/Data/Item/PlayerItem.cs
Normal file
33
Assets/Scripts/Fishing/New/Data/Item/PlayerItem.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.Collections.Generic;
|
||||
using Fantasy;
|
||||
using Fantasy.Entitas;
|
||||
using NBF.Utils;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
/// <summary>
|
||||
/// 玩家物品
|
||||
/// </summary>
|
||||
public abstract class PlayerItem : Entity
|
||||
{
|
||||
public Player Owner;
|
||||
|
||||
/// <summary>
|
||||
/// 配置id
|
||||
/// </summary>
|
||||
public int ConfigID;
|
||||
|
||||
|
||||
public virtual void Init(Player player, ItemInfo bindInfo)
|
||||
{
|
||||
Owner = player;
|
||||
ConfigID = bindInfo.ConfigId;
|
||||
// var itemType = bindInfo.Item.GetItemType();
|
||||
// if (itemType == ItemType.Rod)
|
||||
// {
|
||||
// var rod = AddComponent<PlayerItemRod>();
|
||||
// rod.Init(bindInfo);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
15
Assets/Scripts/Fishing/New/Data/Item/PlayerItemRod.cs
Normal file
15
Assets/Scripts/Fishing/New/Data/Item/PlayerItemRod.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System.Collections.Generic;
|
||||
using Fantasy;
|
||||
using Fantasy.Entitas;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class PlayerItemRod : PlayerItem
|
||||
{
|
||||
public override void Init(Player player, ItemInfo bindInfo)
|
||||
{
|
||||
//var binds = RoleModel.Instance.GetBindItems(item.Id);
|
||||
base.Init(player, bindInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9e0846296bef4505868010bfe1eee1e3
|
||||
timeCreated: 1773124278
|
||||
@@ -2,17 +2,24 @@
|
||||
using System.Collections.Generic;
|
||||
using Fantasy;
|
||||
using Fantasy.Entitas;
|
||||
using NBF.Utils;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class Player : Entity
|
||||
{
|
||||
// ========== 本地状态 ==========
|
||||
/// <summary>
|
||||
/// 是否本地玩家
|
||||
/// </summary>
|
||||
public bool IsLocalPlayer;
|
||||
|
||||
/// <summary>
|
||||
/// 是否切换物品中
|
||||
/// </summary>
|
||||
public bool IsChangeItemIng;
|
||||
|
||||
public bool IsLureRod => false;
|
||||
|
||||
public bool IsSelf => RoleModel.Instance.Id == Id;
|
||||
@@ -61,18 +68,18 @@ namespace NBF
|
||||
/// <summary>
|
||||
/// 当前手持物品
|
||||
/// </summary>
|
||||
public PlayerItem HandItem => Items[HandItemId];
|
||||
public PlayerItem HandItem => Items.GetValueOrDefault(HandItemId);
|
||||
|
||||
#region 初始化
|
||||
|
||||
public void InitPlayer(MapUnitInfo unitInfo)
|
||||
{
|
||||
AddComponent<PlayerViewComponent>();
|
||||
AddComponent<PlayerStateViewComponent>();
|
||||
AddComponent<PlayerView>();
|
||||
AddComponent<PlayerStateView>();
|
||||
if (unitInfo.Id == RoleModel.Instance.Id)
|
||||
{
|
||||
//自己
|
||||
AddComponent<PlayerInputComponent>();
|
||||
AddComponent<PlayerInput>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,29 +87,44 @@ namespace NBF
|
||||
|
||||
#region 物品
|
||||
|
||||
public void UnUseItem()
|
||||
public void ReleaseItem(PlayerItem item)
|
||||
{
|
||||
if (Items.TryGetValue(HandItemId, out var item))
|
||||
if (Items.ContainsValue(item))
|
||||
{
|
||||
Items.Remove(item.Id);
|
||||
item.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public void UnUseItem()
|
||||
{
|
||||
var prevItem = HandItem;
|
||||
HandItemId = 0;
|
||||
ItemChangeEvent();
|
||||
ItemChangeEvent(prevItem);
|
||||
}
|
||||
|
||||
public void UseItem(ItemBindInfo item)
|
||||
public void UseItem(ItemInfo item)
|
||||
{
|
||||
var playerItem = Create<PlayerItem>(Scene);
|
||||
playerItem.Init(item);
|
||||
ItemChangeEvent();
|
||||
}
|
||||
|
||||
private void ItemChangeEvent()
|
||||
{
|
||||
Scene.EventComponent.Publish(new PlayerStateChangeEvent
|
||||
var prevItem = HandItem;
|
||||
var itemType = item.ConfigId.GetItemType();
|
||||
if (itemType == ItemType.Rod)
|
||||
{
|
||||
Player = this
|
||||
var playerItemRod = Create<PlayerItemRod>(Scene);
|
||||
playerItemRod.Init(this, item);
|
||||
Items[playerItemRod.Id] = playerItemRod;
|
||||
HandItemId = playerItemRod.Id;
|
||||
}
|
||||
|
||||
ItemChangeEvent(prevItem);
|
||||
}
|
||||
|
||||
private void ItemChangeEvent(PlayerItem prevItem)
|
||||
{
|
||||
Scene.EventComponent.Publish(new PlayerItemChangeEvent
|
||||
{
|
||||
Player = this,
|
||||
Item = HandItem,
|
||||
PrevItem = prevItem
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
namespace NBF
|
||||
{
|
||||
public struct PlayerStateChangeEvent
|
||||
{
|
||||
public Player Player;
|
||||
}
|
||||
|
||||
public struct PlayerItemChangeEvent
|
||||
{
|
||||
public Player Player;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c10a4d3f5e354dc9a046ddf7219354b2
|
||||
timeCreated: 1773060354
|
||||
@@ -1,25 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Fantasy;
|
||||
using Fantasy.Entitas;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class PlayerItem : Entity
|
||||
{
|
||||
/// <summary>
|
||||
/// 配置id
|
||||
/// </summary>
|
||||
public int ConfigID;
|
||||
|
||||
/// <summary>
|
||||
/// 绑定的子物体
|
||||
/// </summary>
|
||||
public List<int> BindItems = new List<int>();
|
||||
|
||||
public void Init(ItemBindInfo bindInfo)
|
||||
{
|
||||
ConfigID = bindInfo.Item;
|
||||
BindItems.AddRange(bindInfo.BindItems);
|
||||
}
|
||||
}
|
||||
}
|
||||
239
Assets/Scripts/Fishing/New/Data/StateEnterParams.cs
Normal file
239
Assets/Scripts/Fishing/New/Data/StateEnterParams.cs
Normal file
@@ -0,0 +1,239 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class StateParamsConst
|
||||
{
|
||||
public const string ChargedProgress = "ChargedProgress";
|
||||
}
|
||||
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing/New/Data/StateEnterParams.cs.meta
Normal file
3
Assets/Scripts/Fishing/New/Data/StateEnterParams.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a0ff43bbc7dd46b387e62f574ceb2523
|
||||
timeCreated: 1773029210
|
||||
Reference in New Issue
Block a user