From 257cdc83462219c430e41c013b2f641b8f024d3b Mon Sep 17 00:00:00 2001 From: Julius <juliusfe@stud.ntnu.no> Date: Fri, 9 Dec 2022 16:59:33 +0100 Subject: [PATCH] Added ability cluster full charge and cooldown func --- MrBigsock/Assets/Code/UI/AbilityCluster.cs | 20 ++++++++++++++++++++ MrBigsock/Assets/Code/UI/AbilityElement.cs | 22 +++++++++++----------- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/MrBigsock/Assets/Code/UI/AbilityCluster.cs b/MrBigsock/Assets/Code/UI/AbilityCluster.cs index 63fde66f..44832dbb 100644 --- a/MrBigsock/Assets/Code/UI/AbilityCluster.cs +++ b/MrBigsock/Assets/Code/UI/AbilityCluster.cs @@ -1,13 +1,33 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using UnityEngine.UI; +using BigSock.Service; namespace BigSock.UI { public class AbilityCluster : MonoBehaviour { + private const string ABILITYELEMENT = "UI/Ability"; + private List<AbilityElement> abilityList; + public void SetElements(int elementAmount) + { + for (int i = 0; i < elementAmount; ++i) + { + abilityList.Add(PrefabService.SINGLETON.Instance(ABILITYELEMENT, transform).GetComponent<AbilityElement>()); + } + } + public void SetCooldown(int index, float amount) + { + abilityList[index].WithCooldown(amount); + } + + public void SetCharge(int index, float amount) + { + abilityList[index].WithCharge(amount); + } } diff --git a/MrBigsock/Assets/Code/UI/AbilityElement.cs b/MrBigsock/Assets/Code/UI/AbilityElement.cs index f82a1b2d..21307ed2 100644 --- a/MrBigsock/Assets/Code/UI/AbilityElement.cs +++ b/MrBigsock/Assets/Code/UI/AbilityElement.cs @@ -8,31 +8,31 @@ namespace BigSock.UI { public class AbilityElement : MonoBehaviour { - private Slider ChargeSlider, ReloadSlider; + private Slider chargeSlider, cooldownSlider; - public AbilityElement WithCharge(int? value = null, int? maxValue = null) + public AbilityElement WithCharge(float? value = null, float? maxValue = null) { - if (value != null) ChargeSlider.value = value.Value; + if (value != null) chargeSlider.value = value.Value; - if (maxValue != null) ChargeSlider.maxValue = maxValue.Value; + if (maxValue != null) chargeSlider.maxValue = maxValue.Value; return this; } - - public AbilityElement WithReload(int? value = null, int? maxValue = null) + + public AbilityElement WithCooldown(float? value = null, float? maxValue = null) { - if (value != null) ReloadSlider.value = value.Value; + if (value != null) cooldownSlider.value = value.Value; - if (maxValue != null) ReloadSlider.maxValue = maxValue.Value; + if (maxValue != null) cooldownSlider.maxValue = maxValue.Value; return this; - } + } // Start is called before the first frame update void Start() { - ChargeSlider = transform.Find("ChargeSlider").GetComponent<Slider>(); - ReloadSlider = transform.Find("ReloadSlider").GetComponent<Slider>(); + chargeSlider = transform.Find("ChargeSlider").GetComponent<Slider>(); + cooldownSlider = transform.Find("ReloadSlider").GetComponent<Slider>(); } // Update is called once per frame -- GitLab