查看Unity的GUI样式
2016-01-21 12:46
573 查看
Editor Style Viewer
在开发过程中,我喜欢编写一些辅助的Editor插件,方便在游戏开发过程进行调试。下面是摘自Asset Store的一个查看Unity 默认GUI样式的小工具
插件链接:Editor Style Viewer https://www.assetstore.unity3d.com/en/#!/content/3282
预览
![](http://images2015.cnblogs.com/blog/363476/201601/363476-20160121124523859-199426859.png)
![](http://images2015.cnblogs.com/blog/363476/201601/363476-20160121124527109-1500072448.png)
代码
原理:遍历所有的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小工具,辅助开发![](http://images2015.cnblogs.com/blog/363476/201601/363476-20160121124531953-623001930.png)
1、创建GMEditorWindow.cs,放在Editor目录下
2、编写与游戏相关的逻辑功能
[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(); //后面继续.... }
相关文章推荐
- (二十一)unity4.6学习Ugui中文文档-------交互-Supported Events & Raycasters
- unity3d 如何得到当前物体播放的动画
- Unity3D截图并保存任意目录
- Unity3D中Layers和LayerMask解析
- 初学Unity(无法响应的简单原因以及队列的使用)
- unity学习(三)
- 四元数面向对象
- Unity 实时 半透明 阴影 shader
- Unity Motion Blur 运动模糊的实现
- Unity 中实现 打击感的物理
- unity初学(基本的方法)
- Unity 编辑器环境下不能正确加载Android Assetbundle 中的 Shader 解决方法
- Unity3d获取物体的所有子物体对象(child)
- unity car demo解析
- Unity 往复运动的一种计算方法
- Unity Button 动画
- Unity3D学习之Camera
- Unity判断当前鼠标顺逆时针旋转的简单算法
- Unity3D Android手机开发环境配置
- Unity3D插件之FingerGesture的使用