FullScreenTextView.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using UnityEngine;
  2. using FairyGUI;
  3. using UI.Launcher;
  4. namespace GFGGame
  5. {
  6. public class FullScreenTextView
  7. {
  8. private static FullScreenTextView m_Instance = null;
  9. /// <summary>
  10. /// ľĽŔý
  11. /// </summary>
  12. public static FullScreenTextView Instance
  13. {
  14. get
  15. {
  16. if (m_Instance == null)
  17. {
  18. m_Instance = new FullScreenTextView();
  19. }
  20. return m_Instance;
  21. }
  22. }
  23. private UI_FullScreenTextUI _ui;
  24. /// <summary>
  25. /// FairyGUI°üĂű
  26. /// </summary>
  27. private string _packageName;
  28. public void Dispose()
  29. {
  30. if (_ui != null)
  31. {
  32. _ui.Dispose();
  33. _ui = null;
  34. }
  35. }
  36. public FullScreenTextView()
  37. {
  38. _packageName = UI_FullScreenTextUI.PACKAGE_NAME;
  39. _ui = UI_FullScreenTextUI.Create();
  40. UIPackage.AddPackage("UI/" + _packageName + "/" + _packageName);
  41. _ui = UI_FullScreenTextUI.Create();
  42. _ui.target.MakeFullScreen();
  43. _ui.target.AddRelation(GRoot.inst, RelationType.Size);
  44. _ui.m_btnBack.onClick.Add(this.Hide);
  45. }
  46. public void Show(string content)
  47. {
  48. GRoot.inst.AddChild(_ui.target);
  49. _ui.m_txtComp.m_txtContent.text = content;
  50. _ui.m_txtComp.target.scrollPane.ScrollTop();
  51. Timers.inst.AddUpdate(Update);
  52. }
  53. public void Hide()
  54. {
  55. Timers.inst.Remove(Update);
  56. _ui.target.RemoveFromParent();
  57. }
  58. private void Update(object param)
  59. {
  60. if (Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.Home))
  61. {
  62. this.Hide();
  63. }
  64. }
  65. }
  66. }