Unity 框架

UIBehaviour.cs 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. [SerializeField]
  47. private List<UseResInfo> useResInfos;
  48. public override void Start()
  49. {
  50. base.Start();
  51. }
  52. private void OnEnable()
  53. {
  54. if (IsEnableAnim)
  55. uIAnim.EnableAnim(rectTransform);
  56. }
  57. private void OnDisable()
  58. {
  59. if (IsEnableAnim)
  60. uIAnim.DisableAnim(rectTransform);
  61. }
  62. public UnityEngine.Object GetRes(string resName)
  63. {
  64. return useResInfos.Find(p => p.resName.Equals(resName))?.resObj;
  65. }
  66. #region Text
  67. /// <summary>
  68. /// 获取TextPro文本在本地化语言配置表的编号
  69. /// </summary>
  70. /// <returns></returns>
  71. public int GetLanguageId()
  72. {
  73. Text text = GetComponent<Text>();
  74. if (text)
  75. return (text as LocalizedLanguageText) == null ? -1 : (text as LocalizedLanguageText).lacalizedLanguageId;
  76. else
  77. return -1;
  78. }
  79. #endregion
  80. }
  81. [Serializable]
  82. public class VariableInfo
  83. {
  84. public string variableName;
  85. public string compentType;
  86. }
  87. [Serializable]
  88. public class UseResInfo
  89. {
  90. public UnityEngine.Object resObj;
  91. public string resName;
  92. }
  93. }