Advertisement
Guest User

Assets.Scripts.Ui.ModTestDialogScript (SR2TestMod)

a guest
Jun 25th, 2019
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.43 KB | None | 0 0
  1. namespace Assets.Scripts.Ui
  2. {
  3.     using System;
  4.     using System.Collections;
  5.     using System.Collections.Generic;
  6.     using System.Linq;
  7.     using System.Text;
  8.     using ModApi.Ui;
  9.     using TMPro;
  10.     using UnityEngine;
  11.  
  12.     /// <summary>
  13.     /// A test dialog script for a mod.
  14.     /// </summary>
  15.     /// <seealso cref="ModApi.Ui.DialogScript" />
  16.     public class ModTestDialogScript : DialogScript
  17.     {
  18.         /// <summary>
  19.         /// The default dialog text.
  20.         /// </summary>
  21.         private string _defaultDialogText;
  22.  
  23.         /// <summary>
  24.         /// The dialog text component.
  25.         /// </summary>
  26.         private TextMeshProUGUI _dialogText;
  27.  
  28.         /// <summary>
  29.         /// The dialog text element.
  30.         /// </summary>
  31.         private IXmlElement _dialogTextElement;
  32.  
  33.         /// <summary>
  34.         /// The XML layout reference.
  35.         /// </summary>
  36.         private IXmlLayout _xmlLayout;
  37.  
  38.         /// <summary>
  39.         /// Closes the dialog.
  40.         /// </summary>
  41.         public override void Close()
  42.         {
  43.             base.Close();
  44.  
  45.             this._xmlLayout.Hide(() => GameObject.Destroy(this.gameObject), true);
  46.         }
  47.  
  48.         /// <summary>
  49.         /// Called when the dialog is clicked.
  50.         /// </summary>
  51.         public void OnClick()
  52.         {
  53.             Debug.Log("ModTestDialog OnClick");
  54.             this.Close();
  55.         }
  56.  
  57.         /// <summary>
  58.         /// Called when the UI layout is rebuilt.
  59.         /// </summary>
  60.         /// <param name="xmlLayout">The XML layout.</param>
  61.         public void OnLayoutRebuilt(IXmlLayout xmlLayout)
  62.         {
  63.             this._xmlLayout = xmlLayout;
  64.             this._dialogTextElement = xmlLayout.GetElementById("dialog-text");
  65.             this._dialogText = this._dialogTextElement.GameObject.GetComponent<TextMeshProUGUI>();
  66.             this._defaultDialogText = this._dialogText.text;
  67.         }
  68.  
  69.         /// <summary>
  70.         /// Unity Start method.
  71.         /// </summary>
  72.         protected override void Start()
  73.         {
  74.             base.Start();
  75.  
  76.             this.StartCoroutine(this.BlinkTextCoroutine());
  77.         }
  78.  
  79.         /// <summary>
  80.         /// The coroutine used for blinking the dialog text.
  81.         /// </summary>
  82.         /// <returns>The enumerator for the coroutine.</returns>
  83.         private IEnumerator BlinkTextCoroutine()
  84.         {
  85.             while (true)
  86.             {
  87.                 if (this._dialogText == null || this._dialogTextElement == null)
  88.                 {
  89.                     yield return new WaitForSeconds(1f);
  90.                     continue;
  91.                 }
  92.  
  93.                 this._dialogTextElement.Show();
  94.                 this._dialogText.text = this._defaultDialogText;
  95.                 yield return new WaitForSeconds(0.5f);
  96.                 this._dialogText.text = this._defaultDialogText + ".";
  97.                 yield return new WaitForSeconds(0.5f);
  98.                 this._dialogText.text = this._defaultDialogText + "..";
  99.                 yield return new WaitForSeconds(0.5f);
  100.                 this._dialogText.text = this._defaultDialogText + "...";
  101.                 yield return new WaitForSeconds(0.5f);
  102.                 this._dialogText.text = this._defaultDialogText + "....";
  103.                 yield return new WaitForSeconds(0.5f);
  104.                 this._dialogTextElement.Hide();
  105.                 yield return new WaitForSeconds(0.5f);
  106.             }
  107.         }
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement