- Extend editor nodes with custom DialogueContent data type that holds either image or text - Extend the dialogue importer to correctly process the new content into updated RuntimeDialogue content - Update SpeechBubble to be able to display either text or image - Add a custom property drawer for the DialogueContent to allow easy switching in graph authoring Co-authored-by: Michal Pikulski <michal@foolhardyhorizons.com> Reviewed-on: #19
77 lines
2.1 KiB
C#
77 lines
2.1 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;
|
|
|
|
/// <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"}";
|
|
}
|
|
}
|
|
}
|