AboutForm.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //------------------------------------------------------------
  2. // Game Framework
  3. // Copyright © 2013-2021 Jiang Yin. All rights reserved.
  4. // Homepage: https://gameframework.cn/
  5. // Feedback: mailto:ellan@gameframework.cn
  6. //------------------------------------------------------------
  7. using UnityEngine;
  8. using UnityEngine.UI;
  9. using UnityGameFramework.Runtime;
  10. namespace MetaClient
  11. {
  12. public class AboutForm : UGuiForm
  13. {
  14. [SerializeField]
  15. private RectTransform m_Transform = null;
  16. [SerializeField]
  17. private float m_ScrollSpeed = 1f;
  18. private float m_InitPosition = 0f;
  19. #if UNITY_2017_3_OR_NEWER
  20. protected override void OnInit(object userData)
  21. #else
  22. protected internal override void OnInit(object userData)
  23. #endif
  24. {
  25. base.OnInit(userData);
  26. CanvasScaler canvasScaler = GetComponentInParent<CanvasScaler>();
  27. if (canvasScaler == null)
  28. {
  29. Log.Warning("Can not find CanvasScaler component.");
  30. return;
  31. }
  32. m_InitPosition = -0.5f * canvasScaler.referenceResolution.x * Screen.height / Screen.width;
  33. }
  34. #if UNITY_2017_3_OR_NEWER
  35. protected override void OnOpen(object userData)
  36. #else
  37. protected internal override void OnOpen(object userData)
  38. #endif
  39. {
  40. base.OnOpen(userData);
  41. m_Transform.SetLocalPositionY(m_InitPosition);
  42. // 换个音乐
  43. GameEntry.Sound.PlayMusic(3);
  44. }
  45. #if UNITY_2017_3_OR_NEWER
  46. protected override void OnClose(bool isShutdown, object userData)
  47. #else
  48. protected internal override void OnClose(bool isShutdown, object userData)
  49. #endif
  50. {
  51. base.OnClose(isShutdown, userData);
  52. // 还原音乐
  53. GameEntry.Sound.PlayMusic(1);
  54. }
  55. #if UNITY_2017_3_OR_NEWER
  56. protected override void OnUpdate(float elapseSeconds, float realElapseSeconds)
  57. #else
  58. protected internal override void OnUpdate(float elapseSeconds, float realElapseSeconds)
  59. #endif
  60. {
  61. base.OnUpdate(elapseSeconds, realElapseSeconds);
  62. m_Transform.AddLocalPositionY(m_ScrollSpeed * elapseSeconds);
  63. if (m_Transform.localPosition.y > m_Transform.sizeDelta.y - m_InitPosition)
  64. {
  65. m_Transform.SetLocalPositionY(m_InitPosition);
  66. }
  67. }
  68. }
  69. }