Files
FablishRPG/Assets/Scripts/QuestObjectiveUI.cs

64 lines
2.2 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class QuestObjectiveUI : MonoBehaviour
{
[Tooltip("The text component for the objective description")]
public TextMeshProUGUI objectiveText;
[Header("GameObject Toggling (Option A)")]
[Tooltip("The GameObject to show when the objective is NOT the currently active one (Completed or Pending future)")]
[UnityEngine.Serialization.FormerlySerializedAs("incompleteIcon")]
public GameObject inactiveIcon;
[Tooltip("The GameObject to show when the objective IS the currently active one")]
[UnityEngine.Serialization.FormerlySerializedAs("completeIcon")]
public GameObject activeIcon;
[Header("Sprite Swapping (Option B)")]
[Tooltip("Assign this if you use a SINGLE Image and want to swap its sprite")]
public Image iconImage;
[Tooltip("Sprite for Completed/Pending objective")]
public Sprite inactiveSprite;
[Tooltip("Sprite for the Active objective")]
public Sprite activeSprite;
public void Setup(string description, bool isActive, bool isCompleted, string countText = "")
{
if (objectiveText != null)
{
objectiveText.text = description + countText;
if (isCompleted)
{
// Completed
objectiveText.fontStyle = FontStyles.Strikethrough;
objectiveText.color = new Color(0.5f, 0.5f, 0.5f, 0.5f); // Faded gray
}
else if (isActive)
{
// Currently Active!
objectiveText.fontStyle = FontStyles.Normal;
objectiveText.color = Color.white;
}
else
{
// Pending/Locked future objective
objectiveText.fontStyle = FontStyles.Normal;
objectiveText.color = Color.gray;
}
}
// Option A: Toggle GameObjects based on Completion
if (inactiveIcon != null) inactiveIcon.SetActive(!isCompleted);
if (activeIcon != null) activeIcon.SetActive(isCompleted);
// Option B: Swap Sprite on a single Image based on Active state
if (iconImage != null)
{
iconImage.sprite = isActive ? activeSprite : inactiveSprite;
}
}
}