Skip to content

Instantly share code, notes, and snippets.

@deivid-01
Last active April 12, 2021 02:38
Show Gist options
  • Select an option

  • Save deivid-01/04ba1ac6cf67bb588a7b6269a67032e3 to your computer and use it in GitHub Desktop.

Select an option

Save deivid-01/04ba1ac6cf67bb588a7b6269a67032e3 to your computer and use it in GitHub Desktop.
Curve analyzer for AnimationCurve in Unity
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CurveAnalizer : MonoBehaviour
{
public AnimationCurve curve;
float mean = 0;
float std = 0;
void Start()
{
mean = Mean(curve);
std = Std(curve);
print($"Mean: {mean}");
print($"Std: {std}");
}
// Update is called once per frame
float Mean(AnimationCurve curve)
{
float sum = 0;
for (int i = 0; i < curve.keys.Length; i++)
{
sum += curve.keys[i].value;
}
return sum /(float) curve.keys.Length;
}
float Std(AnimationCurve curve)
{
float sum = 0;
for (int i = 0; i < curve.keys.Length; i++)
{
sum += ((curve.keys[i].value -mean)* (curve.keys[i].value - mean));
}
return Mathf.Sqrt(sum/curve.keys.Length);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment