/// <summary> /// /// </summary> /// <param name="pText">Text to be shown</param> /// <param name="pWidth">Width of the box</param> /// <param name="pHeight">Height of the box, will be adjusted if text wrap</param> /// <param name="duration">Duration of the exhibition before close, default is 0</param> /// <param name="delay">Delay before the text show</param> /// <param name="lockPlayer">Lock player input</param> /// <param name="onFinished">callback to be executed after textbox finish</param> /// <param name="fade">if the box will be fade/inout</param> /// <returns></returns> public TextBox ShowTextBox(string pText, int pWidth, int pHeight, int duration = 0, int delay = 0, bool lockPlayer = false, TextBox.OnFinished onFinished = null, bool fade = true) { var textBox = new TextBox(pText, pWidth, pHeight); if (duration > 0) { textBox.ShowPressAnyKeyToNext = false; } textBox.CenterOnBottom(); CoroutineManager.StartCoroutine(ShowTextBoxRoutine(textBox, duration, delay, lockPlayer, onFinished, fade), this); return(textBox); }
IEnumerator ShowTextBoxRoutine(TextBox textBox, int duration, int delay, bool lockPlayer, TextBox.OnFinished onFinished, bool fade) { bool lastPlayerLockState = false; if (lockPlayer && _level?.Player != null) { lastPlayerLockState = _level.Player.InputEnabled; _level.Player.InputEnabled = false; } if (delay > 0) { yield return(new WaitForMilliSeconds(delay)); } HierarchyManager.Instance.LateAdd(this, textBox); if (fade) { DrawableTweener.TweenSpriteAlpha(textBox, 0, 1, Settings.Default_AlphaTween_Duration); } yield return(textBox.TweenTextRoutine(0, Settings.Flashbacks_TextBoxTweenSpeed, duration == 0 ? true : false)); int time = 0; while (time < (duration + Settings.Default_AlphaTween_Duration)) { yield return(null); time += Time.deltaTime; } if (fade) { DrawableTweener.TweenSpriteAlpha(textBox, 1, 0, Settings.Default_AlphaTween_Duration, () => { HierarchyManager.Instance.LateDestroy(textBox); if (lockPlayer && _level?.Player != null) { _level.Player.InputEnabled = lastPlayerLockState; } onFinished?.Invoke(); }); } else { HierarchyManager.Instance.LateDestroy(textBox); if (_level?.Player != null) { _level.Player.InputEnabled = true; } onFinished?.Invoke(); } }