完成基本代码迁移重构
This commit is contained in:
@@ -2,13 +2,14 @@
|
|||||||
using Fantasy;
|
using Fantasy;
|
||||||
using Fantasy.Entitas;
|
using Fantasy.Entitas;
|
||||||
using NBF.Utils;
|
using NBF.Utils;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace NBF
|
namespace NBF
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 玩家物品
|
/// 玩家物品
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class PlayerItem : Entity
|
public class PlayerItem : Entity
|
||||||
{
|
{
|
||||||
public Player Owner;
|
public Player Owner;
|
||||||
|
|
||||||
@@ -17,11 +18,47 @@ namespace NBF
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public int ConfigID;
|
public int ConfigID;
|
||||||
|
|
||||||
|
public List<int> BindItems = new List<int>();
|
||||||
|
|
||||||
public virtual void Init(Player player, ItemInfo bindInfo)
|
#region Rod专属
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 线长度
|
||||||
|
/// </summary>
|
||||||
|
public float LineLength = 1.5f;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 浮漂线长度
|
||||||
|
/// </summary>
|
||||||
|
public float FloatLength = 0.5f;
|
||||||
|
|
||||||
|
private float _tension;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 拉力
|
||||||
|
/// </summary>
|
||||||
|
public float Tension
|
||||||
|
{
|
||||||
|
get => _tension;
|
||||||
|
private set
|
||||||
|
{
|
||||||
|
if (!Mathf.Approximately(_tension, value))
|
||||||
|
{
|
||||||
|
_tension = value;
|
||||||
|
// OnTensionChanged?.Invoke(_tension);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
public void Init(Player player, int configId, List<int> bindItems)
|
||||||
{
|
{
|
||||||
Owner = player;
|
Owner = player;
|
||||||
ConfigID = bindInfo.ConfigId;
|
ConfigID = configId;
|
||||||
|
BindItems.Clear();
|
||||||
|
BindItems.AddRange(bindItems);
|
||||||
// var itemType = bindInfo.Item.GetItemType();
|
// var itemType = bindInfo.Item.GetItemType();
|
||||||
// if (itemType == ItemType.Rod)
|
// if (itemType == ItemType.Rod)
|
||||||
// {
|
// {
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 9e0846296bef4505868010bfe1eee1e3
|
|
||||||
timeCreated: 1773124278
|
|
||||||
@@ -103,18 +103,13 @@ namespace NBF
|
|||||||
ItemChangeEvent(prevItem);
|
ItemChangeEvent(prevItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UseItem(ItemInfo item)
|
public void UseItem(int configId, List<int> bindItems)
|
||||||
{
|
{
|
||||||
var prevItem = HandItem;
|
var prevItem = HandItem;
|
||||||
var itemType = item.ConfigId.GetItemType();
|
var playerItemRod = Create<PlayerItem>(Scene);
|
||||||
if (itemType == ItemType.Rod)
|
playerItemRod.Init(this, configId, bindItems);
|
||||||
{
|
Items[playerItemRod.Id] = playerItemRod;
|
||||||
var playerItemRod = Create<PlayerItemRod>(Scene);
|
HandItemId = playerItemRod.Id;
|
||||||
playerItemRod.Init(this, item);
|
|
||||||
Items[playerItemRod.Id] = playerItemRod;
|
|
||||||
HandItemId = playerItemRod.Id;
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemChangeEvent(prevItem);
|
ItemChangeEvent(prevItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
using Fantasy.Async;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace NBF
|
|
||||||
{
|
|
||||||
public class PlayerItemRodView : PlayerItemView
|
|
||||||
{
|
|
||||||
public RodAsset RodAsset;
|
|
||||||
|
|
||||||
public override async FTask InitShow(PlayerItem item)
|
|
||||||
{
|
|
||||||
Item = item;
|
|
||||||
var itemConfig = Game.Tables.TbItem.Get(Item.ConfigID);
|
|
||||||
RodAsset = itemConfig.InstantiateAndComponent<RodAsset>(SceneSettings.Instance.GearNode, Vector3.zero,
|
|
||||||
Quaternion.identity);
|
|
||||||
|
|
||||||
// await Rod.InitRod(Item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 77390e0ed53847f3b190ffc0d9f1319a
|
|
||||||
timeCreated: 1773124629
|
|
||||||
@@ -7,21 +7,22 @@ namespace NBF
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 玩家物品视图组件
|
/// 玩家物品视图组件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class PlayerItemView : Entity
|
public class PlayerItemView : Entity
|
||||||
{
|
{
|
||||||
public PlayerItem Item { get; protected set; }
|
public PlayerItem Item { get; protected set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 竿子
|
||||||
|
/// </summary>
|
||||||
|
public FRod Rod { get; private set; }
|
||||||
|
|
||||||
public abstract FTask InitShow(PlayerItem item);
|
public async FTask InitShow(PlayerItem item)
|
||||||
|
{
|
||||||
// public async FTask InitShow()
|
Item = item;
|
||||||
// {
|
var itemConfig = Game.Tables.TbItem.Get(Item.ConfigID);
|
||||||
// // Item = GetParent<PlayerItem>();
|
Rod = itemConfig.InstantiateAndComponent<FRod>(SceneSettings.Instance.GearNode, Vector3.zero,
|
||||||
// var itemConfig = Game.Tables.TbItem.Get(Item.ConfigID);
|
Quaternion.identity);
|
||||||
// // Rod = itemConfig.InstantiateAndComponent<FRod>(SceneSettings.Instance.GearNode, Vector3.zero,
|
await Rod.InitRod(Item);
|
||||||
// // Quaternion.identity);
|
}
|
||||||
//
|
|
||||||
// // await Rod.InitRod(Item);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
using Fantasy;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Fantasy;
|
||||||
using Fantasy.Entitas;
|
using Fantasy.Entitas;
|
||||||
using Fantasy.Entitas.Interface;
|
using Fantasy.Entitas.Interface;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@@ -90,7 +92,9 @@ namespace NBF
|
|||||||
var item = RoleModel.Instance.GetSlotItem(index - 1);
|
var item = RoleModel.Instance.GetSlotItem(index - 1);
|
||||||
if (item != null)
|
if (item != null)
|
||||||
{
|
{
|
||||||
Player.UseItem(item);
|
List<ItemInfo> children = RoleModel.Instance.GetBindItems(item.Id);
|
||||||
|
List<int> bindItems = children.Select(itemInfo => itemInfo.ConfigId).ToList();
|
||||||
|
Player.UseItem(item.ConfigId, bindItems);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ namespace NBF
|
|||||||
var itemType = handItem.ConfigID.GetItemType();
|
var itemType = handItem.ConfigID.GetItemType();
|
||||||
if (itemType == ItemType.Rod)
|
if (itemType == ItemType.Rod)
|
||||||
{
|
{
|
||||||
var itemView = handItem.GetOrAddComponent<PlayerItemRodView>();
|
var itemView = handItem.GetOrAddComponent<PlayerItemView>();
|
||||||
await itemView.InitShow(handItem);
|
await itemView.InitShow(handItem);
|
||||||
Unity.ModelAsset.PlayerAnimator.OnUseItem(itemView);
|
Unity.ModelAsset.PlayerAnimator.OnUseItem(itemView);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
namespace NBF
|
namespace NBF
|
||||||
{
|
{
|
||||||
public class FHandItem : MonoBehaviour
|
public abstract class FHandItem : MonoBehaviour
|
||||||
{
|
{
|
||||||
public int ConfigId;
|
public abstract int ConfigId { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,7 +14,10 @@ namespace NBF
|
|||||||
{
|
{
|
||||||
private float _tension;
|
private float _tension;
|
||||||
|
|
||||||
|
public PlayerItem PlayerItem;
|
||||||
|
|
||||||
|
public override int ConfigId => PlayerItem?.ConfigID ?? 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 可用的
|
/// 可用的
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -126,123 +129,122 @@ namespace NBF
|
|||||||
|
|
||||||
public async FTask InitRod(PlayerItem playerItem)
|
public async FTask InitRod(PlayerItem playerItem)
|
||||||
{
|
{
|
||||||
// ConfigId = itemBindInfo.Item;
|
PlayerItem = playerItem;
|
||||||
// // Player = player;
|
|
||||||
//
|
var playerView = playerItem.Owner.GetComponent<PlayerView>();
|
||||||
// var playerView = player.GetComponent<PlayerView>();
|
|
||||||
//
|
var playerViewUnity = playerView.Unity;
|
||||||
// var playerViewUnity = playerView.Unity;
|
|
||||||
//
|
transform.localPosition = Vector3.zero;
|
||||||
// transform.localPosition = Vector3.zero;
|
transform.localRotation = Quaternion.identity;
|
||||||
// transform.localRotation = Quaternion.identity;
|
transform.localScale = Vector3.one;
|
||||||
// transform.localScale = Vector3.one;
|
SceneSettings.Instance.GearNode.position = playerViewUnity.transform.position;
|
||||||
// SceneSettings.Instance.GearNode.position = playerViewUnity.transform.position;
|
await FTask.WaitFrame(playerView.Scene); //等待1帧
|
||||||
// yield return 1;
|
|
||||||
// var obj = new GameObject($"rod_{ConfigId}");
|
var obj = new GameObject($"rod_{ConfigId}");
|
||||||
// obj.transform.SetParent(SceneSettings.Instance.GearNode);
|
obj.transform.SetParent(SceneSettings.Instance.GearNode);
|
||||||
// // obj.transform.SetParent(player.transform);
|
// obj.transform.SetParent(player.transform);
|
||||||
// // obj.transform.localPosition = Vector3.zero;
|
// obj.transform.localPosition = Vector3.zero;
|
||||||
// obj.transform.position = playerViewUnity.transform.position;
|
obj.transform.position = playerViewUnity.transform.position;
|
||||||
// obj.transform.rotation = playerViewUnity.transform.rotation;
|
obj.transform.rotation = playerViewUnity.transform.rotation;
|
||||||
// obj.transform.localScale = Vector3.one;
|
obj.transform.localScale = Vector3.one;
|
||||||
// GearRoot = obj.transform;
|
GearRoot = obj.transform;
|
||||||
//
|
|
||||||
// var parent = GearRoot;
|
var parent = GearRoot;
|
||||||
//
|
|
||||||
// // List<ItemInfo> children = RoleModel.Instance.GetBindItems(itemInfo.Id);
|
// List<ItemInfo> children = RoleModel.Instance.GetBindItems(itemInfo.Id);
|
||||||
//
|
|
||||||
//
|
CreateFishingHandler();
|
||||||
// CreateFishingHandler();
|
await FTask.WaitFrame(playerView.Scene); //等待1帧
|
||||||
// yield return 1; //等待1帧
|
// children.Sort();
|
||||||
// // children.Sort();
|
foreach (var childConfigId in playerItem.BindItems)
|
||||||
// foreach (var childConfigId in itemBindInfo.BindItems)
|
{
|
||||||
// {
|
var itemType = childConfigId.GetItemType();
|
||||||
// var itemType = childConfigId.GetItemType();
|
var config = Game.Tables.TbItem.Get(childConfigId);
|
||||||
// var config = Game.Tables.TbItem.Get(childConfigId);
|
if (itemType == ItemType.Reel)
|
||||||
// if (itemType == ItemType.Reel)
|
{
|
||||||
// {
|
Reel = config.InstantiateAndComponent<FReel>(Asset.ReelConnector, Vector3.zero,
|
||||||
// Reel = config.InstantiateAndComponent<FReel>(Asset.ReelConnector, Vector3.zero,
|
Quaternion.identity);
|
||||||
// Quaternion.identity);
|
Reel.SetItemConfigId(childConfigId);
|
||||||
// Reel.SetItemConfigId(childConfigId);
|
}
|
||||||
// }
|
else if (itemType == ItemType.Bobber)
|
||||||
// else if (itemType == ItemType.Bobber)
|
{
|
||||||
// {
|
Bobber = config.InstantiateAndComponent<FBobber>(parent, Vector3.zero,
|
||||||
// Bobber = config.InstantiateAndComponent<FBobber>(parent, Vector3.zero,
|
Quaternion.identity);
|
||||||
// Quaternion.identity);
|
Bobber.SetItemConfigId(childConfigId);
|
||||||
// Bobber.SetItemConfigId(childConfigId);
|
}
|
||||||
// }
|
else if (itemType == ItemType.Hook)
|
||||||
// else if (itemType == ItemType.Hook)
|
{
|
||||||
// {
|
Hook = config.InstantiateAndComponent<FHook>(parent, Vector3.zero,
|
||||||
// Hook = config.InstantiateAndComponent<FHook>(parent, Vector3.zero,
|
Quaternion.identity);
|
||||||
// Quaternion.identity);
|
Hook.SetItemConfigId(childConfigId);
|
||||||
// Hook.SetItemConfigId(childConfigId);
|
}
|
||||||
// }
|
else if (itemType == ItemType.Bait)
|
||||||
// else if (itemType == ItemType.Bait)
|
{
|
||||||
// {
|
Bait = config.InstantiateAndComponent<FBait>(parent, Vector3.zero,
|
||||||
// Bait = config.InstantiateAndComponent<FBait>(parent, Vector3.zero,
|
Quaternion.identity);
|
||||||
// Quaternion.identity);
|
Bait.SetItemConfigId(childConfigId);
|
||||||
// Bait.SetItemConfigId(childConfigId);
|
}
|
||||||
// }
|
else if (itemType == ItemType.Lure)
|
||||||
// else if (itemType == ItemType.Lure)
|
{
|
||||||
// {
|
Lure = config.InstantiateAndComponent<FLure>(parent, Vector3.zero,
|
||||||
// Lure = config.InstantiateAndComponent<FLure>(parent, Vector3.zero,
|
Quaternion.identity);
|
||||||
// Quaternion.identity);
|
Lure.SetItemConfigId(childConfigId);
|
||||||
// Lure.SetItemConfigId(childConfigId);
|
}
|
||||||
// }
|
else if (itemType == ItemType.Weight)
|
||||||
// else if (itemType == ItemType.Weight)
|
{
|
||||||
// {
|
Weight = config.InstantiateAndComponent<FWeight>(parent, Vector3.zero,
|
||||||
// Weight = config.InstantiateAndComponent<FWeight>(parent, Vector3.zero,
|
Quaternion.identity);
|
||||||
// Quaternion.identity);
|
Weight.SetItemConfigId(childConfigId);
|
||||||
// Weight.SetItemConfigId(childConfigId);
|
}
|
||||||
// }
|
else if (itemType == ItemType.Line)
|
||||||
// else if (itemType == ItemType.Line)
|
{
|
||||||
// {
|
// lineItemInfo = child;
|
||||||
// // lineItemInfo = child;
|
}
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
//
|
await FTask.WaitFrame(playerView.Scene); //等待1帧
|
||||||
// yield return 1;
|
if (Reel)
|
||||||
// if (Reel)
|
{
|
||||||
// {
|
Reel.reelingDrag = 0.699f;
|
||||||
// Reel.reelingDrag = 0.699f;
|
Reel.transform.SetParent(Asset.ReelConnector);
|
||||||
// Reel.transform.SetParent(Asset.ReelConnector);
|
Reel.transform.localPosition = Vector3.zero;
|
||||||
// Reel.transform.localPosition = Vector3.zero;
|
Reel.transform.localEulerAngles = Vector3.zero;
|
||||||
// Reel.transform.localEulerAngles = Vector3.zero;
|
Reel.Init(this);
|
||||||
// Reel.Init(this);
|
}
|
||||||
// }
|
|
||||||
//
|
if (Bobber)
|
||||||
// if (Bobber)
|
{
|
||||||
// {
|
Bobber.Init(this);
|
||||||
// Bobber.Init(this);
|
}
|
||||||
// }
|
|
||||||
//
|
if (Hook)
|
||||||
// if (Hook)
|
{
|
||||||
// {
|
Hook.Init(this);
|
||||||
// Hook.Init(this);
|
}
|
||||||
// }
|
|
||||||
//
|
if (Bait)
|
||||||
// if (Bait)
|
{
|
||||||
// {
|
Bait.Init(this);
|
||||||
// Bait.Init(this);
|
}
|
||||||
// }
|
|
||||||
//
|
if (Lure)
|
||||||
// if (Lure)
|
{
|
||||||
// {
|
Lure.Init(this);
|
||||||
// Lure.Init(this);
|
}
|
||||||
// }
|
|
||||||
//
|
if (Weight)
|
||||||
// if (Weight)
|
{
|
||||||
// {
|
Weight.Init(this);
|
||||||
// Weight.Init(this);
|
}
|
||||||
// }
|
|
||||||
//
|
await FTask.WaitFrame(playerView.Scene); //等待1帧
|
||||||
// yield return 1; //等待1帧
|
|
||||||
//
|
transform.SetParent(playerViewUnity.ModelAsset.RodRoot);
|
||||||
// transform.SetParent(playerViewUnity.ModelAsset.RodRoot);
|
transform.localPosition = Vector3.zero;
|
||||||
// transform.localPosition = Vector3.zero;
|
transform.rotation = playerViewUnity.ModelAsset.RodRoot.rotation;
|
||||||
// transform.rotation = playerViewUnity.ModelAsset.RodRoot.rotation;
|
|
||||||
//
|
Usable = true;
|
||||||
// Usable = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -286,11 +288,6 @@ namespace NBF
|
|||||||
Line = obj.GetComponent<FLine>();
|
Line = obj.GetComponent<FLine>();
|
||||||
Line.transform.position = Asset.lineConnector.position;
|
Line.transform.position = Asset.lineConnector.position;
|
||||||
Line.Init(this);
|
Line.Init(this);
|
||||||
|
|
||||||
// var obiSolver = solver.GetComponent<ObiSolver>();
|
|
||||||
// obiSolver.parameters.ambientWind = Vector3.zero;
|
|
||||||
// obiSolver.wind.
|
|
||||||
// obiSolver.simulateWhenInvisible
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user