Page 1 of 1

Standard UI subtitle panel : animation when speaker changes

Posted: Sat Jan 23, 2021 5:08 pm
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!

Re: Standard UI subtitle panel : animation when speaker changes

Posted: Sat Jan 23, 2021 9:20 pm
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");
        }
    }
}

Re: Standard UI subtitle panel : animation when speaker changes

Posted: Sat Jan 23, 2021 11:46 pm
by Strook
Ooh thats perfect, thank you Tony!

Re: Standard UI subtitle panel : animation when speaker changes

Posted: Sun Jan 24, 2021 9:01 am
by Tony Li
Happy to help!