Page 1 of 1

How to clear portrait (hide portrait no sprite)

Posted: Thu Nov 05, 2020 3:33 am
by papapa909090
I need to hide upper (conversant's) portrait so only bottom portrait (actor's) is shown.

I have a previous dialogue when both portraits are shown but this dialogue is only for actor's thoughts so the upper (conversant's) portrait must be hidden

The only way I can clear upper (conversant's) portrait is to create a conversant node with only a space as dialogue text and assign a dialogue system's actor who has a transparent sprite, also set Delay(0) as a sequence

I was wandering if I'm doing it right, if there's better way I would love to learn it (searched forum, didn't find the answer)

Re: How to clear portrait (hide portrait no sprite)

Posted: Thu Nov 05, 2020 7:50 am
by Tony Li
Hi,

This post has two ways to hide a portrait. I'll recap them here:

1. Create a subtitle panel that is not visible. Use SetPanel() to change the actor to this panel.

2. Or call the subtitle panel's Close method. You can write a sequencer command to do that, or you can use the SendMessage() sequencer command like this:

Code: Select all

SendMessage(Close,,Subtitle Panel 2)
(Provide the GameObject name of the subtitle panel.)

A third way is to use a custom sequencer command. Here's a sequencer command that will hide a subtitle panel:

SequencerCommandHidePanel.cs

Code: Select all

using UnityEngine;

namespace PixelCrushers.DialogueSystem.SequencerCommands
{
    /// <summary>
    /// Syntax: HidePanel(panelNumber, [portrait])
    /// 
    /// - panelNumber: Panel number to hide.
    /// - portrait: If the keyword 'portrait' is included as a second parameter, only hides portrait.
    /// </summary>
    public class SequencerCommandHidePanel : SequencerCommand
    {
        private void Awake()
        {
            var panelNumber = GetParameterAsInt(0);
            var portraitOnly = string.Equals("portrait", GetParameter(1));
            var dialogueUI = DialogueManager.dialogueUI as StandardDialogueUI;
            if (dialogueUI == null)
            {
                if (DialogueDebug.logWarnings) Debug.LogWarning("Dialogue System: Sequencer: HidePanel(" + GetParameters() + ") can't run. Not using a Standard Dialogue UI.");
            }
            else if (!(0 <= panelNumber && panelNumber < dialogueUI.conversationUIElements.subtitlePanels.Length))
            {
                if (DialogueDebug.logWarnings) Debug.LogWarning("Dialogue System: Sequencer: HidePanel(" + GetParameters() + ") dialogue UI doesn't have panel #" + panelNumber + ".");
            }
            else
            {
                if (DialogueDebug.logInfo) Debug.Log("Dialogue System: Sequencer: HidePanel(" + GetParameters() + ")");
                var panel = dialogueUI.conversationUIElements.subtitlePanels[panelNumber];
                if (panel == null) return;
                if (portraitOnly)
                {
                    Tools.SetGameObjectActive(panel.portraitImage, false);
                    Tools.SetGameObjectActive(panel.portraitName.gameObject, false);
                }
                else
                {
                    panel.Close();
                }
            }
        }
    }
}
I will add this sequencer command to the next release of the Dialogue System.