diff options
author | chai <chaifix@163.com> | 2021-05-06 14:51:05 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-05-06 14:51:05 +0800 |
commit | f342c68d13bddf451ab6cd64fc5b13cf65b65c4f (patch) | |
tree | b3457f6c2c9b42017e84a01aef854a4e67586ddc /Assets/uGUI-2017.1/UnityEngine.UI/UI/Core | |
parent | d0e1834bd1972b4262d3e9b46ed55698a7f92025 (diff) | |
parent | 70ee31ea614d248f67f3d98ada5acb981def7e58 (diff) |
Merge branch 'master' of warmcat.org:/home/git-repo/UGUI_LEARN
# Conflicts:
# Assets/Test/08_Button.meta
# Assets/Test/08_Button/08_Button.unity
# Assets/Test/08_Button/08_Button.unity.meta
Diffstat (limited to 'Assets/uGUI-2017.1/UnityEngine.UI/UI/Core')
5 files changed, 49 insertions, 16 deletions
diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/Button.cs b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/Button.cs index 8641b05..d0c9ae3 100644 --- a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/Button.cs +++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/Button.cs @@ -9,7 +9,10 @@ namespace UnityEngine.UI { // Button that's meant to work with mouse or touch-based devices. [AddComponentMenu("UI/Button", 30)] - public class Button : Selectable, IPointerClickHandler, ISubmitHandler + public class Button + : Selectable + , IPointerClickHandler // 鼠标点击\触摸 + , ISubmitHandler // Input>Submit触发,比如手柄、键盘某个按键按下 { [Serializable] public class ButtonClickedEvent : UnityEvent {} @@ -28,6 +31,7 @@ namespace UnityEngine.UI set { m_OnClick = value; } } + // 调回调 private void Press() { if (!IsActive() || !IsInteractable()) @@ -48,6 +52,8 @@ namespace UnityEngine.UI public virtual void OnSubmit(BaseEventData eventData) { + LogHelper.Log("OnSubmit() " + gameObject.name); + Press(); // if we get set disabled during the press diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/Navigation.cs b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/Navigation.cs index 8dce1d5..98e77f9 100644 --- a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/Navigation.cs +++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/Navigation.cs @@ -14,11 +14,11 @@ namespace UnityEngine.UI [Flags] public enum Mode { - None = 0, // No navigation - Horizontal = 1, // Automatic horizontal navigation - Vertical = 2, // Automatic vertical navigation - Automatic = 3, // Automatic navigation in both dimensions - Explicit = 4, // Explicitly specified only + None = 0, // 0 No navigation + Horizontal = 1, // 1 Automatic horizontal navigation + Vertical = 2, // 10 Automatic vertical navigation + Automatic = 3, // 11 Automatic navigation in both dimensions + Explicit = 4, // Explicitly specified only } // Which method of navigation will be used. diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/Selectable.cs b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/Selectable.cs index c0cda18..9cc6178 100644 --- a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/Selectable.cs +++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/Selectable.cs @@ -13,13 +13,14 @@ namespace UnityEngine.UI public class Selectable : UIBehaviour, - IMoveHandler, - IPointerDownHandler, IPointerUpHandler, - IPointerEnterHandler, IPointerExitHandler, - ISelectHandler, IDeselectHandler + IMoveHandler, // Input>Horizontal\Vertical移动时收到这个消息 + IPointerDownHandler, IPointerUpHandler, // 点击click + IPointerEnterHandler, IPointerExitHandler, // 悬停hover + ISelectHandler, IDeselectHandler // navigation获得焦点时收到这个消息 { // Selection state + // 当前场景中的Selectable组件 // List of all the selectable objects currently active in the scene private static List<Selectable> s_List = new List<Selectable>(); public static List<Selectable> allSelectables { get { return s_List; } } @@ -349,7 +350,7 @@ namespace UnityEngine.UI Vector3 pos = transform.TransformPoint(GetPointOnRectEdge(transform as RectTransform, localDir)); float maxScore = Mathf.NegativeInfinity; Selectable bestPick = null; - for (int i = 0; i < s_List.Count; ++i) + for (int i = 0; i < s_List.Count; ++i) // 遍历当前场景中的所有selectable组件 { Selectable sel = s_List[i]; @@ -410,7 +411,7 @@ namespace UnityEngine.UI void Navigate(AxisEventData eventData, Selectable sel) { if (sel != null && sel.IsActive()) - eventData.selectedObject = sel.gameObject; + eventData.selectedObject = sel.gameObject; // 会发送一个selectHandler事件 } // Find the selectable object to the left of this one. @@ -469,12 +470,15 @@ namespace UnityEngine.UI return null; } + // input>horizontal\vertical产生这个事件, public virtual void OnMove(AxisEventData eventData) { + LogHelper.Log("OnMove() " + gameObject.name ); + switch (eventData.moveDir) { case MoveDirection.Right: - Navigate(eventData, FindSelectableOnRight()); + Navigate(eventData, FindSelectableOnRight()); // 会向下一个selectableObj发送一个OnSelect消息 break; case MoveDirection.Up: @@ -496,6 +500,7 @@ namespace UnityEngine.UI if (m_TargetGraphic == null) return; + // 起一个协程做tween动画 m_TargetGraphic.CrossFadeColor(targetColor, instant ? 0f : m_Colors.fadeDuration, true, true); } @@ -512,6 +517,8 @@ namespace UnityEngine.UI if (transition != Transition.Animation || animator == null || !animator.isActiveAndEnabled || !animator.hasBoundPlayables || string.IsNullOrEmpty(triggername)) return; + LogHelper.Log("trigger animation"); + animator.ResetTrigger(m_AnimationTriggers.normalTrigger); animator.ResetTrigger(m_AnimationTriggers.pressedTrigger); animator.ResetTrigger(m_AnimationTriggers.highlightedTrigger); @@ -578,6 +585,7 @@ namespace UnityEngine.UI m_CurrentSelectionState = SelectionState.Normal; } + // 更新状态播放动画 // Change the button to the correct state private void EvaluateAndTransitionToSelectionState(BaseEventData eventData) { @@ -598,12 +606,14 @@ namespace UnityEngine.UI public virtual void OnPointerDown(PointerEventData eventData) { + LogHelper.Log("OnPointerDown() "+ gameObject.name); + if (eventData.button != PointerEventData.InputButton.Left) return; // Selection tracking if (IsInteractable() && navigation.mode != Navigation.Mode.None && EventSystem.current != null) - EventSystem.current.SetSelectedGameObject(gameObject, eventData); + EventSystem.current.SetSelectedGameObject(gameObject, eventData); // 选中这个UI组件 isPointerDown = true; EvaluateAndTransitionToSelectionState(eventData); @@ -611,6 +621,8 @@ namespace UnityEngine.UI public virtual void OnPointerUp(PointerEventData eventData) { + LogHelper.Log("OnPointerUp() " + gameObject.name); + if (eventData.button != PointerEventData.InputButton.Left) return; @@ -620,24 +632,31 @@ namespace UnityEngine.UI public virtual void OnPointerEnter(PointerEventData eventData) { + LogHelper.Log("OnPointerEnter() " + gameObject.name); + isPointerInside = true; EvaluateAndTransitionToSelectionState(eventData); } public virtual void OnPointerExit(PointerEventData eventData) { + LogHelper.Log("OnPointerExit() " + gameObject.name); + isPointerInside = false; EvaluateAndTransitionToSelectionState(eventData); } + // 被选中 public virtual void OnSelect(BaseEventData eventData) { + LogHelper.Log("OnSelect() " + gameObject.name); hasSelection = true; EvaluateAndTransitionToSelectionState(eventData); } public virtual void OnDeselect(BaseEventData eventData) { + LogHelper.Log("OnDeselect() " + gameObject.name); hasSelection = false; EvaluateAndTransitionToSelectionState(eventData); } diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/Slider.cs b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/Slider.cs index ce8f4bb..4e80fb3 100644 --- a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/Slider.cs +++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/Slider.cs @@ -6,7 +6,11 @@ namespace UnityEngine.UI { [AddComponentMenu("UI/Slider", 33)] [RequireComponent(typeof(RectTransform))] - public class Slider : Selectable, IDragHandler, IInitializePotentialDragHandler, ICanvasElement + public class Slider + : Selectable + , IDragHandler + , IInitializePotentialDragHandler + , ICanvasElement // 编辑器下才会用到 { public enum Direction { diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/Toggle.cs b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/Toggle.cs index 5dc9275..8dc4c82 100644 --- a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/Toggle.cs +++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/UIControls/Toggle.cs @@ -10,7 +10,11 @@ namespace UnityEngine.UI /// </summary> [AddComponentMenu("UI/Toggle", 31)] [RequireComponent(typeof(RectTransform))] - public class Toggle : Selectable, IPointerClickHandler, ISubmitHandler, ICanvasElement + public class Toggle + : Selectable + , IPointerClickHandler + , ISubmitHandler + , ICanvasElement // 缂栬緫鍣ㄤ笅鐢ㄥ埌 { public enum ToggleTransition { |