首次提交
This commit is contained in:
94
Assets/Scripts/Common/Utils/FishWeightToLength.cs
Normal file
94
Assets/Scripts/Common/Utils/FishWeightToLength.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class FishWeightToLength : MonoBehaviour
|
||||
{
|
||||
[Serializable]
|
||||
public class FishWeightData
|
||||
{
|
||||
[SerializeField] private string FishName = "Nazwa rybki";
|
||||
|
||||
public FishSpecies species;
|
||||
|
||||
[Tooltip("X - waga ryby, Y - centymetry")]
|
||||
public Vector2[] weightLenghtValues;
|
||||
|
||||
public AnimationCurve weightLengthCurve;
|
||||
|
||||
public void SetupCurvesWeight()
|
||||
{
|
||||
weightLengthCurve.keys = null;
|
||||
for (int i = 0; i < weightLenghtValues.Length; i++)
|
||||
{
|
||||
weightLengthCurve.AddKey(weightLenghtValues[i].x, weightLenghtValues[i].y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static FishWeightToLength instance;
|
||||
|
||||
[SerializeField] [Tooltip("Uzywac tylko w edytorze")]
|
||||
private bool isEditMode = true;
|
||||
|
||||
public FishWeightData[] fishWeightData;
|
||||
|
||||
[Tooltip("Testowanie poprawnosci konwersji waga/centymetry")] [SerializeField]
|
||||
private FishSpecies TestSpecies;
|
||||
|
||||
[SerializeField] private float TestWeight;
|
||||
|
||||
[SerializeField] private float TestWynikCentymetry;
|
||||
|
||||
public static FishWeightToLength Instance => instance;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
DontDestroyOnLoad(this);
|
||||
if (instance == null)
|
||||
{
|
||||
instance = this;
|
||||
}
|
||||
else if (instance != this)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!isEditMode)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < fishWeightData.Length; i++)
|
||||
{
|
||||
fishWeightData[i].SetupCurvesWeight();
|
||||
if (TestSpecies == fishWeightData[i].species)
|
||||
{
|
||||
TestWynikCentymetry = fishWeightData[i].weightLengthCurve.Evaluate(TestWeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public float ConvertWeightFishToLength(FishSpecies species, float weight)
|
||||
{
|
||||
for (int i = 0; i < fishWeightData.Length; i++)
|
||||
{
|
||||
if (fishWeightData[i].species == species)
|
||||
{
|
||||
fishWeightData[i].SetupCurvesWeight();
|
||||
return fishWeightData[i].weightLengthCurve.Evaluate(weight);
|
||||
}
|
||||
}
|
||||
|
||||
return 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user