37 lines
1.4 KiB
C#
37 lines
1.4 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace Jovian.EncounterSystem {
|
|
/// <summary>
|
|
/// Reference to a dialog line. Looks up <see cref="id"/> inside <see cref="library"/> when both
|
|
/// are set; otherwise falls back to <see cref="inlineText"/>. This lets designers prototype
|
|
/// one-off lines inline and promote common ones to the shared library later without changing
|
|
/// the field's type.
|
|
/// </summary>
|
|
[Serializable]
|
|
public struct DialogLineRef {
|
|
/// <summary>Shared library to resolve <see cref="id"/> against. Optional.</summary>
|
|
public DialogLineLibrary library;
|
|
|
|
/// <summary>Line id inside <see cref="library"/>. Ignored if <see cref="library"/> is null.</summary>
|
|
public string id;
|
|
|
|
/// <summary>Fallback text used when the library reference is missing or fails to resolve.
|
|
/// Authored directly in the inspector for one-off lines.</summary>
|
|
[TextArea(2, 6)]
|
|
public string inlineText;
|
|
|
|
/// <summary>Resolve to final text. Returns <see cref="inlineText"/> if no library reference
|
|
/// resolves, or <c>null</c> if both paths yield nothing.</summary>
|
|
public string Resolve() {
|
|
if(library != null && !string.IsNullOrEmpty(id)) {
|
|
var text = library.Resolve(id);
|
|
if(!string.IsNullOrEmpty(text)) {
|
|
return text;
|
|
}
|
|
}
|
|
return inlineText;
|
|
}
|
|
}
|
|
}
|