编写 Unity Editor 插件
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
if (GUILayout.Button(style.name, style))
{
//把名字存储在剪粘板
EditorGUIUtility.systemCopyBuffer = style.name; // "\"" + style.name + "\"";
}
GUILayout.FlexibleSpace();
EditorGUILayout.SelectableLabel("\"" + style.name + "\"");
GUILayout.EndHorizontal();
GUILayout.Space();//右边留白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 = , newMoney = , newVip = , newVp = , newCoin = , newSpirts = ;
private int maxHp = , maxVp = ,maxHurt=; private int nMapId = ; public void OnGUI()
{
EditorGUILayout.LabelField("== 加数值 指令 =="); GUILayout.BeginHorizontal();
GUILayout.Label("经验:");
newExp = EditorGUILayout.IntField(newExp, GUILayout.ExpandWidth(true), GUILayout.MinHeight());
if (GUILayout.Button("加经验", GUILayout.MinWidth(), GUILayout.MaxHeight()))
{
AddExp(newExp);
}
//-------
GUILayout.Label("VIP钱:");
newVip = EditorGUILayout.IntField(newVip, GUILayout.ExpandWidth(true), GUILayout.MinHeight());
if (GUILayout.Button("加VIP", GUILayout.MinWidth(), GUILayout.MaxHeight()))
{
AddVip(newVip);
}
GUILayout.EndHorizontal(); GUILayout.BeginHorizontal();
GUILayout.Label("金币:");
newCoin = EditorGUILayout.IntField(newCoin);
if (GUILayout.Button("加金币", GUILayout.MinWidth(), GUILayout.MaxHeight()))
{
AddCoin(newCoin);
}
//-------
GUILayout.Label("元宝");
newMoney = EditorGUILayout.IntField(newMoney);
if (GUILayout.Button("加元宝", GUILayout.MinWidth(), GUILayout.MaxHeight()))
{
AddMoney(newMoney);
}
GUILayout.EndHorizontal();
//后面继续....
}
编写 Unity Editor 插件的更多相关文章
- 开发unity DLL插件
最近开发一款设备的SDK,想着要开发unity版本,怎么做呢?首先想到的就是在外部编写相关的驱动程序然后集成成几个dll作为unity的SDK使用了.So,我就开始了unity外部插件的研究之旅了. ...
- 自己编写Android Studio插件 别停留在用的程度了(转载)
转自:自己编写Android Studio插件 别停留在用的程度了 1概述 相信大家在使用Android Studio的时候,或多或少的会使用一些插件,适当的配合插件可以帮助我们提升一定的开发效率,更 ...
- 用jquery编写的分页插件
用jquery编写的分页插件 源码 function _pager_go(total_page) { var page_str = $("#_pager_textbox").val ...
- 用jquery编写的tab插件
用jquery编写的tab插件 源码 $.fn.ss_tab = function (options) { var box = $(this); var btns = $(this).find(&qu ...
- 如何自己编写一个easyui插件续
接着如何自己编写一个easyui插件继续分享一下如何从上一节写的“hello”插件继承出一个“hello2”. 参考了combobox的源码中继承combo,当然我这个简单很多了.都是根据自己的理解来 ...
- 用Javascript编写Chrome浏览器插件
原文:http://homepage.yesky.com/62/11206062.shtml 用Javascript编写Chrome浏览器插件 2010-04-12 07:30 来源:天极网软件频道 ...
- 在Eclipse中使用Propertites Editor插件来解决property文件中文显示乱码
在一般情况下,propertites文件在eclipse中的显示中文一直显示乱码,想要解决这个问题,需要通过在eclipse中安装一个Propertites Editor插件来进行解决. 在Eclip ...
- 如何编写一个gulp插件
很久以前,我们在"细说gulp"随笔中,以压缩JavaScript为例,详细地讲解了如何利用gulp来完成前端自动化. 再来短暂回顾下,当时除了借助gulp之外,我们还利用了第三方 ...
- 使用canvas编写时间轴插件
使用canvas编写时间轴插件 背景 项目中有一个视频广场的功能,需要一个时间轴类似视频播放中进度条功能一样显示录像情况,并且可以点击.拖动.放大缩小展示时间轴,获取到时间轴的某个时间.原来的时间轴是 ...
随机推荐
- sql2008“备份集中的数据库备份与现有的xxx数据库不同”解决方法
因为是在另一台电脑对同名数据库做的备份,用常规方法还原,提示不是相同数据库,不让还原,在网上找到下面的方法解决了: 一.打开sql企业管理器,新建查询 执行以下SQL代码: RESTORE DATAB ...
- JavaScript学习笔记-函数
函数的两种创建方式:函数定义表达式.函数声明语句 编译时,函数声明语句创建的函数会‘被提前’至外部函数的作用域顶部,在该作用域内可以被随意调用: 而函数表达式创建的函数,要调用它必须赋值给一个变量,编 ...
- ionic rang在弹出modal中不可拖拽的问题
- 一维Poisson方程计算
package com.smartmap.algorithm.equation.differential.partial.ellipsoidal; import java.io.FileOutputS ...
- Android 视频播放器,在线播放
1. Bilibili https://github.com/Bilibili/ijkplayer 1.测试的时候总是崩溃,不知道是我不会用还是怎么回事. 2016-04-15 2.AndroidVi ...
- Xcode 7中http通信出现如下错误:Application Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
原因 在iOS9 beta1中,苹果将原http协议改成了https协议,使用 TLS1.2 SSL加密请求数据. 解决方法 编辑 info.plist,加入如下设置: <plist> & ...
- android MediaPlayer API大全已经方法详解(转载)
通过这张图,我们可以知道一个MediaPlayer对象有以下的状态: 1)当一个MediaPlayer对象被刚刚用new操作符创建或是调用了reset()方法后,它就处于Idle状态.当调用了rele ...
- Base64与Bitmap转换
Base64与Bitmap互转 /** * 将base64转为bitmap * * @param string * @return */ public Bitmap stringtoBitmap(St ...
- 小结RunLoop
Core Foundation中关于RunLoop的5个类 CFRunLoopRef CFRunLoopModeRef CFRunLoopSourceRef CFRunLoopTimerRef CFR ...
- Android touch mode和focusableInTouchMode分析
首先我们来看看touch mode的定义.它是用户和手机进行交互时view层次结构的一个状态.它本身是很容易理解的, 代表了最近一次的交互是否是通过触摸屏发生的,因为在Android设备上还存在别的交 ...