Standard UI subtitle panel : animation when speaker changes

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
Strook
Posts: 70
Joined: Fri Nov 08, 2019 10:51 am

Standard UI subtitle panel : animation when speaker changes

Post by Strook »

Hello !

Is it possible to trigger an animation, event or animation every time the speaker changes ? Note that to i only want animate the subtitle panel.

I have a lot of dialogues where two actors speak on after each other, i would like to add an animation to to the Portrait Name when the speaker changes.

The standard UI subtitle panel component has the possibility to set Show/Hide/Focus/Unfocus triggers, how would one go about triggering something "on Speaker changed" ?

Thanks!
Currently working on ->Squeakross: Home Squeak Home<- Using Dialogue System Save System and other features.
Previous game made with Dialogue system ->The Spirit and The mouse<-
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: Standard UI subtitle panel : animation when speaker changes

Post by Tony Li »

Hi,

It's probably most straightforward to add a script with an OnConversationLine method to the Dialogue Manager, or to the dialogue UI if it's a child of the Dialogue Manager. Example:

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class AnimateNewPortraitNames : MonoBehaviour
{
    public string lastSpeakerName;
    
    void OnConversationStart(Transform actor) { lastSpeakerName = string.Empty; }
    
    void OnConversationLine(Subtitle subtitle)
    {
        // Has the speaker changed?
        // (Note that this method also runs for the player's lines even if they're not shown as a subtitle.)
        if (subtitle.speakerInfo.Name != lastSpeakerName)
        {
            lastSpeakerName = subtitle.speakerInfo.Name;
            
            // Identify which subtitle panel the subtitle will use:
            DialogueActor dialogueActor;
            var subtitlePanels = (DialogueManager.dialogueUI as StandardDialogueUI).conversationUIElements.subtitleControls;
            var subtitlePanel = subtitlePanels.GetPanel(subtitle, out dialogueActor);
            
            // Play some animation on the subtitle panel's Portrait Name:
            subtitlePanel.portraitName.GetComponent<Animator>().Play("Some Animation State");
        }
    }
}
User avatar
Strook
Posts: 70
Joined: Fri Nov 08, 2019 10:51 am

Re: Standard UI subtitle panel : animation when speaker changes

Post by Strook »

Ooh thats perfect, thank you Tony!
Currently working on ->Squeakross: Home Squeak Home<- Using Dialogue System Save System and other features.
Previous game made with Dialogue system ->The Spirit and The mouse<-
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: Standard UI subtitle panel : animation when speaker changes

Post by Tony Li »

Happy to help!
Post Reply