Unity 自定义Inspector面板 样式

有时候为了开发更加方便,会重写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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值