diff options
author | chai <215380520@qq.com> | 2024-05-23 10:08:29 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2024-05-23 10:08:29 +0800 |
commit | 8722a9920c1f6119bf6e769cba270e63097f8e25 (patch) | |
tree | 2eaf9865de7fb1404546de4a4296553d8f68cc3b /Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/Scenes/OldExamples/Example18_RTS/RTSBuildingQueueUI.cs | |
parent | 3ba4020b69e5971bb0df7ee08b31d10ea4d01937 (diff) |
+ astar project
Diffstat (limited to 'Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/Scenes/OldExamples/Example18_RTS/RTSBuildingQueueUI.cs')
-rw-r--r-- | Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/Scenes/OldExamples/Example18_RTS/RTSBuildingQueueUI.cs | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/Scenes/OldExamples/Example18_RTS/RTSBuildingQueueUI.cs b/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/Scenes/OldExamples/Example18_RTS/RTSBuildingQueueUI.cs new file mode 100644 index 0000000..15bda81 --- /dev/null +++ b/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/Scenes/OldExamples/Example18_RTS/RTSBuildingQueueUI.cs @@ -0,0 +1,76 @@ +using UnityEngine; +using UnityEngine.UI; + +namespace Pathfinding.Examples.RTS { + [HelpURL("https://arongranberg.com/astar/documentation/stable/rtsbuildingqueueui.html")] + public class RTSBuildingQueueUI : VersionedMonoBehaviour { + RTSBuildingBarracks building; + public GameObject prefab; + public Vector3 worldOffset; + public Vector2 screenOffset; + UIItem item; + + class UIItem : RTSWorldSpaceUI.Item { + QueItem[] queItems; + RTSBuildingQueueUI parent; + + public UIItem (Transform tracking, RTSBuildingQueueUI parent) : base(tracking) { + this.parent = parent; + } + + struct QueItem { + public GameObject root; + public UnityEngine.UI.Image icon; + public UnityEngine.UI.Image progress; + + public QueItem (Transform root) { + this.root = root.gameObject; + icon = root.Find("Mask/Image").GetComponent<Image>(); + var p = root.Find("QueProgress"); + progress = p != null? p.GetComponent<Image>() : null; + } + } + + public override void SetUIRoot (UnityEngine.GameObject root) { + base.SetUIRoot(root); + queItems = new QueItem[4]; + queItems[0] = new QueItem(root.transform.Find("Que0")); + queItems[1] = new QueItem(root.transform.Find("Que/Que1")); + queItems[2] = new QueItem(root.transform.Find("Que/Que2")); + queItems[3] = new QueItem(root.transform.Find("Que/Que3")); + } + + public override void Update (UnityEngine.Camera cam) { + base.Update(cam); + for (int i = 0; i < queItems.Length; i++) { + if (i >= parent.building.queue.Count) { + queItems[i].root.SetActive(false); + } else { + queItems[i].root.SetActive(true); + if (i == 0) { + queItems[i].progress.fillAmount = parent.building.queueProgressFraction; + } + queItems[i].icon.sprite = null; //parent.building.queue[i].prefab.GetComponent; + } + } + } + } + + protected override void Awake () { + base.Awake(); + building = GetComponent<RTSBuildingBarracks>(); + } + + void Start () { + item = new UIItem(transform, this); + RTSUI.active.worldSpaceUI.Add(item, prefab); + } + +#if UNITY_EDITOR + void Update () { + item.worldOffset = worldOffset; + item.screenOffset = screenOffset; + } +#endif + } +} |