概述
Editor Style Viewer
在开发过程中,我喜欢编写一些辅助的Editor插件,方便在游戏开发过程进行调试。
下面是摘自Asset Store的一个查看Unity 默认GUI样式的小工具
插件链接:Editor Style Viewer https://www.assetstore.unity3d.com/en/#!/content/3282
预览
Editor Style Viewer源码
原理:遍历所有的GUI.skin,并显示其样式
using UnityEngine; using UnityEditor; /// <summary> /// 查看默认的gui skin样式 /// </summary> public class EditorStyleView : EditorWindow { private Vector2 scrollPosition = Vector2.zero; private string search = string.Empty; [MenuItem("Tools/默认GUI样式查看器")] static void Init() { var window= EditorWindow.GetWindow<EditorStyleView>(); window.title = "GUI样式查看器"; window.Show(); } void OnGUI() { GUILayout.BeginHorizontal("HelpBox"); GUILayout.Label("单击左侧样式将复制其名到剪贴板", "label"); GUILayout.FlexibleSpace(); GUILayout.Label("查找:"); search = EditorGUILayout.TextField(search); GUILayout.EndHorizontal(); scrollPosition = GUILayout.BeginScrollView(scrollPosition); //foreach (GUIStyle style in GUI.skin.customStyles) foreach (GUIStyle style in GUI.skin) { //过滤 if (style.name.ToLower().Contains(search.ToLower())) { //设置奇偶行不同背景 GUILayout.BeginHorizontal("PopupCurveSwatchBackground"); GUILayout.Space(20);//左边留白20 if (GUILayout.Button(style.name, style)) { //把名字存储在剪粘板 EditorGUIUtility.systemCopyBuffer = style.name; // """ + style.name + """; } GUILayout.FlexibleSpace(); EditorGUILayout.SelectableLabel(""" + style.name + """); GUILayout.EndHorizontal(); GUILayout.Space(20);//右边留白20 } } GUILayout.EndScrollView(); } }
GM编辑器插件
比如这样的GM小工具,辅助开发团队。
1、创建GMEditorWindow.cs,放在Editor目录下
2、编写与游戏相关的逻辑功能
GM编辑器插件源码
[MenuItem("Game/GM指令")] static void Init() { var window = EditorWindow.GetWindow<GMEditorWindow>(); window.title = "XX GM指令"; window.Show(); } private int newExp = 0, newMoney = 0, newVip = 0, newVp = 0, newCoin = 0, newSpirts = 0; private int maxHp = 0, maxVp = 0,maxHurt=0; private int nMapId = 0; public void OnGUI() { EditorGUILayout.LabelField("== 加数值 指令 =="); GUILayout.BeginHorizontal(); GUILayout.Label("经验:"); newExp = EditorGUILayout.IntField(newExp, GUILayout.ExpandWidth(true), GUILayout.MinHeight(20)); if (GUILayout.Button("加经验", GUILayout.MinWidth(100), GUILayout.MaxHeight(20))) { AddExp(newExp); } //------- GUILayout.Label("VIP钱:"); newVip = EditorGUILayout.IntField(newVip, GUILayout.ExpandWidth(true), GUILayout.MinHeight(20)); if (GUILayout.Button("加VIP", GUILayout.MinWidth(100), GUILayout.MaxHeight(20))) { AddVip(newVip); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("金币:"); newCoin = EditorGUILayout.IntField(newCoin); if (GUILayout.Button("加金币", GUILayout.MinWidth(100), GUILayout.MaxHeight(20))) { AddCoin(newCoin); } //------- GUILayout.Label("元宝"); newMoney = EditorGUILayout.IntField(newMoney); if (GUILayout.Button("加元宝", GUILayout.MinWidth(100), GUILayout.MaxHeight(20))) { AddMoney(newMoney); } GUILayout.EndHorizontal(); //后面继续.... }
最后
以上就是笑点低星月为你收集整理的编写 Unity Editor 插件的全部内容,希望文章能够帮你解决编写 Unity Editor 插件所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复