summaryrefslogtreecommitdiffhomepage
path: root/Assets/Scripts
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2022-12-07 16:43:35 -0500
committerrealtradam <[email protected]>2022-12-07 16:43:35 -0500
commite0d8634a0aaea9ce8fb4b2683c37edaae53abe3d (patch)
treef829c8f3248f0b0c11c4f11bc85bee4948623f82 /Assets/Scripts
parent0cf6c220b1b468cbc2a849fe8d9190f9e0beab8b (diff)
downloadUnityDancingGraph-e0d8634a0aaea9ce8fb4b2683c37edaae53abe3d.tar.gz
UnityDancingGraph-e0d8634a0aaea9ce8fb4b2683c37edaae53abe3d.zip
added interactive ui and customized skybox
Diffstat (limited to 'Assets/Scripts')
-rw-r--r--Assets/Scripts/FunctionLerp.cs22
-rw-r--r--Assets/Scripts/FunctionLerp.cs.meta11
-rw-r--r--Assets/Scripts/FunctionSelector.cs38
-rw-r--r--Assets/Scripts/FunctionSelector.cs.meta11
-rw-r--r--Assets/Scripts/Graph.cs52
-rw-r--r--Assets/Scripts/ResolutionSlider.cs24
-rw-r--r--Assets/Scripts/ResolutionSlider.cs.meta11
-rw-r--r--Assets/Scripts/ScaleSlider.cs24
-rw-r--r--Assets/Scripts/ScaleSlider.cs.meta11
9 files changed, 196 insertions, 8 deletions
diff --git a/Assets/Scripts/FunctionLerp.cs b/Assets/Scripts/FunctionLerp.cs
new file mode 100644
index 0000000..a255604
--- /dev/null
+++ b/Assets/Scripts/FunctionLerp.cs
@@ -0,0 +1,22 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEngine.UI;
+using TMPro;
+
+public class FunctionLerp : MonoBehaviour
+{
+ public TMP_Text text;
+ private Graph graph;
+
+ void Awake()
+ {
+ var gameObjectGraph = GameObject.Find("Graph");
+ graph = gameObjectGraph.GetComponent<Graph>();
+ }
+
+ void Update()
+ {
+ text.text = "Function Lerp: " + graph.GetLerp().ToString("0.0");
+ }
+}
diff --git a/Assets/Scripts/FunctionLerp.cs.meta b/Assets/Scripts/FunctionLerp.cs.meta
new file mode 100644
index 0000000..c964daa
--- /dev/null
+++ b/Assets/Scripts/FunctionLerp.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 4862b1025ac7bb6fcb629c7e9eb40e92
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/FunctionSelector.cs b/Assets/Scripts/FunctionSelector.cs
new file mode 100644
index 0000000..b6ab1a6
--- /dev/null
+++ b/Assets/Scripts/FunctionSelector.cs
@@ -0,0 +1,38 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEngine.UI;
+using TMPro;
+
+
+public class FunctionSelector : MonoBehaviour
+{
+ Graph graph;
+ TMP_Dropdown dropdown;
+
+ private void Awake()
+ {
+ dropdown = gameObject.GetComponent<TMP_Dropdown>();
+ var gameObjectGraph = GameObject.Find("Graph");
+ graph = gameObjectGraph.GetComponent<Graph>();
+ }
+
+ // Start is called before the first frame update
+ void Start()
+ {
+ }
+
+
+ // Update is called once per frame
+ void Update()
+ {
+ if(graph.IsLerping())
+ {
+ dropdown.interactable = false;
+ }
+ else
+ {
+ dropdown.interactable = true;
+ }
+ }
+}
diff --git a/Assets/Scripts/FunctionSelector.cs.meta b/Assets/Scripts/FunctionSelector.cs.meta
new file mode 100644
index 0000000..cf2896a
--- /dev/null
+++ b/Assets/Scripts/FunctionSelector.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 9f7d5ec3ca50f148d8d3ae215b9fb380
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
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);
}
}
diff --git a/Assets/Scripts/ResolutionSlider.cs b/Assets/Scripts/ResolutionSlider.cs
new file mode 100644
index 0000000..e4ed81a
--- /dev/null
+++ b/Assets/Scripts/ResolutionSlider.cs
@@ -0,0 +1,24 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEngine.UI;
+using TMPro;
+
+public class ResolutionSlider : MonoBehaviour
+{
+ public Slider slider;
+ private Graph graph;
+ private TMP_Text text;
+
+ void Awake()
+ {
+ var gameObjectGraph = GameObject.Find("Graph");
+ graph = gameObjectGraph.GetComponent<Graph>();
+ var gameObjectText = GameObject.Find("ResolutionText");
+ text = gameObjectText.GetComponent<TMP_Text>();
+ slider.onValueChanged.AddListener((value) => {
+ graph.SetResolution((int)value);
+ text.text = "Resolution: " + value.ToString();
+ });
+ }
+}
diff --git a/Assets/Scripts/ResolutionSlider.cs.meta b/Assets/Scripts/ResolutionSlider.cs.meta
new file mode 100644
index 0000000..02b4872
--- /dev/null
+++ b/Assets/Scripts/ResolutionSlider.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: b04f5b5271998d057a9ba522437e08dd
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/ScaleSlider.cs b/Assets/Scripts/ScaleSlider.cs
new file mode 100644
index 0000000..69bb58f
--- /dev/null
+++ b/Assets/Scripts/ScaleSlider.cs
@@ -0,0 +1,24 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEngine.UI;
+using TMPro;
+
+public class ScaleSlider : MonoBehaviour
+{
+ public Slider slider;
+ private Graph graph;
+ private TMP_Text text;
+
+ void Awake()
+ {
+ var gameObjectGraph = GameObject.Find("Graph");
+ graph = gameObjectGraph.GetComponent<Graph>();
+ var gameObjectText = GameObject.Find("ScaleText");
+ text = gameObjectText.GetComponent<TMP_Text>();
+ slider.onValueChanged.AddListener((value) => {
+ graph.SetFunctionScale((float)value);
+ text.text = "Function Scale: " + value.ToString("0.0");
+ });
+ }
+}
diff --git a/Assets/Scripts/ScaleSlider.cs.meta b/Assets/Scripts/ScaleSlider.cs.meta
new file mode 100644
index 0000000..65fc662
--- /dev/null
+++ b/Assets/Scripts/ScaleSlider.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 7045c94623aa337719ee3db7f8a1c8f1
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant: