Files
AppleHillsProduction/Assets/Scripts/Dialogue/DialogueContent.cs

77 lines
2.1 KiB
C#
Raw Normal View History

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