/* Yarn Spinner is licensed to you under the terms found in the file LICENSE.md. */ using System.Collections.Generic; using System.Threading; using UnityEngine; using Yarn.Markup; #nullable enable namespace Yarn.Unity { /// /// Contains methods for retrieving user-facing localized content, given /// non-localized line IDs. /// public interface ILineProvider { /// /// The that contains the localized data for /// lines. /// /// /// This property is set at run-time by the object that will be requesting /// content (typically a ). /// public YarnProject? YarnProject { get; set; } /// /// Gets the line provider's current locale identifier, as a BCP-47 code. /// public string LocaleCode { get; } /// /// Prepares and returns a from the specified /// . /// /// The to produce the from. /// A cancellation token that indicates /// whether the process of fetching the localised version of should be cancelled. /// A localized line, ready to be presented to the /// player. public YarnTask GetLocalizedLineAsync(Line line, CancellationToken cancellationToken); /// /// Signals to the line provider that lines with the provided line IDs may /// be presented shortly. /// /// /// /// This method allows implementing classes a chance to prepare any /// neccessary resources needed to present these lines, like pre-loading /// voice-over audio. The default implementation does nothing. /// /// /// Not every line may run; this method serves as a way to give the line /// provider advance notice that a line may run, not will run. /// /// /// A collection of line IDs that the line provider /// should prepare for. /// A cancellation token that indicates /// whether the operation should be cancelled. public YarnTask PrepareForLinesAsync(IEnumerable lineIDs, CancellationToken cancellationToken); /// /// Adds a new marker processor to the line provider. /// /// The name of the markers to use for. /// The marker processor to add. public void RegisterMarkerProcessor(string attributeName, Yarn.Markup.IAttributeMarkerProcessor markerProcessor); /// /// Removes all marker processors that handle markers named . /// /// The name of the marker to remove processors /// for. public void DeregisterMarkerProcessor(string attributeName); } /// /// A that produces s, for use in Dialogue Presenters. /// /// /// s use a /// to get s, which contain the localized /// information that is presented to the player through dialogue presenters. /// public abstract class LineProviderBehaviour : MonoBehaviour, ILineProvider { /// public abstract YarnTask GetLocalizedLineAsync(Line line, CancellationToken cancellationToken); /// public YarnProject? YarnProject { get; set; } /// public virtual YarnTask PrepareForLinesAsync(IEnumerable lineIDs, CancellationToken cancellationToken) { // No-op by default. return YarnTask.CompletedTask; } /// public abstract string LocaleCode { get; set; } /// /// Called by Unity when the has /// first appeared in the scene. /// /// /// This method is to /// allow subclasses to override it. /// public virtual void Start() { } /// public abstract void RegisterMarkerProcessor(string attributeName, IAttributeMarkerProcessor markerProcessor); /// public abstract void DeregisterMarkerProcessor(string attributeName); } }