UGuiGroupHelper.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. /// <summary>
  13. /// uGUI 界面组辅助器。
  14. /// </summary>
  15. public class UGuiGroupHelper : UIGroupHelperBase
  16. {
  17. public const int DepthFactor = 10000;
  18. private int m_Depth = 0;
  19. private Canvas m_CachedCanvas = null;
  20. /// <summary>
  21. /// 设置界面组深度。
  22. /// </summary>
  23. /// <param name="depth">界面组深度。</param>
  24. public override void SetDepth(int depth)
  25. {
  26. m_Depth = depth;
  27. m_CachedCanvas.overrideSorting = true;
  28. m_CachedCanvas.sortingOrder = DepthFactor * depth;
  29. }
  30. private void Awake()
  31. {
  32. m_CachedCanvas = gameObject.GetOrAddComponent<Canvas>();
  33. gameObject.GetOrAddComponent<GraphicRaycaster>();
  34. }
  35. private void Start()
  36. {
  37. m_CachedCanvas.overrideSorting = true;
  38. m_CachedCanvas.sortingOrder = DepthFactor * m_Depth;
  39. RectTransform transform = GetComponent<RectTransform>();
  40. transform.anchorMin = Vector2.zero;
  41. transform.anchorMax = Vector2.one;
  42. transform.anchoredPosition = Vector2.zero;
  43. transform.sizeDelta = Vector2.zero;
  44. }
  45. }
  46. }