[HOWTO] How To: Accumulate Text With Multiple Subtitle Panels
Posted: Sat Feb 19, 2022 3:48 pm
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
Example scene:
DS_SharedTextSubtitlePanelExample_2023-07-12.unitypackage
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);
}
}
}
DS_SharedTextSubtitlePanelExample_2023-07-12.unitypackage