120 lines
2.6 KiB
C#
120 lines
2.6 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
public class FishWeightToLength : MonoBehaviour
|
|
{
|
|
[Serializable]
|
|
public class FishWeightData
|
|
{
|
|
[SerializeField]
|
|
private string FishName = "Nazwa rybki";
|
|
|
|
public GameManager.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 GameManager.FishSpecies TestSpecies;
|
|
|
|
[SerializeField]
|
|
private float TestWeight;
|
|
|
|
[SerializeField]
|
|
private float TestWynikCentymetry;
|
|
|
|
public static FishWeightToLength Instance => instance;
|
|
|
|
private void Awake()
|
|
{
|
|
UnityEngine.Object.DontDestroyOnLoad(this);
|
|
if (instance == null)
|
|
{
|
|
instance = this;
|
|
}
|
|
else if (instance != this)
|
|
{
|
|
UnityEngine.Object.Destroy(base.gameObject);
|
|
}
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
}
|
|
|
|
public AnimationCurve CurrentCurve(GameManager.FishSpecies species)
|
|
{
|
|
FishWeightData[] array = this.fishWeightData;
|
|
foreach (FishWeightData fishWeightData in array)
|
|
{
|
|
if (fishWeightData.species == species)
|
|
{
|
|
return new AnimationCurve
|
|
{
|
|
keys = fishWeightData.weightLengthCurve.keys,
|
|
postWrapMode = fishWeightData.weightLengthCurve.postWrapMode,
|
|
preWrapMode = fishWeightData.weightLengthCurve.preWrapMode
|
|
};
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public Vector2[] CurrentVectorValues(GameManager.FishSpecies species)
|
|
{
|
|
FishWeightData[] array = this.fishWeightData;
|
|
foreach (FishWeightData fishWeightData in array)
|
|
{
|
|
if (fishWeightData.species == species)
|
|
{
|
|
new AnimationCurve
|
|
{
|
|
keys = fishWeightData.weightLengthCurve.keys,
|
|
postWrapMode = fishWeightData.weightLengthCurve.postWrapMode,
|
|
preWrapMode = fishWeightData.weightLengthCurve.preWrapMode
|
|
};
|
|
return fishWeightData.weightLenghtValues;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public float ConvertWeightFishToLength(GameManager.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;
|
|
}
|
|
}
|