0%

Unity3D UGUI 源码学习

最近学习一下Unity3D原生UI的源码,基于代码版本Tag: 5.5.0f3

本系列文章列表

分析以下几个主要的类:

详解几个重要的UI组件:

其它:

期间自己编写的UI组件,已托管在GitHub:

概览

文件结构

两个文件夹UnityEngine.UI和UnityEditor.UI:

  • UnityEngine.UI:

    存放UI各系统及组件的实现代码:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    |____UnityEngine.UI
    | |____EventSystem
    | | |____EventData
    | | | |____AxisEventData.cs
    | | | |____BaseEventData.cs
    | | | |____PointerEventData.cs
    | | |____EventHandle.cs
    | | |____EventInterfaces.cs
    | | |____EventSystem.cs
    | | |____EventTrigger.cs
    | | |____EventTriggerType.cs
    | | |____ExecuteEvents.cs
    | | |____InputModules
    | | | |____BaseInput.cs
    | | | |____BaseInputModule.cs
    | | | |____PointerInputModule.cs
    | | | |____StandaloneInputModule.cs
    | | | |____TouchInputModule.cs
    | | |____MoveDirection.cs
    | | |____RaycasterManager.cs
    | | |____Raycasters
    | | | |____BaseRaycaster.cs
    | | | |____Physics2DRaycaster.cs
    | | | |____PhysicsRaycaster.cs
    | | |____RaycastResult.cs
    | | |____UIBehaviour.cs
    | |____UI
    | | |____Animation
    | | | |____CoroutineTween.cs
    | | |____Core
    | | | |____AnimationTriggers.cs
    | | | |____Button.cs
    | | | |____CanvasUpdateRegistry.cs
    | | | |____ColorBlock.cs
    | | | |____Culling
    | | | | |____ClipperRegistry.cs
    | | | | |____Clipping.cs
    | | | | |____IClipRegion.cs
    | | | | |____RectangularVertexClipper.cs
    | | | |____DefaultControls.cs
    | | | |____Dropdown.cs
    | | | |____FontData.cs
    | | | |____FontUpdateTracker.cs
    | | | |____Graphic.cs
    | | | |____GraphicRaycaster.cs
    | | | |____GraphicRebuildTracker.cs
    | | | |____GraphicRegistry.cs
    | | | |____IGraphicEnabledDisabled.cs
    | | | |____Image.cs
    | | | |____IMask.cs
    | | | |____IMaskable.cs
    | | | |____InputField.cs
    | | | |____Layout
    | | | | |____AspectRatioFitter.cs
    | | | | |____CanvasScaler.cs
    | | | | |____ContentSizeFitter.cs
    | | | | |____GridLayoutGroup.cs
    | | | | |____HorizontalLayoutGroup.cs
    | | | | |____HorizontalOrVerticalLayoutGroup.cs
    | | | | |____ILayoutElement.cs
    | | | | |____LayoutElement.cs
    | | | | |____LayoutGroup.cs
    | | | | |____LayoutRebuilder.cs
    | | | | |____LayoutUtility.cs
    | | | | |____VerticalLayoutGroup.cs
    | | | |____Mask.cs
    | | | |____MaskableGraphic.cs
    | | | |____MaskUtilities.cs
    | | | |____MaterialModifiers
    | | | | |____IMaterialModifier.cs
    | | | |____Misc.cs
    | | | |____Navigation.cs
    | | | |____RawImage.cs
    | | | |____RectMask2D.cs
    | | | |____Scrollbar.cs
    | | | |____ScrollRect.cs
    | | | |____Selectable.cs
    | | | |____SetPropertyUtility.cs
    | | | |____Slider.cs
    | | | |____SpecializedCollections
    | | | | |____IndexedSet.cs
    | | | |____SpriteState.cs
    | | | |____StencilMaterial.cs
    | | | |____Text.cs
    | | | |____Toggle.cs
    | | | |____ToggleGroup.cs
    | | | |____Utility
    | | | | |____ListPool.cs
    | | | | |____ObjectPool.cs
    | | | | |____ReflectionMethodsCache.cs
    | | | | |____VertexHelper.cs
    | | | |____VertexModifiers
    | | | | |____BaseMeshEffect.cs
    | | | | |____IMeshModifier.cs
    | | | | |____Outline.cs
    | | | | |____PositionAsUV1.cs
    | | | | |____Shadow.cs
  • UnityEditor.UI

    各UI组件提供编辑器的支持:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    |____UnityEditor.UI
    | |____EventSystem
    | | |____EventSystemEditor.cs
    | | |____EventTriggerEditor.cs
    | |____UI
    | | |____AspectRatioFitterEditor.cs
    | | |____AssemblyInfo.cs
    | | |____ButtonEditor.cs
    | | |____CanvasScalerEditor.cs
    | | |____ContentSizeFitterEditor.cs
    | | |____DropdownEditor.cs
    | | |____GraphicEditor.cs
    | | |____GridLayoutGroupEditor.cs
    | | |____HorizontalOrVerticalLayoutGroupEditor.cs
    | | |____ImageEditor.cs
    | | |____InputFieldEditor.cs
    | | |____InterceptedEventsPreview.cs
    | | |____LayoutElementEditor.cs
    | | |____LayoutPropertiesPreview.cs
    | | |____MaskEditor.cs
    | | |____MenuOptions.cs
    | | |____PrefabLayoutRebuilder.cs
    | | |____PropertyDrawers
    | | | |____AnimationTriggersDrawer.cs
    | | | |____ColorBlockDrawer.cs
    | | | |____DropdownOptionListDrawer.cs
    | | | |____FontDataDrawer.cs
    | | | |____NavigationDrawer.cs
    | | | |____SpriteStateDrawer.cs
    | | |____RawImageEditor.cs
    | | |____RectMask2DEditor.cs
    | | |____ScrollbarEditor.cs
    | | |____ScrollRectEditor.cs
    | | |____SelectableEditor.cs
    | | |____SelfControllerEditor.cs
    | | |____SliderEditor.cs
    | | |____SpriteDrawUtility.cs
    | | |____TextEditor.cs
    | | |____ToggleEditor.cs

主要的类和接口

类的关系图如下:

image

[ 点击这里看大图 ]

REFERENCE

https://bitbucket.org/Unity-Technologies/ui