summaryrefslogtreecommitdiff
path: root/Assets/uGUI-2017.1/UnityEngine.UI
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/uGUI-2017.1/UnityEngine.UI')
-rw-r--r--Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/StandaloneInputModule.cs1
-rw-r--r--Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/Dropdown.cs20
-rw-r--r--Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/InputField.cs11
-rw-r--r--Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/ScrollRect.cs50
-rw-r--r--Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/Scrollbar.cs7
5 files changed, 59 insertions, 30 deletions
diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/StandaloneInputModule.cs b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/StandaloneInputModule.cs
index 592ea4d..198d5b0 100644
--- a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/StandaloneInputModule.cs
+++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/StandaloneInputModule.cs
@@ -322,6 +322,7 @@ namespace UnityEngine.EventSystems
// Save the drag handler as well
pointerEvent.pointerDrag = ExecuteEvents.GetEventHandler<IDragHandler>(currentOverGo);
+ // 只有包含IDragHandler接口时才会触发IInitializePotentialDragHandler接口
if (pointerEvent.pointerDrag != null)
ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.initializePotentialDrag);
}
diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/Dropdown.cs b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/Dropdown.cs
index 86bed37..9ad2a61 100644
--- a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/Dropdown.cs
+++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/Dropdown.cs
@@ -145,6 +145,7 @@ namespace UnityEngine.UI
private static OptionData s_NoOptionData = new OptionData();
+ // 当前选中
// Current value.
public int value
{
@@ -162,6 +163,8 @@ namespace UnityEngine.UI
// Notify all listeners
UISystemProfilerApi.AddMarker("Dropdown.value", this);
+
+ //
m_OnValueChanged.Invoke(m_Value);
}
}
@@ -176,9 +179,13 @@ namespace UnityEngine.UI
return;
#endif
+ // 初始化渐变模块
m_AlphaTweenRunner = new TweenRunner<FloatTween>();
m_AlphaTweenRunner.Init(this);
+
+ // 隐藏item模板
+
if (m_CaptionImage)
m_CaptionImage.enabled = (m_CaptionImage.sprite != null);
@@ -427,17 +434,20 @@ namespace UnityEngine.UI
}
// Reposition all items now that all of them have been added
+ // 计算内容区域的高度
Vector2 sizeDelta = contentRectTransform.sizeDelta;
sizeDelta.y = itemSize.y * m_Items.Count + offsetMin.y - offsetMax.y;
contentRectTransform.sizeDelta = sizeDelta;
+ //计算是否有额外空区域(当内容区域小于列表本身的区域时调整列表大小)
float extraSpace = dropdownRectTransform.rect.height - contentRectTransform.rect.height;
if (extraSpace > 0)
- dropdownRectTransform.sizeDelta = new Vector2(dropdownRectTransform.sizeDelta.x, dropdownRectTransform.sizeDelta.y - extraSpace);
-
- // Invert anchoring and position if dropdown is partially or fully outside of canvas rect.
- // Typically this will have the effect of placing the dropdown above the button instead of below,
- // but it works as inversion regardless of initial setup.
+ dropdownRectTransform.sizeDelta = new Vector2(dropdownRectTransform.sizeDelta.x, dropdownRectTransform.sizeDelta.y - extraSpace);
+
+ // Invert anchoring and position if dropdown is partially or fully outside of canvas rect.
+ // Typically this will have the effect of placing the dropdown above the button instead of below,
+ // but it works as inversion regardless of initial setup.
+ // 当列表处于canvas外部时,将其按坐标轴进行翻转
Vector3[] corners = new Vector3[4];
dropdownRectTransform.GetWorldCorners(corners);
diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/InputField.cs b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/InputField.cs
index 1f3267a..ef6afa4 100644
--- a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/InputField.cs
+++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/InputField.cs
@@ -121,7 +121,7 @@ namespace UnityEngine.UI
[FormerlySerializedAs("hideMobileInput")]
[SerializeField]
- private bool m_HideMobileInput = false;
+ private bool m_HideMobileInput = false; // 手机端不绘制竖线caret
/// <summary>
/// What kind of validation to use with the input field's data.
@@ -1866,7 +1866,7 @@ namespace UnityEngine.UI
switch (update)
{
case CanvasUpdate.LatePreRender:
- UpdateGeometry();
+ UpdateGeometry();// 绘制竖线Caret
break;
}
}
@@ -1875,10 +1875,12 @@ namespace UnityEngine.UI
{}
public virtual void GraphicUpdateComplete()
- {}
-
+ {}
+
+ //c 绘制竖线Caret
private void UpdateGeometry()
{
+
#if UNITY_EDITOR
if (!Application.isPlaying)
return;
@@ -1889,6 +1891,7 @@ namespace UnityEngine.UI
if (m_CachedInputRenderer == null && m_TextComponent != null)
{
+ // InputField Input Caret找到对应的caret renderer
GameObject go = new GameObject(transform.name + " Input Caret", typeof(RectTransform), typeof(CanvasRenderer));
go.hideFlags = HideFlags.DontSave;
go.transform.SetParent(m_TextComponent.transform.parent);
diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/ScrollRect.cs b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/ScrollRect.cs
index a44bc5c..b2230d6 100644
--- a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/ScrollRect.cs
+++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/ScrollRect.cs
@@ -1,3 +1,4 @@
+#define UGUI_DEBUG
using System;
using UnityEngine.Events;
using UnityEngine.EventSystems;
@@ -11,14 +12,14 @@ namespace UnityEngine.UI
[RequireComponent(typeof(RectTransform))]
public class ScrollRect
: UIBehaviour
- , IInitializePotentialDragHandler
- , IBeginDragHandler
- , IEndDragHandler
- , IDragHandler
- , IScrollHandler
- , ICanvasElement
- , ILayoutElement
- , ILayoutGroup
+ , IInitializePotentialDragHandler // 可能的拖拽之前
+ , IBeginDragHandler // 拖拽之前
+ , IEndDragHandler // 拖拽之后
+ , IDragHandler // 拖拽中
+ , IScrollHandler // 鼠标滚轮
+ , ICanvasElement // 处理重新布局
+ , ILayoutElement // 布局元素
+ , ILayoutGroup // 容器
{
public enum MovementType
{
@@ -147,10 +148,15 @@ namespace UnityEngine.UI
m_ViewRect = (RectTransform)transform;
return m_ViewRect;
}
- }
-
+ }
+
+#if UGUI_DEBUG
+ public Bounds m_ContentBounds;
+ public Bounds m_ViewBounds;
+#else
protected Bounds m_ContentBounds;
private Bounds m_ViewBounds;
+#endif
private Vector2 m_Velocity;
public Vector2 velocity { get { return m_Velocity; } set { m_Velocity = value; } }
@@ -227,16 +233,19 @@ namespace UnityEngine.UI
m_HSliderHeight = (m_HorizontalScrollbarRect == null ? 0 : m_HorizontalScrollbarRect.rect.height);
m_VSliderWidth = (m_VerticalScrollbarRect == null ? 0 : m_VerticalScrollbarRect.rect.width);
}
-
+
+ // 初始化
protected override void OnEnable()
{
base.OnEnable();
+ // 注册滚动条监听函数
if (m_HorizontalScrollbar)
m_HorizontalScrollbar.onValueChanged.AddListener(SetHorizontalNormalizedPosition);
if (m_VerticalScrollbar)
m_VerticalScrollbar.onValueChanged.AddListener(SetVerticalNormalizedPosition);
+ // 注册到布局重建队列
CanvasUpdateRegistry.RegisterCanvasElementForLayoutRebuild(this);
}
@@ -786,8 +795,10 @@ namespace UnityEngine.UI
{
if (m_Content == null)
return new Bounds();
- m_Content.GetWorldCorners(m_Corners);
- var viewWorldToLocalMatrix = viewRect.worldToLocalMatrix;
+ // 获得世界空间下content RectTransform矩形四个角的坐标(左下角开始的顺时针)
+ m_Content.GetWorldCorners(m_Corners);
+ // viewport的w2l矩阵,用来把content变到viewport坐标系下
+ var viewWorldToLocalMatrix = viewRect.worldToLocalMatrix;
return InternalGetBounds(m_Corners, ref viewWorldToLocalMatrix);
}
@@ -796,15 +807,16 @@ namespace UnityEngine.UI
var vMin = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
var vMax = new Vector3(float.MinValue, float.MinValue, float.MinValue);
+ // 找边界
for (int j = 0; j < 4; j++)
{
- Vector3 v = viewWorldToLocalMatrix.MultiplyPoint3x4(corners[j]);
- vMin = Vector3.Min(v, vMin);
- vMax = Vector3.Max(v, vMax);
+ Vector3 v = viewWorldToLocalMatrix.MultiplyPoint3x4(corners[j]); // viewport坐标系下的坐标
+ vMin = Vector3.Min(v, vMin); // 分别选每一个分量的最小值
+ vMax = Vector3.Max(v, vMax); // 分别选每一个分量的最大值
}
var bounds = new Bounds(vMin, Vector3.zero);
- bounds.Encapsulate(vMax);
+ bounds.Encapsulate(vMax); // 这个方法会以vMin和vMax为边界,center=(vMin + vMax) / 2, size=vMax - vMin
return bounds;
}
@@ -862,12 +874,12 @@ namespace UnityEngine.UI
LayoutRebuilder.MarkLayoutForRebuild(rectTransform);
}
- #if UNITY_EDITOR
+#if UNITY_EDITOR
protected override void OnValidate()
{
SetDirtyCaching();
}
- #endif
+#endif
}
}
diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/Scrollbar.cs b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/Scrollbar.cs
index c280305..f28e042 100644
--- a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/Scrollbar.cs
+++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/Scrollbar.cs
@@ -310,11 +310,14 @@ namespace UnityEngine.UI
{
while (isPointerDownAndNotDragging)
{
+ // 如果点击的位置没在handle里,但是在进度条其他地方,表明要跳到对应的位置(准确来说是对应的size*n位置)
if (!RectTransformUtility.RectangleContainsScreenPoint(m_HandleRect, eventData.position, eventData.enterEventCamera))
- {
+ {
Vector2 localMousePos;
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(m_HandleRect, eventData.position, eventData.pressEventCamera, out localMousePos))
- {
+ {
+ Debug.Log("ClickRepeat");
+
var axisCoordinate = axis == 0 ? localMousePos.x : localMousePos.y;
if (axisCoordinate < 0)
value -= size;