[HOWTO] How To: Accumulate Text With Multiple Subtitle Panels

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
Tony Li
Posts: 20705
Joined: Thu Jul 18, 2013 1:27 pm

[HOWTO] How To: Accumulate Text With Multiple Subtitle Panels

Post by Tony Li »

The Standard UI Subtitle Panel component's Accumulate Text only accumulates its own subtitle text. If you need to accumulate text across multiple subtitle panels -- for example to show multiple portrait images -- use this subclass in place of StandardUISubtitlePanel:

SharedTextSubtitlePanel.cs

Code: Select all

using System.Collections.Generic;
using UnityEngine;

namespace PixelCrushers.DialogueSystem
{

    public class SharedTextSubtitlePanel : StandardUISubtitlePanel
    {
        private List<SharedTextSubtitlePanel> m_otherPanels = new List<SharedTextSubtitlePanel>();

        protected override void Awake()
        {
            base.Awake();
            foreach (Transform t in transform.parent)
            {
                if (t == this.transform) continue;
                var otherPanel = t.GetComponent<SharedTextSubtitlePanel>();
                if (otherPanel != null) m_otherPanels.Add(otherPanel);
            }
        }

        public override void ClearText()
        {
            base.ClearText();
            m_otherPanels.ForEach(panel => panel.accumulatedText = string.Empty);
        }

        protected override void SetSubtitleTextContent(Subtitle subtitle)
        {
            base.SetSubtitleTextContent(subtitle);
            m_otherPanels.ForEach(panel => panel.accumulatedText = accumulatedText);
        }
    }
}
Example scene:

DS_SharedTextSubtitlePanelExample_2023-07-12.unitypackage
Post Reply