// Copyright (c) Pixel Crushers. All rights reserved. using UnityEngine; namespace PixelCrushers.DialogueSystem { /// /// A static class that provides a simplified interface to the Dialogue System's core /// functions. This class manages a singleton instance of DialogueSystemController. /// Starting in version 2.0, it will NOT auto-instantiate an instance if none exists. /// public static class DialogueManager { private static DialogueSystemController m_instance = null; /// /// Gets the instance of DialogueSystemController. /// /// /// The instance. /// public static DialogueSystemController instance { get { if (m_instance == null) m_instance = GameObjectUtility.FindFirstObjectByType(); return m_instance; } } /// /// Returns true if the singleton has found or created an instance. /// /// true if has instance; otherwise, false. public static bool hasInstance { get { return instance != null; } } #if UNITY_2019_3_OR_NEWER && UNITY_EDITOR [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] static void InitStaticVariables() { m_instance = null; } #endif /// /// Gets the database manager. /// /// /// The database manager. /// public static DatabaseManager databaseManager { get { return hasInstance ? instance.databaseManager : null; } } /// /// Gets the master database. /// /// /// The master database. /// public static DialogueDatabase masterDatabase { get { return hasInstance ? instance.masterDatabase : null; } } /// /// Gets the dialogue UI. /// /// /// The dialogue UI. /// public static IDialogueUI dialogueUI { get { return (instance != null) ? instance.dialogueUI : null; } set { instance.dialogueUI = value; } } /// /// Convenience property that casts the dialogueUI property as a StandardDialogueUI. /// If the dialogueUI is not a StandardDialogueUI, returns null. /// public static StandardDialogueUI standardDialogueUI { get { return (instance != null) ? instance.standardDialogueUI : null; } set { instance.standardDialogueUI = value; } } /// /// Gets the display settings. /// /// /// The display settings. /// public static DisplaySettings displaySettings { get { return hasInstance ? instance.displaySettings : null; } } /// /// Indicates whether a conversation is active. /// /// /// true if a conversation is active; otherwise, false. /// public static bool isConversationActive { get { return hasInstance ? instance.isConversationActive : false; } } /// /// Indicates whether more than one conversation can play at the same time. /// /// true if simultaneous conversations are allowed; otherwise, false. public static bool allowSimultaneousConversations { get { return hasInstance ? instance.allowSimultaneousConversations : false; } } /// /// If not allowing simultaneous conversations and a conversation is active, stop it if another conversation wants to start. /// /// true to interrupt active conversation if another wants to start; otherwise, false. public static bool interruptActiveConversations { get { return hasInstance ? instance.interruptActiveConversations : false; } } /// /// The IsDialogueEntryValid delegate (if one is assigned). This is an optional delegate that you /// can add to check if a dialogue entry is valid before allowing a conversation to use it. /// It should return true if the entry is valid. /// public static IsDialogueEntryValidDelegate isDialogueEntryValid { get { return hasInstance ? instance.isDialogueEntryValid : null; } set { instance.isDialogueEntryValid = value; } } /// /// If response timeout action is set to Custom and menu times out, call this method. /// public static System.Action customResponseTimeoutHandler { get { return hasInstance ? instance.customResponseTimeoutHandler : null; } set { instance.customResponseTimeoutHandler = value; } } /// /// The GetInputButtonDown delegate. Overrides calls to the standard Unity /// Input.GetButtonDown function. /// public static GetInputButtonDownDelegate getInputButtonDown { get { return hasInstance ? instance.getInputButtonDown : null; } set { instance.getInputButtonDown = value; } } /// /// Gets the current actor in the last conversation started (or null if no /// conversation is active or the last conversation started has ended). /// See https://www.pixelcrushers.com/dialogue_system/manual2x/html/triggers_and_interaction.html#interactionDialogueSystemTriggerGameObjectAssignments /// for an explanation of how a conversation's actor and conversant are assigned /// at runtime. /// /// /// The actor in the current conversation. /// public static Transform currentActor { get { return hasInstance ? instance.currentActor : null; } } /// /// Gets the current conversant in the last conversation started (or null if no /// conversation is active or the last conversation started has ended). /// See https://www.pixelcrushers.com/dialogue_system/manual2x/html/triggers_and_interaction.html#interactionDialogueSystemTriggerGameObjectAssignments /// for an explanation of how a conversation's actor and conversant are assigned /// at runtime. /// /// /// The conversant in the current conversation. /// public static Transform currentConversant { get { return hasInstance ? instance.currentConversant : null; } } /// /// Gets the current conversation state of the last conversation started (or null if no /// conversation is active or the last conversation started has ended). /// /// The current conversation state. public static ConversationState currentConversationState { get { return hasInstance ? instance.currentConversationState : null; } } /// /// Gets the title of the last conversation started. /// /// The title of the last conversation started. public static string lastConversationStarted { get { return hasInstance ? instance.lastConversationStarted : string.Empty; } } /// /// Gets the title of the last conversation that ended. /// /// The title of the last conversation ended. public static string lastConversationEnded { get { return hasInstance ? instance.lastConversationEnded : string.Empty; } } /// /// Gets the ID of the last conversation started. /// public static int lastConversationID { get { return hasInstance ? instance.lastConversationID : -1; } } /// /// Gets the active conversation's ConversationController. /// public static ConversationController conversationController { get { return hasInstance ? instance.conversationController : null; } } /// /// Gets the active conversation's ConversationModel. /// public static ConversationModel conversationModel { get { return hasInstance ? instance.conversationModel : null; } } /// /// Gets the active conversation's ConversationView. /// public static ConversationView conversationView { get { return hasInstance ? instance.conversationView : null; } } /// /// If true, Dialogue System Triggers set to OnStart should wait until save data has been applied or variables initialized. /// public static bool onStartTriggerWaitForSaveDataApplied { get { return hasInstance ? instance.onStartTriggerWaitForSaveDataApplied : false; } set { if (hasInstance) instance.onStartTriggerWaitForSaveDataApplied = value; } } /// /// Gets or sets the debug level. /// /// /// The debug level. /// public static DialogueDebug.DebugLevel debugLevel { get { return hasInstance ? instance.debugLevel : DialogueDebug.level; } set { if (hasInstance) instance.debugLevel = value; DialogueDebug.level = value; } } /// /// Gets or sets a value indicating whether exceptions in Lua code will be caught by /// the calling method or allowed to rise up to Unity. Defaults to false. /// /// true if Lua exceptions are allowed; otherwise, false. public static bool allowLuaExceptions { get { return hasInstance ? instance.allowLuaExceptions : false; } set { instance.allowLuaExceptions = value; } } /// @cond FOR_V1_COMPATIBILITY public static DialogueSystemController Instance { get { return instance; } } public static bool HasInstance { get { return hasInstance; } } public static DatabaseManager DatabaseManager { get { return databaseManager; } } public static DialogueDatabase MasterDatabase { get { return masterDatabase; } } public static IDialogueUI DialogueUI { get { return dialogueUI; } set { dialogueUI = value; } } public static DisplaySettings DisplaySettings { get { return displaySettings; } } public static bool IsConversationActive { get { return isConversationActive; } } public static bool AllowSimultaneousConversations { get { return allowSimultaneousConversations; } } public static IsDialogueEntryValidDelegate IsDialogueEntryValid { get { return isDialogueEntryValid; } set { isDialogueEntryValid = value; } } public static GetInputButtonDownDelegate GetInputButtonDown { get { return getInputButtonDown; } set { getInputButtonDown = value; } } public static Transform CurrentActor { get { return currentActor; } } public static Transform CurrentConversant { get { return currentConversant; } } public static ConversationState CurrentConversationState { get { return currentConversationState; } } public static string LastConversationStarted { get { return lastConversationStarted; } } public static int LastConversationID { get { return lastConversationID; } } public static ConversationController ConversationController { get { return conversationController; } } public static ConversationModel ConversationModel { get { return conversationModel; } } public static ConversationView ConversationView { get { return conversationView; } } public static DialogueDebug.DebugLevel DebugLevel { get { return debugLevel; } set { debugLevel = value; } } public static bool AllowLuaExceptions { get { return allowLuaExceptions; } set { allowLuaExceptions = value; } } /// @endcond /// /// Sets the language to use for localized text. /// /// /// Language to use. Specify null or an emtpy string to use the default language. /// public static void SetLanguage(string language) { if (!hasInstance) return; instance.SetLanguage(language); } /// /// Enables or disables Dialogue System input. /// /// True to enable, false to disable. public static void SetDialogueSystemInput(bool value) { if (!hasInstance) return; instance.SetDialogueSystemInput(value); } /// /// Returns true if Dialogue System input is disabled. /// /// public static bool IsDialogueSystemInputDisabled() { return hasInstance ? instance.IsDialogueSystemInputDisabled() : true; } /// /// Adds a dialogue database to memory. To save memory or reduce load time, you may want to /// break up your dialogue data into multiple smaller databases. You can add or remove /// these databases as needed. /// /// /// The database to add. /// public static void AddDatabase(DialogueDatabase database) { if (!hasInstance) return; instance.AddDatabase(database); } /// /// Removes a dialogue database from memory. To save memory or reduce load time, you may /// want to break up your dialogue data into multiple smaller databases. You can add or /// remove these databases as needed. /// /// /// The database to remove. /// public static void RemoveDatabase(DialogueDatabase database) { if (!hasInstance) return; instance.RemoveDatabase(database); } /// /// Resets the database to a default state. /// /// /// Accepts the following values: /// - RevertToDefault: Restores the default database, removing any other databases that /// were added after startup. /// - KeepAllLoaded: Keeps all loaded databases in memory, but reverts them to their /// starting values. /// public static void ResetDatabase(DatabaseResetOptions databaseResetOptions) { if (!hasInstance) return; instance.ResetDatabase(databaseResetOptions); } /// /// Resets the database to a default state, keeping all loaded databases. /// public static void ResetDatabase() { if (!hasInstance) return; instance.ResetDatabase(); } /// /// Preloads the master database. The Dialogue System delays loading of the dialogue database /// until the data is needed. This avoids potentially long delays during Start(). If you want /// to load the database manually (for example to run Lua commands on its contents), call /// this method. /// public static void PreloadMasterDatabase() { if (!hasInstance) return; instance.PreloadMasterDatabase(); } /// /// Preloads the dialogue UI. The Dialogue System delays loading of the dialogue UI until the /// first time it's needed for a conversation or alert. Since dialogue UIs often contain /// textures and other art assets, loading can cause a slight pause. You may want to preload /// the UI at a time of your design by using this method. /// public static void PreloadDialogueUI() { if (!hasInstance) return; instance.PreloadDialogueUI(); } /// /// Checks whether a conversation has any valid entries linked from the start entry, since it's possible that /// the conditions of all entries could be false. /// /// /// true, if the conversation has a valid entry, false otherwise. /// /// /// The title of the conversation to look up in the master database. /// /// /// The transform of the actor (primary participant). The sequencer uses this to direct /// camera angles and perform other actions. In PC-NPC conversations, the actor is usually /// the PC. /// /// /// The transform of the conversant (the other participant). The sequencer uses this to /// direct camera angles and perform other actions. In PC-NPC conversations, the conversant /// is usually the NPC. /// /// Optional starting entry ID; omit to start at beginning. public static bool ConversationHasValidEntry(string title, Transform actor, Transform conversant, int initialDialogueEntryID = -1) { return hasInstance ? instance.ConversationHasValidEntry(title, actor, conversant, initialDialogueEntryID) : false; } /// /// Checks whether a conversation has any valid entries linked from the start entry, since it's possible that /// the conditions of all entries could be false. /// /// /// true, if the conversation has a valid entry, false otherwise. /// /// /// The title of the conversation to look up in the master database. /// /// /// The transform of the actor (primary participant). The sequencer uses this to direct /// camera angles and perform other actions. In PC-NPC conversations, the actor is usually /// the PC. /// public static bool ConversationHasValidEntry(string title, Transform actor) { return ConversationHasValidEntry(title, actor, null); } /// /// Checks whether a conversation has any valid entries linked from the start entry, since it's possible that /// the conditions of all entries could be false. /// /// /// true, if the conversation has a valid entry, false otherwise. /// /// /// The title of the conversation to look up in the master database. /// public static bool ConversationHasValidEntry(string title) { return ConversationHasValidEntry(title, null, null); } /// /// Returns a conversation title given its ID, or empty string if no conversation has the ID. /// public static string GetConversationTitle(int conversationID) { return hasInstance ? instance.GetConversationTitle(conversationID) : string.Empty; } /// /// Starts a conversation, which also broadcasts an OnConversationStart message to the /// actor and conversant. Your scripts can listen for OnConversationStart to do anything /// necessary at the beginning of a conversation, such as pausing other gameplay or /// temporarily disabling player control. See the Feature Demo scene, which uses the /// SetEnabledOnDialogueEvent component to disable player control during conversations. /// /// /// The title of the conversation to look up in the master database. /// /// /// The transform of the actor (primary participant). The sequencer uses this to direct /// camera angles and perform other actions. In PC-NPC conversations, the actor is usually /// the PC. /// /// /// The transform of the conversant (the other participant). The sequencer uses this to /// direct camera angles and perform other actions. In PC-NPC conversations, the conversant /// is usually the NPC. /// /// /// The initial dialogue entry ID, or -1 to start from the beginning. /// /// /// StartConversation("Shopkeeper Conversation", player, shopkeeper); /// public static void StartConversation(string title, Transform actor, Transform conversant, int initialDialogueEntryID, IDialogueUI overrideDialogueUI) { if (!hasInstance) return; instance.StartConversation(title, actor, conversant, initialDialogueEntryID, overrideDialogueUI); } /// /// Starts a conversation, which also broadcasts an OnConversationStart message to the /// actor and conversant. Your scripts can listen for OnConversationStart to do anything /// necessary at the beginning of a conversation, such as pausing other gameplay or /// temporarily disabling player control. See the Feature Demo scene, which uses the /// SetEnabledOnDialogueEvent component to disable player control during conversations. /// /// /// The title of the conversation to look up in the master database. /// /// /// The transform of the actor (primary participant). The sequencer uses this to direct /// camera angles and perform other actions. In PC-NPC conversations, the actor is usually /// the PC. /// /// /// The transform of the conversant (the other participant). The sequencer uses this to /// direct camera angles and perform other actions. In PC-NPC conversations, the conversant /// is usually the NPC. /// /// /// The initial dialogue entry ID, or -1 to start from the beginning. /// /// /// StartConversation("Shopkeeper Conversation", player, shopkeeper); /// public static void StartConversation(string title, Transform actor, Transform conversant, int initialDialogueEntryID) { if (!hasInstance) return; instance.StartConversation(title, actor, conversant, initialDialogueEntryID); } /// /// Starts a conversation, which also broadcasts an OnConversationStart message to the /// actor and conversant. Your scripts can listen for OnConversationStart to do anything /// necessary at the beginning of a conversation, such as pausing other gameplay or /// temporarily disabling player control. See the Feature Demo scene, which uses the /// SetEnabledOnDialogueEvent component to disable player control during conversations. /// /// /// The title of the conversation to look up in the master database. /// /// /// The transform of the actor (primary participant). The sequencer uses this to direct /// camera angles and perform other actions. In PC-NPC conversations, the actor is usually /// the PC. /// /// /// The transform of the conversant (the other participant). The sequencer uses this to /// direct camera angles and perform other actions. In PC-NPC conversations, the conversant /// is usually the NPC. /// /// /// StartConversation("Shopkeeper Conversation", player, shopkeeper); /// public static void StartConversation(string title, Transform actor, Transform conversant) { if (!hasInstance) return; instance.StartConversation(title, actor, conversant); } /// /// Starts a conversation, which also broadcasts an OnConversationStart message to the /// actor. Your scripts can listen for OnConversationStart to do anything /// necessary at the beginning of a conversation, such as pausing other gameplay or /// temporarily disabling player control. See the Feature Demo scene, which uses the /// SetEnabledOnDialogueEvent component to disable player control during conversations. /// /// /// The title of the conversation to look up in the master database. /// /// /// The transform of the actor (primary participant). The sequencer uses this to direct /// camera angles and perform other actions. In PC-NPC conversations, the actor is usually /// the PC. /// public static void StartConversation(string title, Transform actor) { if (!hasInstance) return; instance.StartConversation(title, actor); } /// /// Starts the conversation with no transforms specified for the actor or conversant. /// /// /// The title of the conversation to look up in the master database. /// public static void StartConversation(string title) { if (!hasInstance) return; instance.StartConversation(title, null, null); } /// /// Stop the current conversation immediately, and sends an OnConversationEnd message to /// the actor and conversant. Your scripts can listen for OnConversationEnd to do anything /// necessary at the end of a conversation, such as resuming other gameplay or re-enabling /// player control. /// public static void StopConversation() { if (!hasInstance) return; instance.StopConversation(); } /// /// Stops all current conversations immediately. /// public static void StopAllConversations() { if (!hasInstance) return; instance.StopAllConversations(); } /// /// Updates the responses for the current state of the current conversation. /// If the response menu entries' conditions have changed while the response menu is /// being shown, you can call this method to update the response menu. /// public static void UpdateResponses() { if (!hasInstance) return; instance.UpdateResponses(); } /// /// Sets continue button mode to Always (true) or Never (false). /// Before changing, records current mode so you can use /// SetOriginalContinueMode() to revert the setting. /// public static void SetContinueMode(bool value) { if (instance != null) instance.SetContinueMode(value); } /// /// Sets continue button mode. /// Before changing, records current mode so you can use /// SetOriginalContinueMode() to revert the setting. /// public static void SetContinueMode(DisplaySettings.SubtitleSettings.ContinueButtonMode mode) { if (instance != null) instance.SetContinueMode(mode); } /// /// Reverts continue button mode to the previously-saved mode. /// public static void SetOriginalContinueMode() { if (instance != null) instance.SetOriginalContinueMode(); } /// /// Changes an actor's Display Name. /// /// Actor's Name field. /// New Display Name value. public static void ChangeActorName(string actorName, string newDisplayName) { DialogueSystemController.ChangeActorName(actorName, newDisplayName); } /// /// Causes a character to bark a line at another character. A bark is a line spoken outside /// of a full conversation. It uses a simple gameplay bark UI instead of the dialogue UI. /// /// /// Title of the conversation that contains the bark lines. In this conversation, all /// dialogue entries linked from the first entry are considered bark lines. /// /// /// The character barking the line. /// /// /// The character being barked at. /// /// /// Bark history used to track the most recent bark, so the bark controller can go through /// the bark lines in a specified order. /// public static void Bark(string conversationTitle, Transform speaker, Transform listener, BarkHistory barkHistory) { if (!hasInstance) return; instance.Bark(conversationTitle, speaker, listener, barkHistory); } /// /// Causes a character to bark a line at another character. A bark is a line spoken outside /// of a full conversation. It uses a simple gameplay bark UI instead of the dialogue UI. /// /// /// Title of the conversation that contains the bark lines. In this conversation, all /// dialogue entries linked from the first entry are considered bark lines. /// /// /// The character barking the line. /// /// /// The character being barked at. /// /// Dialogue entry ID to bark. public static void Bark(string conversationTitle, Transform speaker, Transform listener, int entryID) { if (!hasInstance) return; instance.Bark(conversationTitle, speaker, listener, entryID); } /// /// Causes a character to bark a line at another character. A bark is a line spoken outside /// of a full conversation. It uses a simple gameplay bark UI instead of the dialogue UI. /// Since this form of the Bark() method does not include a BarkHistory, a random bark is /// selected from the bark lines. /// /// /// Title of the conversation that contains the bark lines. In this conversation, all /// dialogue entries linked from the first entry are considered bark lines. /// /// /// The character barking the line. /// /// /// The character being barked at. /// public static void Bark(string conversationTitle, Transform speaker, Transform listener) { if (!hasInstance) return; instance.Bark(conversationTitle, speaker, listener); } /// /// Causes a character to bark a line. A bark is a line spoken outside /// of a full conversation. It uses a simple gameplay bark UI instead of the dialogue UI. /// Since this form of the Bark() method does not include a BarkHistory, a random bark is /// selected from the bark lines. /// /// /// Title of the conversation that contains the bark lines. In this conversation, all /// dialogue entries linked from the first entry are considered bark lines. /// /// /// The character barking the line. /// public static void Bark(string conversationTitle, Transform speaker) { if (!hasInstance) return; instance.Bark(conversationTitle, speaker); } /// /// Causes a character to bark a line. A bark is a line spoken outside /// of a full conversation. It uses a simple gameplay bark UI instead of the dialogue UI. /// /// /// Title of the conversation that contains the bark lines. In this conversation, all /// dialogue entries linked from the first entry are considered bark lines. /// /// /// The character barking the line. /// /// /// Bark history used to track the most recent bark, so the bark controller can go through /// the bark lines in a specified order. /// public static void Bark(string conversationTitle, Transform speaker, BarkHistory barkHistory) { if (!hasInstance) return; instance.Bark(conversationTitle, speaker, barkHistory); } /// /// Causes a character to bark a literal string instead of looking up its line from /// a conversation. /// /// The string to bark. /// The barker. /// The target of the bark. (May be null) /// The optional sequence to play. (May be null or empty) public static void BarkString(string barkText, Transform speaker, Transform listener = null, string sequence = null) { if (!hasInstance) return; instance.BarkString(barkText, speaker, listener, sequence); } /// /// Returns the default duration that a string of bark text will be shown. /// /// The text that will be barked (to determine the duration). /// The default duration in seconds for the specified bark text. public static float GetBarkDuration(string barkText) { return hasInstance ? instance.GetBarkDuration(barkText) : 0; } /// /// Shows an alert message using the dialogue UI. /// /// /// The message to show. /// /// /// The duration in seconds to show the message. /// public static void ShowAlert(string message, float duration) { if (!hasInstance) return; instance.ShowAlert(message, duration); } /// /// Shows an alert message using the dialogue UI for the UI's default duration. /// /// /// The message to show. /// public static void ShowAlert(string message) { if (!hasInstance) return; instance.ShowAlert(message); } /// /// Checks Lua Variable['Alert'] to see if we need to show an alert. /// public static void CheckAlerts() { if (!hasInstance) return; instance.CheckAlerts(); } /// /// Hides the currently-displaying alert message. /// public static void HideAlert() { if (!hasInstance) return; instance.HideAlert(); } /// /// Hides the currently-displaying alert message and clears any pending queued alerts. /// public static void HideAllAlerts() { if (!hasInstance) return; instance.HideAllAlerts(); } /// /// Gets localized text. /// /// If the specified field exists in the text tables, returns the field's /// localized text for the current language. Otherwise returns the field itself. /// The field to look up. public static string GetLocalizedText(string s) { return hasInstance ? instance.GetLocalizedText(s) : s; } /// /// Starts a sequence. See @ref sequencer. /// /// The sequence to play. /// The speaker, for sequence commands that reference the speaker. /// The listener, for sequence commands that reference the listener. /// Specifies whether to send OnSequenceStart and OnSequenceEnd messages to the speaker and listener. Default is true. /// Specifies whether destroy the sequencer when done playing the sequence. Default is /// The entrytag to associate with the sequence. /// The sequencer that is playing the sequence. public static Sequencer PlaySequence(string sequence, Transform speaker, Transform listener, bool informParticipants, bool destroyWhenDone, string entrytag) { return hasInstance ? instance.PlaySequence(sequence, speaker, listener, informParticipants, destroyWhenDone, entrytag) : null; } /// /// Starts a sequence. See @ref sequencer. /// /// /// The sequencer that is playing the sequence. /// /// /// The sequence to play. /// /// /// The speaker, for sequence commands that reference the speaker. /// /// /// The listener, for sequence commands that reference the listener. /// /// /// Specifies whether to send OnSequenceStart and OnSequenceEnd messages to the speaker and /// listener. Default is true. /// /// /// Specifies whether destroy the sequencer when done playing the sequence. Default is /// true. /// public static Sequencer PlaySequence(string sequence, Transform speaker, Transform listener, bool informParticipants, bool destroyWhenDone) { return hasInstance ? instance.PlaySequence(sequence, speaker, listener, informParticipants, destroyWhenDone) : null; } /// /// Starts a sequence. See @ref sequencer. /// /// /// The sequencer that is playing the sequence. /// /// /// The sequence to play. /// /// /// The speaker, for sequence commands that reference the speaker. /// /// /// The listener, for sequence commands that reference the listener. /// /// /// Specifies whether to send OnSequenceStart and OnSequenceEnd messages to the speaker and /// listener. Default is true. /// public static Sequencer PlaySequence(string sequence, Transform speaker, Transform listener, bool informParticipants) { return hasInstance ? instance.PlaySequence(sequence, speaker, listener, informParticipants) : null; } /// /// Starts a sequence, and sends OnSequenceStart/OnSequenceEnd messages to the /// participants. See @ref sequencer. /// /// /// The sequencer that is playing the sequence. /// /// /// The sequence to play. /// /// /// The speaker, for sequence commands that reference the speaker. /// /// /// The listener, for sequence commands that reference the listener. /// public static Sequencer PlaySequence(string sequence, Transform speaker, Transform listener) { return hasInstance ? instance.PlaySequence(sequence, speaker, listener) : null; } /// /// Starts a sequence. See @ref sequencer. /// /// /// The sequencer that is playing the sequence. /// /// /// The sequence to play. /// public static Sequencer PlaySequence(string sequence) { return hasInstance ? instance.PlaySequence(sequence) : null; } /// /// Stops a sequence. /// /// /// The sequencer playing the sequence. /// public static void StopSequence(Sequencer sequencer) { instance.StopSequence(sequencer); } /// /// Pauses the Dialogue System. Also broadcasts OnDialogueSystemPause to /// the Dialogue Manager and conversation participants. Conversations, /// timers, typewriter and fade effects, and the AudioWait() and Voice() /// sequencer commands will be paused. Other than this, AudioSource, /// Animation, and Animator components will not be paused; it's up to /// you to handle them as appropriate for your project. /// public static void Pause() { if (!hasInstance) return; instance.Pause(); } /// /// Unpauses the Dialogue System. Also broadcasts OnDialogueSystemUnpause to /// the Dialogue Manager and conversation participants. /// public static void Unpause() { if (!hasInstance) return; instance.Unpause(); } /// /// Sets the dialogue UI. /// /// /// Game object containing an implementation of IDialogueUI. /// public static void UseDialogueUI(GameObject gameObject) { instance.UseDialogueUI(gameObject); } /// /// Sets the dialogue UI's main panel visible or invisible. /// /// If true, show (or re-show) the panel; if false, hide it. /// If true, skip animation and change immediately. public static void SetDialoguePanel(bool show, bool immediate = false) { instance.SetDialoguePanel(show, immediate); } /// /// Sets an actor's portrait. If can be: /// - 'default' or null to use the primary portrait defined in the database, /// - 'pic=#' to use an alternate portrait defined in the database (numbered from 2), or /// - the name of a texture in a Resources folder. /// /// Actor name. /// Portrait name. public static void SetPortrait(string actorName, string portraitName) { if (!hasInstance) return; instance.SetPortrait(actorName, portraitName); } /// /// Adds a Lua expression observer. /// /// /// Lua expression to watch. /// /// /// Frequency to check the expression. /// /// /// Delegate to call when the expression changes. This should be in the form: /// void MyDelegate(LuaWatchItem luaWatchItem, Lua.Result newValue) {...} /// public static void AddLuaObserver(string luaExpression, LuaWatchFrequency frequency, LuaChangedDelegate luaChangedHandler) { if (!hasInstance) return; instance.AddLuaObserver(luaExpression, frequency, luaChangedHandler); } /// /// Removes a Lua expression observer. To be removed, the expression, frequency, and /// notification delegate must all match. /// /// /// Lua expression being watched. /// /// /// Frequency that the expression is being watched. /// /// /// Delegate that's called when the expression changes. /// public static void RemoveLuaObserver(string luaExpression, LuaWatchFrequency frequency, LuaChangedDelegate luaChangedHandler) { if (!hasInstance) return; instance.RemoveLuaObserver(luaExpression, frequency, luaChangedHandler); } /// /// Removes all Lua expression observers for a specified frequency. /// /// /// Frequency. /// public static void RemoveAllObservers(LuaWatchFrequency frequency) { if (!hasInstance) return; instance.RemoveAllObservers(frequency); } /// /// Removes all Lua expression observers. /// public static void RemoveAllObservers() { if (!hasInstance) return; instance.RemoveAllObservers(); } /// /// Registers an asset bundle with the Dialogue System. This allows sequencer /// commands to load assets inside it. /// /// Asset bundle. public static void RegisterAssetBundle(AssetBundle bundle) { if (!hasInstance) return; instance.RegisterAssetBundle(bundle); } /// /// Unregisters an asset bundle from the Dialogue System. Always unregister /// asset bundles before freeing them. /// /// Asset bundle. public static void UnregisterAssetBundle(AssetBundle bundle) { if (!hasInstance) return; instance.UnregisterAssetBundle(bundle); } /// /// Loads a named asset from the registered asset bundles or from Resources. /// Note: This version now also works with Addressables, and works synchronously. /// /// The asset, or null if not found. /// Name of the asset. public static UnityEngine.Object LoadAsset(string name) { return hasInstance ? instance.LoadAsset(name) : null; } /// /// Loads a named asset from the registered asset bundles or from Resources. /// Note: This version now also works with Addressables, and works synchronously. /// /// The asset, or null if not found. /// Name of the asset. /// Type of the asset. public static UnityEngine.Object LoadAsset(string name, System.Type type) { return hasInstance ? instance.LoadAsset(name, type) : null; } /// /// Loads a named asset from the registered asset bundles, Resources, or /// Addressables. Returns the asset in a callback delegate. Addressables /// will be unloaded when the scene is unloaded. To unload them earlier, /// use DialogueManager.UnloadAsset(). /// /// By default, scene changes unload all addressables loaded via /// DialogueManager.LoadAsset(). To prevent the unload, set /// DialogueManager.instance.unloadAddressablesOnSceneChange to false. /// /// Name of the asset. /// Type of the asset /// Delegate method to call when returning loaded asset, or null if not found. public static void LoadAsset(string name, System.Type type, AssetLoadedDelegate assetLoaded) { if (hasInstance) { instance.LoadAsset(name, type, assetLoaded); } else if (assetLoaded != null) { assetLoaded(null); } } /// /// Unloads an object previously loaded by LoadAsset. Only unloads /// if using addressables. /// public static void UnloadAsset(object obj) { if (hasInstance) instance.UnloadAsset(obj); } /// /// Sends an "UpdateTracker" message to the Dialogue Manager, which may have a quest tracker component /// that listens for this message, /// public static void SendUpdateTracker() { if (!hasInstance) return; instance.BroadcastMessage(DialogueSystemMessages.UpdateTracker, SendMessageOptions.DontRequireReceiver); } } }