Files
2026-03-04 10:03:45 +08:00

191 lines
4.9 KiB
C#

using Obi;
using UFS2.Gameplay;
using UFS2.Helpers;
using UnityEngine;
using UnityEngine.Events;
public class FFishingLine : MonoBehaviour
{
private Rigidbody toRodConnector;
[Tooltip("0-One segment, 1- Two segment, 2-There segment")]
public GameObject[] ObiLinePrefab;
public Transform[] rodLinePoints;
[HideInInspector]
public FLineHandler currentLineHandler;
[HideInInspector]
public LineRenderer lineRenderer;
public float lineStrenght = 1f;
public float currentLineStrenght;
private float currentLineTension;
public float linelenghtDiferent;
public float ropeToHookDistance;
[HideInInspector]
public ObiLateFixedUpdater obiFixedUpdater;
[HideInInspector]
public ObiSolver obiSolver;
private int currentLineTypeIndex;
[HideInInspector]
public FRod rod;
private Transform waterPlane;
public UnityEvent OnLineCut;
public float CurrentLineTension
{
get
{
return currentLineTension;
}
set
{
currentLineTension = value;
}
}
private void Start()
{
obiFixedUpdater = Object.FindObjectOfType<ObiLateFixedUpdater>();
rod = GetComponent<FRod>();
lineRenderer = GetComponent<LineRenderer>();
toRodConnector = rodLinePoints[0].GetComponent<Rigidbody>();
}
private void OnGUI()
{
if (GameManager.IsDevModeAllowed && (bool)RefferenceHelper.GetCurrentLineHandler())
{
string text = $"Tension: {CurrentLineTension}\n RopeLength: {currentLineHandler.GetRopeLenght()}\n LineDiferent: {GetLineDiferent()}";
if (!(Camera.main == null))
{
Vector3 vector = new Vector3(155f, 255f);
Vector2 vector2 = GUI.skin.label.CalcSize(new GUIContent(text));
GUI.Label(new Rect(vector.x, (float)Screen.height - vector.y, vector2.x, vector2.y), text);
}
}
}
private void Update()
{
if ((bool)currentLineHandler)
{
linelenghtDiferent = GetLineDiferent();
ropeToHookDistance = Vector3.Distance(toRodConnector.transform.position, currentLineHandler.LineConnector_1.transform.position);
if ((bool)currentLineHandler)
{
currentLineHandler.LineConnector_0.transform.position = toRodConnector.transform.position;
}
float num = rod.maxRodStrength * 0.01f;
currentLineStrenght = Mathf.Clamp01(linelenghtDiferent) * (lineStrenght + num);
if ((bool)rod && !FishEntity.CurrentFishInFight)
{
CurrentLineTension = Mathf.Clamp(linelenghtDiferent, 0f, 0.05f);
}
}
}
private void LineWaterDisplacement()
{
if ((bool)currentLineHandler && (bool)waterPlane)
{
for (int i = 0; i < currentLineHandler.obiRopeSegment_1.activeParticleCount; i++)
{
_ = currentLineHandler.obiRopeSegment_1.GetParticlePosition(i).y;
_ = waterPlane.position.y;
}
}
}
public void RenderLine()
{
if (!currentLineHandler)
{
return;
}
int num = 0;
bool isBlockLineByFinger = rod.currentReel.isBlockLineByFinger;
if (rod.currentReel.isBailOpen && isBlockLineByFinger && rod.currentReel.type == FReel.Type.Normal)
{
lineRenderer.positionCount = rodLinePoints.Length + 3;
}
else
{
lineRenderer.positionCount = rodLinePoints.Length + 2;
}
lineRenderer.SetPosition(num, rod.currentReel.szpulaCenterPoint.position);
num++;
if (rod.currentReel.isBailOpen && rod.currentReel.type == FReel.Type.Normal)
{
lineRenderer.SetPosition(num, rod.currentReel.linePointSzpula.position);
num++;
if (isBlockLineByFinger)
{
lineRenderer.SetPosition(num, rod.currentReel.lineFingerPoint.position);
num++;
}
}
else
{
lineRenderer.SetPosition(num, rod.currentReel.linePointRoter.position);
num++;
}
for (int num2 = rodLinePoints.Length; num2 > 0; num2--)
{
lineRenderer.SetPosition(num, rodLinePoints[num2 - 1].position);
num++;
}
}
public void CreateObiFishingLine(int currentLineTypeIndex)
{
if ((bool)rod.currentReel && !currentLineHandler)
{
GameObject gameObject = Object.Instantiate(ObiLinePrefab[currentLineTypeIndex], toRodConnector.transform.position, Quaternion.identity, obiFixedUpdater.transform);
currentLineHandler = gameObject.GetComponent<FLineHandler>();
currentLineHandler.currentRodFishingLineComponent = this;
currentLineHandler.transform.position = toRodConnector.transform.position;
currentLineHandler.LineConnector_0.connectedBody = toRodConnector;
obiSolver = currentLineHandler.GetComponent<ObiSolver>();
obiFixedUpdater.solvers.Add(obiSolver);
}
}
public void DestroyObiLine()
{
if ((bool)currentLineHandler)
{
ObiSolver component = currentLineHandler.GetComponent<ObiSolver>();
obiFixedUpdater.solvers.Remove(component);
Object.Destroy(currentLineHandler.gameObject);
currentLineHandler = null;
}
}
private float GetLineDiferent()
{
if (!currentLineHandler)
{
return 0f;
}
return Vector3.Distance(currentLineHandler.LineConnector_1.transform.position, toRodConnector.transform.position) - currentLineHandler.ObiLineOut;
}
public float GetTension(float weight)
{
return weight * GetLineDiferent();
}
}