summaryrefslogtreecommitdiff
path: root/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/Scenes/OldExamples/Example18_RTS/RTSResourceView.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/Scenes/OldExamples/Example18_RTS/RTSResourceView.cs')
-rw-r--r--Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/Scenes/OldExamples/Example18_RTS/RTSResourceView.cs37
1 files changed, 37 insertions, 0 deletions
diff --git a/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/Scenes/OldExamples/Example18_RTS/RTSResourceView.cs b/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/Scenes/OldExamples/Example18_RTS/RTSResourceView.cs
new file mode 100644
index 0000000..6c47133
--- /dev/null
+++ b/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/Scenes/OldExamples/Example18_RTS/RTSResourceView.cs
@@ -0,0 +1,37 @@
+using UnityEngine;
+using UnityEngine.UI;
+
+namespace Pathfinding.Examples.RTS {
+ [HelpURL("https://arongranberg.com/astar/documentation/stable/rtsresourceview.html")]
+ public class RTSResourceView : VersionedMonoBehaviour {
+ public float adjustmentSpeed = 10;
+
+ [System.Serializable]
+ public class Item {
+ public RTSUnit.Type resource;
+ public string name;
+ public Text label;
+ float smoothedValue;
+
+ public void Tick (RTSPlayerResources resources, float adjustmentSpeed) {
+ float val = resources.GetResource(resource);
+ var diff = Mathf.Abs(val - smoothedValue);
+ var dv = Mathf.Min(diff, Mathf.Max(diff * adjustmentSpeed * Time.deltaTime, 10f * adjustmentSpeed * Time.deltaTime));
+
+ smoothedValue += dv * Mathf.Sign(val - smoothedValue);
+ label.text = name + ": " + Mathf.Round(smoothedValue).ToString("0");
+ }
+ }
+
+ public int team;
+ public Item[] items;
+
+ void Update () {
+ var resources = RTSManager.instance.GetPlayer(team).resources;
+
+ for (int i = 0; i < items.Length; i++) {
+ items[i].Tick(resources, adjustmentSpeed);
+ }
+ }
+ }
+}