LoginView.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using UnityEngine;
  2. using FairyGUI;
  3. using UI.Login;
  4. namespace GFGGame
  5. {
  6. public class LoginView : BaseView
  7. {
  8. private UI_LoginUI _ui;
  9. private GameObject _scenePrefab;
  10. private GameObject _sceneObject;
  11. public override void Dispose()
  12. {
  13. _ui = null;
  14. if(_scenePrefab != null)
  15. {
  16. GameObject.Destroy(_scenePrefab);
  17. _scenePrefab = null;
  18. }
  19. base.Dispose();
  20. }
  21. protected override void Init()
  22. {
  23. base.Init();
  24. packageName = UI_LoginUI.PACKAGE_NAME;
  25. _ui = UI_LoginUI.Create();
  26. viewCom = _ui.target;
  27. isfullScreen = true;
  28. _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("SceneMain"));
  29. }
  30. protected override void OnInit()
  31. {
  32. base.OnInit();
  33. _ui.m_txtVersion.text = GameGlobal.version;
  34. _ui.m_btnNotice.onClick.Add(OnClickBtnNotice);
  35. _ui.m_btnStart.onClick.Add(OnClickBtnStart);
  36. _ui.m_btnLogout.onClick.Add(OnClickBtnLogout);
  37. }
  38. protected override void OnShown()
  39. {
  40. base.OnShown();
  41. MusicManager.Instance.Play(ResPathUtil.GetMusicPath(ConstMusicName.DEFAULT));
  42. if (_sceneObject == null)
  43. {
  44. _sceneObject = GameObject.Instantiate(_scenePrefab);
  45. }
  46. SceneController.UpdateLoginScene(_sceneObject);
  47. if (GameGlobal.isOfflineVisitor)
  48. {
  49. _ui.m_btnLogout.visible = false;
  50. }
  51. else
  52. {
  53. _ui.m_btnLogout.visible = GameController.CheckLoginCache(false);
  54. if(!_ui.m_btnLogout.visible)
  55. {
  56. ViewManager.Show<LoginInputView>();
  57. }
  58. }
  59. }
  60. protected override void OnHide()
  61. {
  62. if (_sceneObject != null)
  63. {
  64. GameObject.Destroy(_sceneObject);
  65. _sceneObject = null;
  66. }
  67. base.OnHide();
  68. }
  69. private void OnClickBtnNotice()
  70. {
  71. ViewManager.Show<NoticeView>();
  72. }
  73. private void OnClickBtnStart()
  74. {
  75. if (GameGlobal.isOfflineVisitor)
  76. {
  77. LoginProxy.LoginAsVisitor();
  78. }
  79. else
  80. {
  81. if (!GameController.CheckLoginCache(true))
  82. {
  83. ViewManager.Show<LoginInputView>();
  84. }
  85. }
  86. }
  87. private void OnClickBtnLogout()
  88. {
  89. _ui.m_btnLogout.visible = false;
  90. GameController.Logout();
  91. ViewManager.Show<LoginInputView>();
  92. }
  93. }
  94. }