80 lines
1.6 KiB
C#
80 lines
1.6 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
internal class FishBaitEvaluator
|
|
{
|
|
private class Element
|
|
{
|
|
public AnimationCurve curve;
|
|
|
|
public float minRange;
|
|
|
|
public float maxRange;
|
|
|
|
public float weight;
|
|
|
|
public float minValue;
|
|
|
|
public float maxValue;
|
|
|
|
public string name;
|
|
|
|
public float curveTime = float.NaN;
|
|
|
|
public Element(string name, AnimationCurve curve, float minRange, float maxRange, float weight, float minValue, float maxValue)
|
|
{
|
|
this.name = name;
|
|
this.curve = curve;
|
|
this.minRange = minRange;
|
|
this.maxRange = maxRange;
|
|
this.weight = weight;
|
|
this.minValue = minValue;
|
|
this.maxValue = maxValue;
|
|
}
|
|
}
|
|
|
|
private List<Element> elements = new List<Element>();
|
|
|
|
public void AddElement(string name, AnimationCurve c, float minRange, float maxRange, float weight, float minValue = float.MinValue, float maxValue = float.MinValue)
|
|
{
|
|
elements.Add(new Element(name, c, minRange, maxRange, weight, minValue, maxValue));
|
|
}
|
|
|
|
public void SetCurveTime(string name, float curveTime)
|
|
{
|
|
foreach (Element element in elements)
|
|
{
|
|
if (element.name == name)
|
|
{
|
|
element.curveTime = curveTime;
|
|
return;
|
|
}
|
|
}
|
|
Debug.LogWarning("field " + name + " not found");
|
|
}
|
|
|
|
public float Evaluate()
|
|
{
|
|
float num = 0f;
|
|
float num2 = 0f;
|
|
foreach (Element element in elements)
|
|
{
|
|
if (!float.IsNaN(element.curveTime))
|
|
{
|
|
float num3 = element.curve.Evaluate(element.curveTime);
|
|
num += num3 * element.weight;
|
|
num2 += element.weight;
|
|
}
|
|
}
|
|
return num / num2;
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
foreach (Element element in elements)
|
|
{
|
|
element.curveTime = float.NaN;
|
|
}
|
|
}
|
|
}
|