Unity创建自定义窗口编辑器

        先看看最终效果Unity创建自定义窗口编辑器_第1张图片

要实现自定义窗口编辑器需要了解Unity提供的EditorWindow,EditorGUILayout,GUILayout。

1.先创建一个窗口

     [MenuItem("Custom/CharactInfo Editor")]
    public static void Init()
    {
        charactEditorWindow = EditorWindow.GetWindow(false, "Test", true);
        charactEditorWindow.Show();
        //初始化
        charactEditorWindow.Populate();
    }

2.EditorWindow中给我们提供了一些事件,可以按照自己的需求添加

 OnFocus()  获得焦点时

 OnLostFocus() 失去焦点时

 OnProjectChange()  项目改变时

3.EditorGUILayout或GUILayout 用来显示上图中的控件,以GUILayout.Button(string name, GUIStyle style)为例,关于样式, 用户可以自定义GUIStyle,也可以使用Unity提供的GUIStyle 如

GUILayout.Button("", "TL SelectionBarCloseButton")        显示的结果为

GUILayout.Button("移除", "LargeButton")  显示的结果为 


大家可能会奇怪,GUILayout.Button 方法并没有传入两个字符串的重载方法呀? 其实传入的样式串=GUIStyle 因为在GUIStyle类中存在一个从字符串转换到GUIStyle的隐式转换的方法

 public static implicit operator GUIStyle(string str);
关于隐式转换大家可以看下MSDN上的 implicit关键字。


5.案例下载:  http://pan.baidu.com/s/1sltjV8D

如果本文对您有帮助,请点赞。写的不对的地方请在评论处指出,我会积极学习修改。

样式串的显示结果希望大家在能评论处能帮忙加以补充,方便大家!


更多的样式串请看:

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

  

你可能感兴趣的:(unity编辑器)