QQ扫一扫联系
一个很好用的编辑器拓展工具(Odin)实现如下效果:
点击按钮输出信息
/*---------------------------------------------------------------- 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; }