UEScrollPan.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Xml;
  5. using CommonLang;
  6. using CommonUnity3D.UGUI;
  7. using UnityEngine.UI;
  8. using UnityEngine;
  9. using CommonLang.Xml;
  10. using UnityEngine.EventSystems;
  11. using CommonUI.Data;
  12. namespace CommonUnity3D.UGUIEditor.UI
  13. {
  14. public class UEScrollPan : UIComponent
  15. {
  16. protected ScrollablePanel mMaskPanel;
  17. protected float mBorderSize;
  18. public UEScrollPan()
  19. {
  20. }
  21. protected virtual ScrollablePanel CreateScrollablePanel(string name)
  22. {
  23. return new ScrollablePanel(name);
  24. }
  25. public DisplayNode ContainerPanel { get { return mMaskPanel.Container; } }
  26. public ScrollablePanel Scrollable { get { return mMaskPanel; } }
  27. public Rect ScrollRect2D { get { return mMaskPanel.ScrollRect2D; } }
  28. public bool ShowSlider
  29. {
  30. get
  31. {
  32. if (mMaskPanel is ScrollablePanel)
  33. {
  34. return (mMaskPanel as ScrollablePanel).ShowSlider;
  35. }
  36. return false;
  37. }
  38. set
  39. {
  40. if (mMaskPanel is ScrollablePanel)
  41. {
  42. (mMaskPanel as ScrollablePanel).ShowSlider = value;
  43. }
  44. }
  45. }
  46. public Rect ViewRect2D
  47. {
  48. get
  49. {
  50. Rect rect = this.Bounds2D;
  51. rect.x = mBorderSize;
  52. rect.y = mBorderSize;
  53. rect.width -= mBorderSize * 2;
  54. rect.height -= mBorderSize * 2;
  55. return rect;
  56. }
  57. }
  58. public void SetScrollBar(UILayout layout_scroll_h, UILayout layout_scroll_v)
  59. {
  60. UIComponent scroll_v = null;
  61. UIComponent scroll_h = null;
  62. if (layout_scroll_v != null)
  63. {
  64. scroll_v = new UIComponent("scroll_v");
  65. scroll_v.Layout = layout_scroll_v;
  66. scroll_v.Size2D = layout_scroll_v.PreferredSize;
  67. }
  68. if (layout_scroll_h != null)
  69. {
  70. scroll_h = new UIComponent("scroll_h");
  71. scroll_h.Layout = layout_scroll_h;
  72. scroll_h.Size2D = layout_scroll_h.PreferredSize;
  73. }
  74. if (mMaskPanel is ScrollablePanel)
  75. {
  76. (mMaskPanel as ScrollablePanel).SetScrollBarPair(scroll_h, scroll_v);
  77. }
  78. }
  79. protected override void OnUpdate()
  80. {
  81. base.OnUpdate();
  82. Rect view_rect = this.ViewRect2D;
  83. this.mMaskPanel.Bounds2D = view_rect;
  84. }
  85. protected override void AddEditorComopnent(UIComponent c)
  86. {
  87. mMaskPanel.Container.AddChild(c);
  88. }
  89. protected override void DecodeBegin(UIEditor.Decoder editor, UIComponentMeta e)
  90. {
  91. this.mMaskPanel = CreateScrollablePanel("scrollable");
  92. if (this.mMaskPanel != null)
  93. {
  94. this.AddChild(mMaskPanel);
  95. }
  96. base.DecodeBegin(editor, e);
  97. this.Decode_ScrollPan(editor, e as UEScrollPanMeta);
  98. }
  99. private void Decode_ScrollPan(UIEditor.Decoder editor, UEScrollPanMeta e)
  100. {
  101. this.mMaskPanel.Scroll.movementType = e.EnableElasticity ? ScrollRect.MovementType.Elastic : ScrollRect.MovementType.Clamped;
  102. this.mMaskPanel.Scroll.horizontal = e.EnableScrollH;
  103. this.mMaskPanel.Scroll.vertical = e.EnableScrollV;
  104. this.mBorderSize = e.BorderSize;
  105. this.ShowSlider = e.ShowSlider;
  106. if (mMaskPanel is ScrollablePanel)
  107. {
  108. (mMaskPanel as ScrollablePanel).ScrollFadeTimeMaxMS = e.scroll_fade_time_max * 30;
  109. }
  110. this.SetScrollBar(
  111. editor.CreateLayout(e.layout_scroll_h),
  112. editor.CreateLayout(e.layout_scroll_v));
  113. }
  114. protected override void DecodeEnd(UIEditor.Decoder editor, UIComponentMeta e)
  115. {
  116. base.DecodeEnd(editor, e);
  117. this.EnableChildren = true;
  118. Rect view_rect = this.ViewRect2D;
  119. this.mMaskPanel.Bounds2D = view_rect;
  120. }
  121. }
  122. }