Last active
April 12, 2021 02:38
-
-
Save deivid-01/04ba1ac6cf67bb588a7b6269a67032e3 to your computer and use it in GitHub Desktop.
Curve analyzer for AnimationCurve in Unity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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