FullScreenTextView.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using UnityEngine;
  2. using FairyGUI;
  3. using UI.Launcher;
  4. using System;
  5. namespace GFGGame
  6. {
  7. public class FullScreenTextView
  8. {
  9. private static FullScreenTextView m_Instance = null;
  10. /// <summary>
  11. /// 单例
  12. /// </summary>
  13. public static FullScreenTextView Instance
  14. {
  15. get
  16. {
  17. if (m_Instance == null)
  18. {
  19. m_Instance = new FullScreenTextView();
  20. }
  21. return m_Instance;
  22. }
  23. }
  24. private UI_FullScreenTextUI _ui;
  25. /// <summary>
  26. /// FairyGUI包名
  27. /// </summary>
  28. private string _packageName;
  29. public void Dispose()
  30. {
  31. if (_ui != null)
  32. {
  33. _ui.Dispose();
  34. _ui = null;
  35. }
  36. }
  37. public FullScreenTextView()
  38. {
  39. _packageName = UI_FullScreenTextUI.PACKAGE_NAME;
  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 eventName)
  47. {
  48. GRoot.inst.AddChild(_ui.target);
  49. _ui.m_txtComp.m_txtContent.text = "加载中...";
  50. _ui.m_txtComp.target.scrollPane.ScrollTop();
  51. LoadText(eventName);
  52. Timers.inst.AddUpdate(Update);
  53. }
  54. public void Hide()
  55. {
  56. Timers.inst.Remove(Update);
  57. _ui.target.RemoveFromParent();
  58. }
  59. private void Update(object param)
  60. {
  61. if (Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.Home))
  62. {
  63. this.Hide();
  64. }
  65. }
  66. private void LoadText(string eventName)
  67. {
  68. string fileName = null;
  69. switch (eventName)
  70. {
  71. case "event:a":
  72. fileName = "serviceProtocal";
  73. break;
  74. case "event:b":
  75. fileName = "privacyPolicy";
  76. break;
  77. case "event:c":
  78. fileName = "privacyPolicyChildren";
  79. break;
  80. default:
  81. return;
  82. }
  83. string url = string.Format(LauncherConfig.privacy_v, fileName);
  84. HttpTool.Instance.Get(url, (string content) =>
  85. {
  86. _ui.m_txtComp.m_txtContent.text = content;
  87. });
  88. }
  89. }
  90. }