91 lines
2.7 KiB
C#
91 lines
2.7 KiB
C#
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;
|
|
[SerializeField] private AudioClip _audio = 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>
|
|
/// The audio clip to play with this content
|
|
/// </summary>
|
|
public AudioClip Audio => _audio;
|
|
|
|
/// <summary>
|
|
/// Create text content
|
|
/// </summary>
|
|
/// <param name="text">The text to display</param>
|
|
/// <param name="audio">Optional audio clip to play</param>
|
|
public static DialogueContent CreateText(string text, AudioClip audio = null)
|
|
{
|
|
return new DialogueContent
|
|
{
|
|
_contentType = DialogueContentType.Text,
|
|
_text = text,
|
|
_audio = audio
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// Create image content
|
|
/// </summary>
|
|
/// <param name="image">The image to display</param>
|
|
/// <param name="audio">Optional audio clip to play</param>
|
|
public static DialogueContent CreateImage(Sprite image, AudioClip audio = null)
|
|
{
|
|
return new DialogueContent
|
|
{
|
|
_contentType = DialogueContentType.Image,
|
|
_image = image,
|
|
_audio = audio
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns a string representation of this content
|
|
/// </summary>
|
|
public override string ToString()
|
|
{
|
|
string contentDesc = ContentType == DialogueContentType.Text
|
|
? $"Text: {_text}"
|
|
: $"Image: {_image?.name ?? "None"}";
|
|
|
|
return _audio != null
|
|
? $"{contentDesc} (with audio: {_audio.name})"
|
|
: contentDesc;
|
|
}
|
|
}
|
|
}
|