// Copyright (c) Pixel Crushers. All rights reserved. using UnityEngine; using System; namespace PixelCrushers.QuestMachine { /// /// Unity UI template for an icon. /// [AddComponentMenu("")] // Use wrapper. public class UnityUIIconTemplate : UnityUIContentTemplate { [Tooltip("Image UI element for icon's image.")] [SerializeField] private UnityEngine.UI.Image m_image; [Tooltip("Text UI element for count. Shown if icon's count is greater than 1.")] [SerializeField] private UITextField m_countText; [Tooltip("Text UI element for icon's caption.")] [SerializeField] private UITextField m_captionText; /// /// Image UI element for icon's image. /// public UnityEngine.UI.Image image { get { return m_image; } set { m_image = value; } } /// /// Text UI element for count. Shown if icon's count is greater than 1. /// public UITextField countText { get { return m_countText; } set { m_countText = value; } } /// /// Text UI element for icon's caption. /// public UITextField captionText { get { return m_captionText; } set { m_captionText = value; } } public virtual void Awake() { //--- No warning. These are optional: //if (image == null && Debug.isDebugBuild) Debug.LogError("Quest Machine: UI Image is unassigned.", this); //if (countText == null && Debug.isDebugBuild) Debug.LogError("Quest Machine: Count Text is unassigned.", this); //if (captionText == null && Debug.isDebugBuild) Debug.LogError("Quest Machine: Caption Text is unassigned.", this); } public virtual void Assign(Sprite sprite, int count, string caption) { Assign(sprite, Color.white, count, caption); } public virtual void Assign(Sprite sprite, Color color, int count, string caption) { if (image != null) { image.sprite = sprite; image.color = color; } if (countText != null) { countText.text = count.ToString(); countText.enabled = count > 1; } if (captionText != null) captionText.text = caption; } } }