Guest User

Assets.Scripts.Ui.MainMenuModButtonScript (SR2TestMod)

a guest
Jun 25th, 2019
796
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.85 KB | None | 0 0
  1. namespace Assets.Scripts.Ui
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.     using System.Text;
  7.     using ModApi.Common;
  8.     using ModApi.Ui;
  9.     using UnityEngine;
  10.  
  11.     /// <summary>
  12.     /// Ascript for managing the main menu mod button UI.
  13.     /// </summary>
  14.     /// <seealso cref="UnityEngine.MonoBehaviour" />
  15.     public class MainMenuModButtonScript : MonoBehaviour
  16.     {
  17.         /// <summary>
  18.         /// The dialog reference.
  19.         /// </summary>
  20.         private ModTestDialogScript _dialog;
  21.  
  22.         /// <summary>
  23.         /// Called when the button is clicked.
  24.         /// </summary>
  25.         /// <param name="element">The element.</param>
  26.         public void OnClick(UI.Xml.XmlElement element)
  27.         {
  28.             Debug.Log("Clicked Main Menu Mod Button");
  29.             Debug.Log("Clicked Element: " + element?.name ?? "null");
  30.  
  31.             if (this._dialog == null)
  32.             {
  33.                 this._dialog = Game.Instance.UserInterface.CreateDialog<ModTestDialogScript>(
  34.                     "SR2TestMod/Xml/ModTestDialog", null, (d, c) => d.OnLayoutRebuilt(c.XmlLayout));
  35.                 this._dialog.Closed += this.DialogClosed;
  36.             }
  37.             else
  38.             {
  39.                 this._dialog.Close();
  40.             }
  41.         }
  42.  
  43.         /// <summary>
  44.         /// Called when the UI layout is rebuilt.
  45.         /// </summary>
  46.         /// <param name="xmlLayout">The XML layout.</param>
  47.         public void OnLayoutRebuilt(IXmlLayout xmlLayout)
  48.         {
  49.         }
  50.  
  51.         /// <summary>
  52.         /// Called when the dialog is closed.
  53.         /// </summary>
  54.         /// <param name="dialog">The dialog.</param>
  55.         private void DialogClosed(IDialog dialog)
  56.         {
  57.             this._dialog.Closed -= this.DialogClosed;
  58.             this._dialog = null;
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment