Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Assets.Scripts.Ui
- {
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using ModApi.Ui;
- using TMPro;
- using UnityEngine;
- /// <summary>
- /// A test dialog script for a mod.
- /// </summary>
- /// <seealso cref="ModApi.Ui.DialogScript" />
- public class ModTestDialogScript : DialogScript
- {
- /// <summary>
- /// The default dialog text.
- /// </summary>
- private string _defaultDialogText;
- /// <summary>
- /// The dialog text component.
- /// </summary>
- private TextMeshProUGUI _dialogText;
- /// <summary>
- /// The dialog text element.
- /// </summary>
- private IXmlElement _dialogTextElement;
- /// <summary>
- /// The XML layout reference.
- /// </summary>
- private IXmlLayout _xmlLayout;
- /// <summary>
- /// Closes the dialog.
- /// </summary>
- public override void Close()
- {
- base.Close();
- this._xmlLayout.Hide(() => GameObject.Destroy(this.gameObject), true);
- }
- /// <summary>
- /// Called when the dialog is clicked.
- /// </summary>
- public void OnClick()
- {
- Debug.Log("ModTestDialog OnClick");
- this.Close();
- }
- /// <summary>
- /// Called when the UI layout is rebuilt.
- /// </summary>
- /// <param name="xmlLayout">The XML layout.</param>
- public void OnLayoutRebuilt(IXmlLayout xmlLayout)
- {
- this._xmlLayout = xmlLayout;
- this._dialogTextElement = xmlLayout.GetElementById("dialog-text");
- this._dialogText = this._dialogTextElement.GameObject.GetComponent<TextMeshProUGUI>();
- this._defaultDialogText = this._dialogText.text;
- }
- /// <summary>
- /// Unity Start method.
- /// </summary>
- protected override void Start()
- {
- base.Start();
- this.StartCoroutine(this.BlinkTextCoroutine());
- }
- /// <summary>
- /// The coroutine used for blinking the dialog text.
- /// </summary>
- /// <returns>The enumerator for the coroutine.</returns>
- private IEnumerator BlinkTextCoroutine()
- {
- while (true)
- {
- if (this._dialogText == null || this._dialogTextElement == null)
- {
- yield return new WaitForSeconds(1f);
- continue;
- }
- this._dialogTextElement.Show();
- this._dialogText.text = this._defaultDialogText;
- yield return new WaitForSeconds(0.5f);
- this._dialogText.text = this._defaultDialogText + ".";
- yield return new WaitForSeconds(0.5f);
- this._dialogText.text = this._defaultDialogText + "..";
- yield return new WaitForSeconds(0.5f);
- this._dialogText.text = this._defaultDialogText + "...";
- yield return new WaitForSeconds(0.5f);
- this._dialogText.text = this._defaultDialogText + "....";
- yield return new WaitForSeconds(0.5f);
- this._dialogTextElement.Hide();
- yield return new WaitForSeconds(0.5f);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement