Unity 框架

UIBehaviour.cs 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Reflection;
  5. using TMPro;
  6. using UnityEngine;
  7. using UnityEngine.Events;
  8. using UnityEngine.EventSystems;
  9. using UnityEngine.UI;
  10. namespace TFramework
  11. {
  12. [Serializable]
  13. public class UIBehaviour : Behaviour
  14. {
  15. private RectTransform _rt;
  16. /// <summary>
  17. /// 启用动画
  18. /// </summary>
  19. [SerializeField]
  20. private bool enableAnim = false;
  21. public string m_uiAnimType;
  22. private UIAnimBase uIAnim;
  23. public RectTransform rectTransform => _rt = _rt ?? GetComponent<RectTransform>();
  24. public bool IsEnableAnim
  25. {
  26. get
  27. {
  28. if (enableAnim)
  29. {
  30. if (uIAnim == null)
  31. uIAnim = GlobalTool.CretaInstanceToCurrentDomain<UIAnimBase>(m_uiAnimType);
  32. }
  33. return enableAnim;
  34. }
  35. set
  36. {
  37. enableAnim = value;
  38. }
  39. }
  40. [SerializeField]
  41. private bool isScriptUse;
  42. [SerializeField]
  43. private List<VariableInfo> variableInfos;
  44. [SerializeField]
  45. private string parnetPanel;
  46. public override void Start()
  47. {
  48. base.Start();
  49. }
  50. private void OnEnable()
  51. {
  52. if (IsEnableAnim)
  53. uIAnim.EnableAnim(rectTransform);
  54. }
  55. private void OnDisable()
  56. {
  57. if (IsEnableAnim)
  58. uIAnim.DisableAnim(rectTransform);
  59. }
  60. #region Text
  61. /// <summary>
  62. /// 获取TextPro文本在本地化语言配置表的编号
  63. /// </summary>
  64. /// <returns></returns>
  65. public int GetLanguageId()
  66. {
  67. Text text = GetComponent<Text>();
  68. if (text)
  69. return (text as LocalizedLanguageText) == null ? -1 : (text as LocalizedLanguageText).lacalizedLanguageId;
  70. else
  71. return -1;
  72. }
  73. #endregion
  74. }
  75. [Serializable]
  76. public class VariableInfo
  77. {
  78. public string variableName;
  79. public string compentType;
  80. }
  81. }