Unity编辑器开发入门(一)

Unity编辑器   2022-09-03 23:10   1867   1  

一个很好用的编辑器拓展工具(Odin)实现如下效果:

60928_gu32_1729.png

 60928_rxvz_4058.png

60929_bphn_1544.png 

60929_07tw_5618.png

 点击按钮输出信息

60929_40k6_4367.png

 
/*----------------------------------------------------------------
 Created by 王银
 文件名: MyCustomEditorWindow
 创建时间: 2022/8/2
 文件功能描述: Unity编辑器拓展基础
 Copyright © 2022年 王银 All rights reserved.
----------------------------------------------------------------*/
 
using Sirenix.OdinInspector;
using Sirenix.OdinInspector.Editor;
using UnityEditor;
using UnityEngine;
 
public class MyCustomEditorWindow : OdinMenuEditorWindow
{
    [MenuItem("My Game/My Editor")]
    private static void OpenWindow()
    {
        GetWindow<MyCustomEditorWindow>().Show();
    }
 
    protected override OdinMenuTree BuildMenuTree()
    {
        var tree = new OdinMenuTree();
        tree.Selection.SupportsMultiSelect = false;
 
        tree.Add("TestMenu", new TestMenu());
        tree.Add("DetailedInfoBox", new DetailedInfoBox());
        return tree;
    }
 
}
 
public class TestMenu
{
    [ButtonGroup]
    [GUIColor(255, 1, 1)]
    private void Apply()
    {
        Debug.Log("OnClick Apply");
    }
 
    [ButtonGroup]
    [GUIColor(1, 0.6f, 0.4f)]
    private void Cancel()
    {
        Debug.Log("OnClick Cancel");
    }
    [ButtonGroup]
    [GUIColor(1, 34f, 1f)]
    private void OK()
    {
        Debug.Log("OnClick OK");
    }
 
    [InfoBox("测试颜色变化文本!\n白日依山尽,\n黄河入海流。\n欲穷千里目,\n更上一层楼。\n")]
    [GUIColor("GetButtonColor")]
    [Button("I Am Fabulous", ButtonSizes.Gigantic)]
    private static void IAmFabulous()
    {
        Debug.Log("OnClick IAmFabulous");
    }
 
    [Button(ButtonSizes.Large)]
    [GUIColor("@Color.Lerp(Color.red, Color.green, Mathf.Abs(Mathf.Sin((float)EditorApplication.timeSinceStartup)))")]
    private static void Expressive()
    {
        Debug.Log("OnClick Expressive");
    }
 
#if UNITY_EDITOR 
    private static Color GetButtonColor()
    {
        Sirenix.Utilities.Editor.GUIHelper.RequestRepaint();
        return Color.HSVToRGB(Mathf.Cos((float)UnityEditor.EditorApplication.timeSinceStartup + 1f) * 0.225f + 0.325f, 1, 1);
    }
#endif
}
 
public class DetailedInfoBox
{
    [DetailedInfoBox("点我查看详情...",
        "\n白日依山尽,\n黄河入海流。\n欲穷千里目,\n更上一层楼。\n")]
    public int Field;
}


博客评论
还没有人评论,赶紧抢个沙发~
发表评论
说明:请文明发言,共建和谐网络,您的个人信息不会被公开显示。
QQ
微信
打赏
扫一扫