Unity Editor Inspector界面编辑

一、继承MonoBehaviour
1、[Header(" ")] 标题

//Add a header above some fields in the Inspector.
[Header("Tittle")]
public string Str;

2、[Tooltip(" ")] 如果鼠标光标是在字段上,显示的说明文本

//Specify a tooltip for a field.
[Tooltip("This is a Tooltip")]
public string Str;

3、[Range(0, 5)] 将int、float变量限制在特定范围内,滑动条

//Attribute used to make a float or int variable in a script be restricted to a
//specific range.
[Range(0, 5)]
public int Int;
[Range(0, 5)]
public float Float;

4、[Multiline] 字符串多行文本显示

//Attribute used to make a string value be shown in a multiline textarea.
[Multiline]
public string Str;

5、[TextArea(2, 5)] 字符串多行文本显示,可以设置可现实的最大值和最小值的行数

//Attribute to make a string be edited with a height-flexible and scrollable 
//text area.
[TextArea(2, 5)]
public string Str;

6、[ContextMenu(" ")] 右键脚本添加菜单事件

//Adds the function to the context menu of the component.
[ContextMenu("QwQ")]
void HelloWorld()
    {
        Debug.Log("我发出了QwQ");
    }

7、[ContextMenuItem(" ", " ")] 右键变量添加菜单事件

//Use this attribute to add a context menu to a field that calls a named method.
[ContextMenuItem("ResetValue", "resetValue")]
public int A = 100;

void resetValue()
{
    A = 50;
}

8、[HideInInspector] 在Inspector面板中隐藏

//Makes a variable not show up in the inspector but be serialized.
[HideInInspector]
public string Str;

9、[Serializable] 可序列化

[Serializable]
public class SerializableTest
{
    public int A = 5;

    public Color c = Color.white;
}
  
public SerializableTest Test;

10、[Space(50)] 两个变量之间添加间距

//Use this DecoratorDrawer to add some spacing in the Inspector.
public string Str0;
[Space(50)]
public string Str1;

11、Class序列化

[Serializable]
public class TestClass
{
    public string Str = "这是一句话...";
    public bool IsOn;
}

public class Test : MonoBehaviour
{
    public TestClass testClass;
}
12、[MenuItem("A/B")] 在菜单栏添加事件

(1)在顶部菜单栏添加事件

public class Test : MonoBehaviour
{
    [MenuItem("QAQ/QvQ")]
    public static void QvQ()
    {
        print("O-O");
    }
}

 

(2)在Project空白部分右键菜单栏添加事件

public class Test
{
    const string menuA = "Assets/QAQ/QvQ";
    const string menuB = "Assets/QAQ/Q_Q";
    const string menuC = "Assets/QAQ/QuQ";

    static bool isOn;

    [MenuItem(menuA, priority = 0, validate = false)]
    private static bool OvO()
    {
        bool value = !EditorPrefs.GetBool("HAHA", false);
        EditorPrefs.SetBool("HAHA", value);
        Menu.SetChecked(menuA, value);
        isOn = value;
        Debug.Log("OvO" + value);        
        return value;
    }
    
    [MenuItem(menuB, priority = 100)]
    private static void O_O()
    {
        if (isOn)
            Debug.Log("O_O");
    }

    [MenuItem(menuC)]
    private static void OuO()
    {
        if (!isOn)
      
  • 6
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值