using UnityEngine; using UnityEngine.UI; public class GoalSlider : MonoBehaviour { public Text text; public Slider slider; public Vector2 rangeAmount = Vector2.zero; public Vector2 rangeWeightSum = Vector2.zero; public Vector2 rangeWeightMax = Vector2.zero; private bool isUpdatingValue; private void OnEnable() { UpdateValue(); } public void UpdateValue() { if (!isUpdatingValue) { isUpdatingValue = true; if ((bool)GlobalSettings.Instance) { GlobalSettings.Instance.tournamentDefinition.goalAmount = (int)slider.value; } text.text = Utilities.GetTranslation("GUI/TOURNAMENTS_GOAL") + ": "; if (GlobalSettings.Instance.tournamentDefinition.goalType == TournamentManager.TournamentDefinition.GoalType.AMOUNT) { slider.minValue = rangeAmount.x; slider.maxValue = rangeAmount.y; text.text += slider.value; } else if (GlobalSettings.Instance.tournamentDefinition.goalType == TournamentManager.TournamentDefinition.GoalType.WEIGHT_SUM) { slider.minValue = rangeWeightSum.x; slider.maxValue = rangeWeightSum.y; text.text += UtilitiesUnits.GetWeightString(slider.value); } else if (GlobalSettings.Instance.tournamentDefinition.goalType == TournamentManager.TournamentDefinition.GoalType.WEIGHT_MAX) { slider.minValue = rangeWeightMax.x; slider.maxValue = rangeWeightMax.y; text.text += UtilitiesUnits.GetWeightString(slider.value); } text.color = new Color(text.color.r, text.color.g, text.color.b, (!slider.interactable) ? slider.colors.disabledColor.a : 1f); isUpdatingValue = false; } } }