URIDialog.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.Events;
  4. using UnityEngine.UI;
  5. namespace TriLib.Samples
  6. {
  7. public class URIDialog : MonoBehaviour
  8. {
  9. public static URIDialog Instance { get; private set; }
  10. public string Filename
  11. {
  12. get
  13. {
  14. return this._uriText.text;
  15. }
  16. set
  17. {
  18. this._uriText.text = value;
  19. }
  20. }
  21. public string Extension
  22. {
  23. get
  24. {
  25. return this._extensionText.text;
  26. }
  27. set
  28. {
  29. this._extensionText.text = value;
  30. }
  31. }
  32. protected void Awake()
  33. {
  34. this._cancelButton.onClick.AddListener(new UnityAction(this.HideDialog));
  35. this._uriText.onValueChanged.AddListener(new UnityAction<string>(this.UpdateExtension));
  36. URIDialog.Instance = this;
  37. }
  38. public void ShowDialog(Action<string, string> onOk)
  39. {
  40. this._okButton.onClick.RemoveAllListeners();
  41. this._okButton.onClick.AddListener(delegate()
  42. {
  43. if (onOk != null)
  44. {
  45. onOk(this.Filename, this.Extension);
  46. }
  47. this.HideDialog();
  48. });
  49. this._rendererGameObject.SetActive(true);
  50. }
  51. public void HideDialog()
  52. {
  53. this._rendererGameObject.SetActive(false);
  54. }
  55. private void UpdateExtension(string text)
  56. {
  57. this._extensionText.text = FileUtils.GetFileExtension(text);
  58. }
  59. [SerializeField]
  60. private Button _okButton;
  61. [SerializeField]
  62. private Button _cancelButton;
  63. [SerializeField]
  64. private InputField _uriText;
  65. [SerializeField]
  66. private InputField _extensionText;
  67. [SerializeField]
  68. private GameObject _rendererGameObject;
  69. }
  70. }