diff options
| author | realtradam <[email protected]> | 2022-12-07 16:43:35 -0500 |
|---|---|---|
| committer | realtradam <[email protected]> | 2022-12-07 16:43:35 -0500 |
| commit | e0d8634a0aaea9ce8fb4b2683c37edaae53abe3d (patch) | |
| tree | f829c8f3248f0b0c11c4f11bc85bee4948623f82 /Assets/Scripts/Graph.cs | |
| parent | 0cf6c220b1b468cbc2a849fe8d9190f9e0beab8b (diff) | |
| download | UnityDancingGraph-e0d8634a0aaea9ce8fb4b2683c37edaae53abe3d.tar.gz UnityDancingGraph-e0d8634a0aaea9ce8fb4b2683c37edaae53abe3d.zip | |
added interactive ui and customized skybox
Diffstat (limited to 'Assets/Scripts/Graph.cs')
| -rw-r--r-- | Assets/Scripts/Graph.cs | 52 |
1 files changed, 44 insertions, 8 deletions
diff --git a/Assets/Scripts/Graph.cs b/Assets/Scripts/Graph.cs index 6c3b5de..e454ebb 100644 --- a/Assets/Scripts/Graph.cs +++ b/Assets/Scripts/Graph.cs @@ -8,14 +8,12 @@ public class Graph : MonoBehaviour [SerializeField] Transform pointPrefab; - const int max_resolution = 100; + const int max_resolution = 50; - [SerializeField, Range(3, max_resolution)] int resolution = 30; int old_resolution = 30; - [SerializeField] - MathFunctionLibrary.FunctionEnum function; + static MathFunctionLibrary.FunctionEnum function; MathFunctionLibrary.FunctionEnum old_function; [SerializeField, Range(0.1f, 2.0f)] @@ -26,9 +24,46 @@ public class Graph : MonoBehaviour float lerp_timer = 0f; bool lerping = false; + // prevents lag spike from skipping too many frames of animation + const float lerp_max_delta = 1f/20f; + + Transform[] points; - void SetResolution() { + public float GetLerp() + { + if(lerp_speed <= 0) + { + return 0f; + } + else + { + return lerp_timer / lerp_speed; + } + } + + public void SetFunctionScale(float scale) + { + function_scale = scale; + } + + public void SetResolution(int res) + { + resolution = res; + } + + public void SetFunction(int func) + { + function = (MathFunctionLibrary.FunctionEnum)func; + } + + public bool IsLerping() + { + return lerping; + } + + void UpdateResolution() + { float step = 2f / resolution; for(int i = 0, x = 0, z = 0; i < (max_resolution * max_resolution); i++, x++) { Transform point = points[i]; @@ -53,7 +88,8 @@ public class Graph : MonoBehaviour } } - void Awake() { + void Awake() + { points = new Transform[max_resolution * max_resolution]; float step = 2f / resolution; for(int i = 0, x = 0, z = 0; i < (max_resolution * max_resolution); i++, x++) { @@ -90,7 +126,7 @@ public class Graph : MonoBehaviour if(old_resolution != resolution) { old_resolution = resolution; - SetResolution(); + UpdateResolution(); } if(function != old_function) @@ -110,7 +146,7 @@ public class Graph : MonoBehaviour } else { - lerp_timer -= Time.deltaTime; + lerp_timer -= Mathf.Min(Time.deltaTime, lerp_max_delta); } } |
