using System; using UnityEngine; namespace Dialogue { /// /// Content type for dialogue entries /// public enum DialogueContentType { Text, Image } /// /// Wrapper class for dialogue content that can be either text or image /// [Serializable] public class DialogueContent { [SerializeField] private DialogueContentType _contentType = DialogueContentType.Text; [SerializeField] private string _text = string.Empty; [SerializeField] private Sprite _image = null; /// /// The type of content this entry contains /// public DialogueContentType ContentType => _contentType; /// /// The text content (valid when ContentType is Text) /// public string Text => _text; /// /// The image content (valid when ContentType is Image) /// public Sprite Image => _image; /// /// Create text content /// /// The text to display public static DialogueContent CreateText(string text) { return new DialogueContent { _contentType = DialogueContentType.Text, _text = text }; } /// /// Create image content /// /// The image to display public static DialogueContent CreateImage(Sprite image) { return new DialogueContent { _contentType = DialogueContentType.Image, _image = image }; } /// /// Returns a string representation of this content /// public override string ToString() { return ContentType == DialogueContentType.Text ? $"Text: {_text}" : $"Image: {_image?.name ?? "None"}"; } } }