UiRoot.cs 1007 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using Godot;
  3. using TBL.GodotSharp.Ui.AutoAdaption;
  4. namespace TBL.GodotSharp.Ui
  5. {
  6. /// <summary>
  7. /// Ui 根节点
  8. /// </summary>
  9. public class UiRoot<TEnumUiLayer> : Control
  10. where TEnumUiLayer : Enum
  11. {
  12. public override void _EnterTree()
  13. {
  14. Name = "UiRoot";
  15. this.SetFullParent();
  16. foreach (var uiLayerName in Enum.GetNames(typeof(TEnumUiLayer)))
  17. {
  18. var layer =
  19. uiLayerName == "Debug"
  20. ? new Control()
  21. : new AutoAdaptionUiRoot();
  22. layer.Name = uiLayerName;
  23. layer.MouseFilter = MouseFilterEnum.Pass;
  24. AddChild(layer);
  25. if (layer is AutoAdaptionUiRoot)
  26. {
  27. layer.SetCenterParent(true);
  28. }
  29. else
  30. {
  31. layer.SetFullParent();
  32. }
  33. }
  34. }
  35. }
  36. }