86 lines
2.8 KiB
C#
86 lines
2.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Obi;
|
|
using UFS3;
|
|
using UnityEngine;
|
|
|
|
public class FishingLineManager : MonoBehaviourSingleton<FishingLineManager>
|
|
{
|
|
[SerializeField] private ObiSolver solverTemplate;
|
|
|
|
[SerializeField] private FishingLine setSpinningObj;
|
|
|
|
[SerializeField] private FishingLine setFloatLineObj;
|
|
|
|
private FishingLine currentLine;
|
|
|
|
[SerializeField] private ObiUpdater _ObiUpdater;
|
|
|
|
public event Action<FishingLine> OnFishingLineCreated;
|
|
|
|
public void CreateLine(LineType lineType, List<Transform> rodGuides, FishingSetController fishingSet)
|
|
{
|
|
_ObiUpdater.gameObject.SetActive(value: false);
|
|
Rigidbody rodTipBone = fishingSet.AttachedRod.RodTipBone;
|
|
_ = fishingSet.AttachedRod.transform;
|
|
ObiSolver obiSolver = UnityEngine.Object.Instantiate(solverTemplate);
|
|
obiSolver.transform.parent = base.transform;
|
|
fishingSet.Solver = obiSolver;
|
|
_ObiUpdater.gameObject.SetActive(value: true);
|
|
_ObiUpdater.solvers.Add(obiSolver);
|
|
obiSolver.gameObject.SetActive(value: true);
|
|
switch (lineType)
|
|
{
|
|
case LineType.Spinning:
|
|
Set(rodGuides, setSpinningObj, obiSolver.transform, rodTipBone);
|
|
break;
|
|
case LineType.Float:
|
|
Set(rodGuides, setFloatLineObj, obiSolver.transform, rodTipBone);
|
|
break;
|
|
case LineType.Feeder:
|
|
throw new NotImplementedException();
|
|
case LineType.Fly:
|
|
throw new NotImplementedException();
|
|
case LineType.Ice:
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
|
|
public static void KillSolver(ObiSolver solver)
|
|
{
|
|
if (!(MonoBehaviourSingleton<FishingLineManager>.Instance == null))
|
|
{
|
|
MonoBehaviourSingleton<FishingLineManager>.Instance._ObiUpdater.solvers.Remove(solver);
|
|
MonoBehaviourSingleton<FishingLineManager>.Instance._ObiUpdater.gameObject.SetActive(value: false);
|
|
UnityEngine.Object.Destroy(solver.gameObject);
|
|
}
|
|
}
|
|
|
|
private void OnRodGearChanged(BaseItemData obj)
|
|
{
|
|
RodData rodData = (RodData)obj;
|
|
if ((bool)rodData && (bool)rodData.AttachedLine)
|
|
{
|
|
Hide();
|
|
}
|
|
else
|
|
{
|
|
Hide();
|
|
}
|
|
}
|
|
|
|
private void Set(List<Transform> guides, FishingLine setLineObj, Transform parent, Rigidbody rodTip)
|
|
{
|
|
currentLine = UnityEngine.Object.Instantiate(setLineObj, parent);
|
|
currentLine.Initialize(rodTip.transform, rodTip, guides);
|
|
this.OnFishingLineCreated?.Invoke(currentLine);
|
|
}
|
|
|
|
private void Hide()
|
|
{
|
|
if ((bool)currentLine)
|
|
{
|
|
UnityEngine.Object.Destroy(currentLine.gameObject);
|
|
}
|
|
}
|
|
} |