新增脚本
This commit is contained in:
317
Assets/Scripts/Fishing/Tackle/FRod.cs
Normal file
317
Assets/Scripts/Fishing/Tackle/FRod.cs
Normal file
@@ -0,0 +1,317 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Fantasy;
|
||||
using NBC.Asset;
|
||||
using NBF.Utils;
|
||||
using Obi;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class FRod : FHandItem
|
||||
{
|
||||
/// <summary>
|
||||
/// 可用的
|
||||
/// </summary>
|
||||
public bool Usable { get; private set; }
|
||||
|
||||
public RodAsset Asset;
|
||||
|
||||
public FPlayer Player { get; protected set; }
|
||||
public ItemInfo ItemInfo;
|
||||
|
||||
public FReel Reel;
|
||||
public FHook Hook;
|
||||
public FBobber Bobber;
|
||||
public FBait Bait;
|
||||
public FLure Lure;
|
||||
public FWeight Weight;
|
||||
public FLine Line;
|
||||
|
||||
/// <summary>
|
||||
/// 鱼线处理器
|
||||
/// </summary>
|
||||
public FLineHandler lineHandler;
|
||||
|
||||
public Transform GearRoot;
|
||||
|
||||
// public FWaterDisplacement LureHookWaterDisplacement;
|
||||
|
||||
[HideInInspector] public FFish currentFish;
|
||||
public RodRingNode[] rings;
|
||||
|
||||
/// <summary>
|
||||
/// 线长度
|
||||
/// </summary>
|
||||
public float lineLength;
|
||||
|
||||
public float currentLineTension;
|
||||
public float linelenghtDiferent;
|
||||
public float currentLineStrenght;
|
||||
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Asset = GetComponent<RodAsset>();
|
||||
}
|
||||
|
||||
public IEnumerator Destroy()
|
||||
{
|
||||
yield return 1;
|
||||
}
|
||||
|
||||
public IEnumerator InitRod(FPlayer player, ItemInfo itemInfo)
|
||||
{
|
||||
ItemInfo = itemInfo;
|
||||
Player = player;
|
||||
|
||||
transform.localPosition = Vector3.zero;
|
||||
transform.localRotation = Quaternion.identity;
|
||||
transform.localScale = Vector3.one;
|
||||
yield return 1;
|
||||
var obj = new GameObject($"rod_{itemInfo.Id}_{itemInfo.ConfigId}");
|
||||
obj.transform.SetParent(SceneSettings.Instance.GearNode);
|
||||
// obj.transform.localPosition = Vector3.zero;
|
||||
obj.transform.position = player.transform.position;
|
||||
obj.transform.rotation = player.transform.rotation;
|
||||
obj.transform.localScale = Vector3.one;
|
||||
GearRoot = obj.transform;
|
||||
|
||||
var parent = GearRoot;
|
||||
|
||||
CreateFishingHandler();
|
||||
|
||||
List<ItemInfo> children = RoleModel.Instance.GetBindItems(itemInfo.Id);
|
||||
// children.Sort();
|
||||
foreach (var child in children)
|
||||
{
|
||||
var itemType = child.ConfigId.GetItemType();
|
||||
if (itemType == ItemType.Reel)
|
||||
{
|
||||
Reel = child.Config.InstantiateAndComponent<FReel>(Asset.ReelConnector, Vector3.zero,
|
||||
Quaternion.identity);
|
||||
Reel.SetItemInfo(child);
|
||||
}
|
||||
else if (itemType == ItemType.Bobber)
|
||||
{
|
||||
Bobber = child.Config.InstantiateAndComponent<FBobber>(parent, Vector3.zero,
|
||||
Quaternion.identity);
|
||||
Bobber.SetItemInfo(child);
|
||||
}
|
||||
else if (itemType == ItemType.Hook)
|
||||
{
|
||||
Hook = child.Config.InstantiateAndComponent<FHook>(parent, Vector3.zero,
|
||||
Quaternion.identity);
|
||||
Hook.SetItemInfo(child);
|
||||
}
|
||||
else if (itemType == ItemType.Bait)
|
||||
{
|
||||
Bait = child.Config.InstantiateAndComponent<FBait>(parent, Vector3.zero,
|
||||
Quaternion.identity);
|
||||
Bait.SetItemInfo(child);
|
||||
}
|
||||
else if (itemType == ItemType.Lure)
|
||||
{
|
||||
Lure = child.Config.InstantiateAndComponent<FLure>(parent, Vector3.zero,
|
||||
Quaternion.identity);
|
||||
Lure.SetItemInfo(child);
|
||||
}
|
||||
else if (itemType == ItemType.Weight)
|
||||
{
|
||||
Weight = child.Config.InstantiateAndComponent<FWeight>(parent, Vector3.zero,
|
||||
Quaternion.identity);
|
||||
Weight.SetItemInfo(child);
|
||||
}
|
||||
}
|
||||
|
||||
yield return 1;
|
||||
if (Reel)
|
||||
{
|
||||
Reel.reelingDrag = 0.699f;
|
||||
Reel.transform.SetParent(Asset.ReelConnector);
|
||||
Reel.transform.localPosition = Vector3.zero;
|
||||
Reel.transform.localEulerAngles = Vector3.zero;
|
||||
Reel.Init(player, this);
|
||||
}
|
||||
|
||||
if (Bobber)
|
||||
{
|
||||
Bobber.Init(Player, this);
|
||||
Bobber.transform.position = lineHandler.LineConnector_1.transform.position;
|
||||
Bobber.gameObject.GetComponent<ConfigurableJoint>().connectedBody =
|
||||
lineHandler.LineConnector_1.GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
if (Hook)
|
||||
{
|
||||
Hook.Init(Player, this);
|
||||
Hook.transform.position = lineHandler.LineConnector_2.transform.position;
|
||||
Hook.transform.rotation = lineHandler.LineConnector_2.transform.rotation; // 确保旋转也同步
|
||||
var target = lineHandler.LineConnector_2.GetComponent<Rigidbody>();
|
||||
var joint = Hook.gameObject.GetComponent<ConfigurableJoint>();
|
||||
joint.connectedBody = target;
|
||||
// LureHookWaterDisplacement = Hook.GetComponent<FWaterDisplacement>();
|
||||
}
|
||||
|
||||
if (Bait)
|
||||
{
|
||||
Bait.Init(Player, this);
|
||||
Bait.transform.position = Hook.hookAsset.baitConnector.position;
|
||||
Bait.transform.SetParent(Hook.hookAsset.baitConnector);
|
||||
}
|
||||
|
||||
if (Lure)
|
||||
{
|
||||
Lure.Init(Player, this);
|
||||
Lure.transform.position = lineHandler.LineConnector_1.transform.position;
|
||||
Lure.gameObject.GetComponent<ConfigurableJoint>().connectedBody =
|
||||
lineHandler.LineConnector_1.GetComponent<Rigidbody>();
|
||||
// LureHookWaterDisplacement = Lure.GetComponent<FWaterDisplacement>();
|
||||
}
|
||||
|
||||
if (Weight)
|
||||
{
|
||||
Weight.Init(Player, this);
|
||||
}
|
||||
|
||||
yield return 1; //等待1帧
|
||||
transform.SetParent(Player.ModelAsset.RodRoot);
|
||||
transform.localPosition = Vector3.zero;
|
||||
transform.rotation = Player.ModelAsset.RodRoot.rotation;
|
||||
|
||||
Usable = true;
|
||||
}
|
||||
|
||||
|
||||
public void SetRing(RodRingAsset ringAsset)
|
||||
{
|
||||
if (Asset.rings == null || Asset.rings.Length < 1) return;
|
||||
|
||||
var trans = ringAsset.rings;
|
||||
RodRingNode lastRingNode = null;
|
||||
List<RodRingNode> list = new List<RodRingNode>();
|
||||
for (int i = 0; i < Asset.rings.Length; i++)
|
||||
{
|
||||
var ring = Asset.rings[i];
|
||||
if (ring == null)
|
||||
{
|
||||
Log.Error($"ring is null,index={i}");
|
||||
continue;
|
||||
}
|
||||
|
||||
var lastName = ring.name.GetLastString();
|
||||
foreach (var tran in trans)
|
||||
{
|
||||
var ringNode = tran.ring;
|
||||
var lastName2 = ringNode.name.GetLastString();
|
||||
if (lastName != lastName2) continue;
|
||||
list.Add(tran);
|
||||
ringNode.SetParent(ring);
|
||||
ringNode.localPosition = Vector3.zero;
|
||||
ringNode.localRotation = Quaternion.identity;
|
||||
lastRingNode = tran;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (lastRingNode != null)
|
||||
{
|
||||
Asset.lineConnector = lastRingNode.point;
|
||||
}
|
||||
|
||||
rings = list.ToArray();
|
||||
}
|
||||
|
||||
|
||||
public void CreateFishingHandler()
|
||||
{
|
||||
if (lineHandler == null)
|
||||
{
|
||||
Debug.LogError("创建钓组=====");
|
||||
var rodType = (ItemSubType)ItemInfo.Config.Type;
|
||||
if (rodType == ItemSubType.RodTele)
|
||||
{
|
||||
CreateObiFishingLine(0);
|
||||
}
|
||||
else if (rodType == ItemSubType.RodSpine || rodType == ItemSubType.RodBolo)
|
||||
{
|
||||
CreateObiFishingLine(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void CreateObiFishingLine(int currentLineTypeIndex)
|
||||
{
|
||||
// if ((bool)Owner.Gears.Reel && !currentLineHandler)
|
||||
if (!lineHandler)
|
||||
{
|
||||
var indexNames = new[] { "FFishingLine_0", "FFishingLine_1" };
|
||||
var path =
|
||||
$"Assets/ResRaw/Prefabs/{indexNames[currentLineTypeIndex]}.prefab"; //$"GameItemsPrefabs/Lines/{indexNames[currentLineTypeIndex]}";
|
||||
var prefab = Assets.Load<GameObject>(path);
|
||||
|
||||
// var toRodConnector = rodAsset.lineConnector.GetComponent<Rigidbody>();
|
||||
GameObject obj = Instantiate(prefab, GearRoot.position, Quaternion.identity, GearRoot);
|
||||
|
||||
lineHandler = obj.GetComponent<FLineHandler>();
|
||||
// lineHandler.transform.SetParent(toRodConnector.transform);
|
||||
lineHandler.transform.position = Asset.lineConnector.position;
|
||||
lineHandler.LineConnector_0.target = Asset.lineConnector; //.GetComponent<Rigidbody>();
|
||||
// lineHandler.toRodConnector.target = rodAsset.lineConnector;
|
||||
lineHandler.Rod = this;
|
||||
// var obiSolver = lineHandler.GetComponent<ObiSolver>();
|
||||
// SceneSettings.Instance.obiFixedUpdater.solvers.Add(obiSolver);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void RenderLine()
|
||||
{
|
||||
if (!lineHandler)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Reel) return;
|
||||
if (!Asset.lineRenderer) return;
|
||||
|
||||
// var reel = Reel;
|
||||
// int num = 0;
|
||||
// bool isBlockLineByFinger = reel.isBlockLineByFinger;
|
||||
// if (reel.AnimatorCtrl.Unlock && isBlockLineByFinger && reel.reelAsset.type == ReelAsset.Type.Normal)
|
||||
// {
|
||||
// Asset.lineRenderer.positionCount = rings.Length + 3;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Asset.lineRenderer.positionCount = rings.Length + 2;
|
||||
// }
|
||||
//
|
||||
// Asset.lineRenderer.SetPosition(num, reel.reelAsset.lineIntersectHelper.position);
|
||||
// num++;
|
||||
// if (reel.AnimatorCtrl.Unlock && reel.reelAsset.type == ReelAsset.Type.Normal)
|
||||
// {
|
||||
// Asset.lineRenderer.SetPosition(num, reel.reelAsset.lineIntersect.position);
|
||||
// num++;
|
||||
// if (isBlockLineByFinger)
|
||||
// {
|
||||
// // Asset.lineRenderer.SetPosition(num, reel.reelAsset.lineFingerPoint.position);
|
||||
// // num++;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Asset.lineRenderer.SetPosition(num, reel.reelAsset.lineConnector.position);
|
||||
// num++;
|
||||
// }
|
||||
//
|
||||
// for (int num2 = 0; num2 < rings.Length; num2++)
|
||||
// {
|
||||
// Asset.lineRenderer.SetPosition(num, rings[num2].point.position);
|
||||
// num++;
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user