关闭

Unity 自定义Inspector面板 样式

标签: Unity
254人阅读 评论(0) 收藏 举报
分类:

有时候为了开发更加方便,会重写Inspector面板或者Editor窗口。一般情况下,Unity已经将public修饰符的字段自动序列化,使得该字段能够在Inspector面板中能够被修改。而且也添加了许多unity的特性,例如[Range(0, 100)],[HideInInspector]等等,需要了解的同学们可以百度一下。

这次我们说的是Inspector面板。

马上看看效果及代码。

using UnityEngine;
using System.Collections;
using UnityEditor;


[CustomEditor(typeof(NewBehaviourScript))]
public class InspectorTest : Editor
{

    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();
        GUILayout.Label("Expansion", "GUIEditor.BreadcrumbLeft");

        GUILayout.Label("Expansion", "WhiteBoldLabel");
        GUI.color = Color.green;
        GUILayout.Label("Expansion", "NotificationText");
        GUILayout.Label("Expansion", "Wizard Error");

        EditorGUILayout.Space();
    }

}

效果如下图:




然后我们来解释一下代码:

[CustomEditor(typeof(NewBehaviourScript))] 即重新自定义NewBehaviourScript类的inspector面板

重新绘制inspector面板需要重写OnInspectorGUI方法,一旦重写了,本来已经序列化的字段就不见了,怎么办呢?

实现DrawDefaultInspector方法会将Unity绘制在面板上的字段保存下来

GUI.color = Color.green; 改变绘制的组件的颜色


好了,其他绘制的组件和一些方法可以百度。这次只不过是一个小尝试。哈哈


下面提供一些绘制样式。






AboutWIndowLicenseLabel
AC LeftArrow
AC RightArrow
AnimationCurveEditorBackground
AnimationEventBackground
AnimationEventTooltip
AnimationEventTooltipArrow
AnimationKeyframeBackground
AnimationRowEven
AnimationRowOdd
AnimationSelectionTextField
AnimationTimelineTick
AnimPropDropdown
AppToolbar
AS TextArea
BoldLabel
BoldToggle
ButtonLeft
ButtonMid
ButtonRight
CN Box
CN CountBadge
CN EntryBackEven
CN EntryBackOdd
CN EntryError
CN EntryInfo
CN EntryWarn
CN Message
CN StatusError
CN StatusInfo
CN StatusWarn
ColorField
ColorPicker2DThumb
ColorPickerBackground
ColorPickerBox
ColorPickerHorizThumb
ColorPickerVertThumb
Command
CommandLeft
CommandMid
CommandRight
ControlLabel
CurveEditorLabelTickmarks
debug_layout_box
dockarea
dockareaOverlay
dockareaStandalone
dragtab
dragtabbright
dragtabdropwindow
DropDown
DropDownButton
ErrorLabel
ExposablePopupItem
ExposablePopupMenu
EyeDropperHorizontalLine
EyeDropperPickedPixel
EyeDropperVerticalLine
flow background
flow navbar back
flow navbar button
flow navbar separator
flow node 0
flow node 0 on
flow node 1
flow node 1 on
flow node 2
flow node 2 on
flow node 3
flow node 3 on
flow node 4
flow node 4 on
flow node 5
flow node 5 on
flow node 6
flow node 6 on
flow node hex 0
flow node hex 0 on
flow node hex 1
flow node hex 1 on
flow node hex 2
flow node hex 2 on
flow node hex 3
flow node hex 3 on
flow node hex 4
flow node hex 4 on
flow node hex 5
flow node hex 5 on
flow node hex 6
flow node hex 6 on
flow node titlebar
flow overlay area left
flow overlay area right
flow overlay box
flow overlay foldout
flow overlay header lower left
flow overlay header lower right
flow overlay header upper left
flow overlay header upper right
flow shader in 0
flow shader in 1
flow shader in 2
flow shader in 3
flow shader in 4
flow shader in 5
flow shader node 0
flow shader node 0 on
flow shader out 0
flow shader out 1
flow shader out 2
flow shader out 3
flow shader out 4
flow shader out 5
flow target in
flow triggerPin in
flow triggerPin out
flow var 0
flow var 0 on
flow var 1
flow var 1 on
flow var 2
flow var 2 on
flow var 3
flow var 3 on
flow var 4
flow var 4 on
flow var 5
flow var 5 on
flow var 6
flow var 6 on
flow varPin in
flow varPin out
flow varPin tooltip
Foldout
FoldOutPreDrop
GameViewBackground
Grad Down Swatch
Grad Down Swatch Overlay
Grad Up Swatch
Grad Up Swatch Overlay
grey_border
GridList
GridListText
GridToggle
GroupBox
GUIEditor.BreadcrumbLeft
GUIEditor.BreadcrumbMid
GV Gizmo DropDown
HeaderLabel
HelpBox
Hi Label
HorizontalMinMaxScrollbarThumb
hostview
IN BigTitle
IN BigTitle Inner
IN ColorField
IN DropDown
IN Foldout
IN FoldoutStatic
IN Label
IN LockButton
IN ObjectField
IN Popup
IN SelectedLine
IN TextField
IN ThumbnailSelection
IN ThumbnailShadow
IN Title
IN TitleText
IN Toggle
InnerShadowBg
InvisibleButton
LargeButton
LargeButtonLeft
LargeButtonMid
LargeButtonRight
LargeDropDown
LargeLabel
LargePopup
LargeTextField
LightmapEditorSelectedHighlight
ListToggle
LockedHeaderBackground
LockedHeaderButton
LockedHeaderLabel
LODBlackBox
LODCameraLine
LODLevelNotifyText
LODRendererAddButton
LODRendererButton
LODRendererRemove
LODRenderersText
LODSceneText
LODSliderBG
LODSliderRange
LODSliderRangeSelected
LODSliderText
LODSliderTextSelected
MeBlendBackground
MeBlendPosition
MeBlendTriangleLeft
MeBlendTriangleRight
MeLivePlayBackground
MeLivePlayBar
MeTimeLabel
MeTransBGOver
MeTransitionBack
MeTransitionBlock
MeTransitionHandleLeft
MeTransitionHandleLeftPrev
MeTransitionHandleRight
MeTransitionHead
MeTransitionSelect
MeTransitionSelectHead
MeTransOff2On
MeTransOffLeft
MeTransOffRight
MeTransOn2Off
MeTransOnLeft
MeTransOnRight
MeTransPlayhead
MiniBoldLabel
minibutton
minibuttonleft
minibuttonmid
minibuttonright
MiniLabel
MiniLabelRight
MiniMinMaxSliderHorizontal
MiniMinMaxSliderVertical
MiniPopup
MiniPullDown
MiniPullDownLeft
MiniTextField
MiniToolbarButton
MiniToolbarButtonLeft
MiniToolbarPopup
MinMaxHorizontalSliderThumb
NotificationBackground
NotificationText
ObjectField
ObjectFieldThumb
ObjectFieldThumbOverlay
ObjectFieldThumbOverlay2
ObjectPickerBackground
ObjectPickerGroupHeader
ObjectPickerLargeStatus
ObjectPickerPreviewBackground
ObjectPickerResultsEven
ObjectPickerResultsGrid
ObjectPickerResultsGridLabel
ObjectPickerResultsOdd
ObjectPickerSmallStatus
ObjectPickerTab
ObjectPickerToolbar
OL box
OL box NoExpand
OL Elem
OL EntryBackEven
OL EntryBackOdd
OL header
OL Label
OL Minus
OL Plus
OL TextField
OL Title
OL Title TextRight
OL Titleleft
OL Titlemid
OL Titleright
OL Toggle
OL ToggleWhite
PaneOptions
PlayerSettingsLevel
PlayerSettingsPlatform
Popup
PopupBackground
PopupCurveDropdown
PopupCurveEditorBackground
PopupCurveEditorSwatch
PopupCurveSwatchBackground
PR DigDownArrow
PR Insertion
PR Label
PR Ping
PR TextField
PreBackground
PreButton
PreferencesKeysElement
PreferencesSection
PreferencesSectionBox
PreHorizontalScrollbar
PreHorizontalScrollbarThumb
PreLabel
PreOverlayLabel
PreSlider
PreSliderThumb
PreToolbar
PreToolbar2
PreVerticalScrollbar
PreVerticalScrollbarThumb
ProfilerBadge
ProfilerLeftPane
ProfilerLeftPaneOverlay
ProfilerPaneLeftBackground
ProfilerPaneSubLabel
ProfilerRightPane
ProfilerScrollviewBackground
ProfilerSelectedLabel
ProgressBarBack
ProgressBarBar
ProgressBarText
ProjectBrowserBottomBarBg
ProjectBrowserGridLabel
ProjectBrowserHeaderBgMiddle
ProjectBrowserHeaderBgTop
ProjectBrowserIconAreaBg
ProjectBrowserIconDropShadow
ProjectBrowserPreviewBg
ProjectBrowserSubAssetBg
ProjectBrowserSubAssetBgCloseEnded
ProjectBrowserSubAssetBgDivider
ProjectBrowserSubAssetBgMiddle
ProjectBrowserSubAssetBgOpenEnded
ProjectBrowserSubAssetExpandBtn
ProjectBrowserTopBarBg
QualitySettingsDefault
Radio
RightLabel
RL Background
RL DragHandle
RL Element
RL Footer
RL FooterButton
RL Header
SC ViewAxisLabel
SC ViewLabel
SceneViewOverlayTransparentBackground
ScriptText
SearchCancelButton
SearchCancelButtonEmpty
SearchModeFilter
SearchTextField
SelectionRect
ServerChangeCount
ServerUpdateChangeset
ServerUpdateChangesetOn
ServerUpdateInfo
ServerUpdateLog
ShurikenCheckMark
ShurikenEffectBg
ShurikenEmitterTitle
ShurikenLabel
ShurikenLine
ShurikenMinus
ShurikenModuleBg
ShurikenModuleTitle
ShurikenObjectField
ShurikenPlus
ShurikenPopUp
ShurikenToggle
ShurikenValue
SimplePopup
SliderMixed
StaticDropdown
sv_iconselector_back
sv_iconselector_button
sv_iconselector_labelselection
sv_iconselector_selection
sv_iconselector_sep
sv_label_0
sv_label_1
sv_label_2
sv_label_3
sv_label_4
sv_label_5
sv_label_6
sv_label_7
TabWindowBackground
Tag MenuItem
Tag TextField
Tag TextField Button
Tag TextField Empty
TE NodeBackground
TE NodeBox
TE NodeBoxSelected
TE NodeLabelBot
TE NodeLabelTop
TE PinLabel
TE Toolbar
TE toolbarbutton
TE ToolbarDropDown
TimeScrubber
TimeScrubberButton
TL BaseStateLogicBarOverlay
TL EndPoint
TL InPoint
TL ItemTitle
TL LeftColumn
TL LeftItem
TL LogicBar 0
TL LogicBar 1
TL LogicBar parentgrey
TL LoopSection
TL OutPoint
TL Playhead
TL Range Overlay
TL RightLine
TL Selection H1
TL Selection H2
TL SelectionBarCloseButton
TL SelectionBarPreview
TL SelectionBarText
TL SelectionButton
TL SelectionButton PreDropGlow
TL SelectionButtonName
TL SelectionButtonNew
TL tab left
TL tab mid
TL tab plus left
TL tab plus right
TL tab right
ToggleMixed
Toolbar
toolbarbutton
ToolbarDropDown
ToolbarPopup
ToolbarSeachCancelButton
ToolbarSeachCancelButtonEmpty
ToolbarSeachTextField
ToolbarSeachTextFieldPopup
ToolbarSearchField
ToolbarTextField
Tooltip
U2D.createRect
U2D.dragDot
U2D.dragDotDimmed
VCS_StickyNote
VCS_StickyNoteArrow
VCS_StickyNoteLabel
VCS_StickyNoteP4
VerticalMinMaxScrollbarThumb
VisibilityToggle
WhiteBoldLabel
WhiteLabel
WhiteLargeLabel
WhiteMiniLabel
WinBtnCloseActiveMac
WinBtnCloseMac
WinBtnCloseWin
WinBtnInactiveMac
WinBtnMaxActiveMac
WinBtnMaxMac
WinBtnMaxWin
WinBtnMinActiveMac
WinBtnMinMac
WinBtnMinWin
WindowBackground
WindowBottomResize
WindowResizeMac
Wizard Box
Wizard Error
WordWrapLabel
WordWrappedLabel
WordWrappedMiniLabel
WrappedLabel







0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:5976次
    • 积分:52
    • 等级:
    • 排名:千里之外
    • 原创:6篇
    • 转载:11篇
    • 译文:0篇
    • 评论:2条
    文章分类
    最新评论