Skip to content

Instantly share code, notes, and snippets.

@digiwombat
Created July 4, 2021 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save digiwombat/59b3692c225c49817a7aa89ac5bcf186 to your computer and use it in GitHub Desktop.
Save digiwombat/59b3692c225c49817a7aa89ac5bcf186 to your computer and use it in GitHub Desktop.
using PixelCrushers.DialogueSystem.SuperTextMeshSupport;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SequenceSubtitlePanel : SuperTextMeshSubtitlePanel
{
public override void Open()
{
if (panelState == PanelState.Open || panelState == PanelState.Opening) return;
panelState = PanelState.Opening;
gameObject.SetActive(true);
onOpen.Invoke();
SequenceHandler.Instance.StartCutscene("ShowDialogueBox");
// With quick panel changes, panel may not reach OnEnable/OnDisable before being reused.
// Update panelStack here also to handle this case:
if (gameObject.activeInHierarchy) StartCoroutine(OpenFinished());
PushToPanelStack();
}
private IEnumerator OpenFinished()
{
yield return new WaitForSecondsRealtime(0.2f);
base.OnVisible();
}
private IEnumerator CloseFinished()
{
//Debug.Log("Starting to Close Dialogue UI");
yield return new WaitForSecondsRealtime(0.2f);
//Debug.Log("Closing all UI");
base.OnHidden();
}
public override void Close()
{
PopFromPanelStack();
if (gameObject.activeInHierarchy) CancelInvoke();
if (panelState == PanelState.Closed || panelState == PanelState.Closing) return;
panelState = PanelState.Closing;
onClose.Invoke();
SequenceHandler.Instance.StartCutscene("HideDialogueBox");
if (gameObject.activeInHierarchy) StartCoroutine(CloseFinished());
// Deselect ours:
if (UnityEngine.EventSystems.EventSystem.current != null && selectables.Contains(UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject))
{
UnityEngine.EventSystems.EventSystem.current.SetSelectedGameObject(null);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment