Unity EditorWindow 笔记
一:功能
1.实例化
//设置插件在菜单栏的位置 和快捷键
[MenuItem("YCC's Tools/模型更改/更改父物体和测量长度 %W")]
//实例化窗体
static void Init()
{
myTools window = (myTools)EditorWindow.GetWindow(typeof(myTools));
window.titleContent.text = "更改父物体/测长";
window.Show();
}
2.选项卡制作
//用GUI画出窗体的空间布局
void OnGUI()
{
toolbarOption = GUILayout.Toolbar(toolbarOption, toolbarTexts);
switch (toolbarOption)
{
case :
fnChangeParent();
break;
case :
fnLength();
break;
}
}
3.多个物体更改模型父物体
void fnChangeParent()
{
GUILayout.BeginHorizontal("box");
GUILayout.Label("父物体:", EditorStyles.boldLabel);
ObjParent = EditorGUILayout.ObjectField(ObjParent, typeof(Transform)) as Transform;
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal("box");
iChildCount = Selection.transforms.Length;//获取当前鼠标选中的物体个数
if (Selection.transforms.Length > )
{
GUILayout.Label("当前选中子物体个数:"+iChildCount, EditorStyles.boldLabel);
if (GUILayout.Button("应用"))
{
if (ObjParent != null)
{
for (int i = ; i < iChildCount; i++)
{
if (Selection.transforms[i].parent != ObjParent)
Selection.transforms[i].parent = ObjParent;
}
EditorUtility.DisplayDialog("提示", "已更换父物体", "确定");//显示对话框 DisplayDialog (title : string, message : string, ok : string, cancel : string = "") : bool
}
else
this.ShowNotification(new GUIContent("当前没有父物体!"));//显示通知
}
}
else
GUILayout.Label("当前没有选中子物体" , EditorStyles.boldLabel);
GUILayout.EndHorizontal();
}
4.测量两个物体在场景中的距离
void fnLength()
{
GUILayout.BeginHorizontal("box");
GUILayout.Label("测量基准物体1:", EditorStyles.boldLabel);
T1 = EditorGUILayout.ObjectField(T1, typeof(Transform)) as Transform;
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal("box");
GUILayout.Label("测量参考物体2:", EditorStyles.boldLabel);
T2 = EditorGUILayout.ObjectField(T2, typeof(Transform)) as Transform;
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
if (T1 != null && T2 != null)
{
Debug.DrawLine(T1.position, T2.position, Color.red);
//if (GUILayout.Button("查 寻"))
//{
fDistance = Vector3.Distance(T1.position, T2.position);
//}
GUILayout.Label("距离:", EditorStyles.boldLabel);
EditorGUILayout.FloatField(fDistance, EditorStyles.boldLabel);
}
GUILayout.EndHorizontal();
}
二:注意
1.重绘
//在OnInspectorUpdate上调用重绘,因为它在窗口上较少重绘,就好象是OnGUI/Update
void OnInspectorUpdate()
{
Repaint();//重绘
}
2.错误
出现错误: Invalid editor window UnityEditor.FallbackEditorWindow 解决方法:Layout-> Revert Factory Settings
Unity EditorWindow 笔记的更多相关文章
- C#程序员整理的Unity 3D笔记(十):Unity3D的位移、旋转的3D数学模型
遇到一个想做的功能,但是实现不了,核心原因是因为对U3D的3D数学概念没有灵活吃透.故再次系统学习之—第三次学习3D数学. 本次,希望实现的功能很简单: 如在小地图中,希望可以动态画出Player当前 ...
- [Unity Shader笔记]渲染路径--Forward渲染路径
[Unity Shader笔记]渲染路径--Forward渲染路径 (2014-04-22 20:08:25) 转载▼ 标签: shader unity renderingpath forward 游 ...
- unity入门笔记
我于2010年4月1日硕士毕业加入完美时空, 至今5年整.刚刚从一家公司的微端(就是端游技术+页游思想, 具体点就是c++开发, directX渲染, 资源采取所需才会下载)项目的前端主程职位离职, ...
- [Unity菜鸟] 笔记2 —— 问题篇
记录在学习<Unity 3.x 游戏开发 经典教材>时遇到的各种问题与笔记 1. 初始不能降低Terrain的高度,需要到Terrain设置的第二个按钮中将Height从0调高 (注意:最 ...
- 微软企业库Unity学习笔记
本文主要介绍: 关于Unity container配置,注册映射关系.类型,单实例.已存在对象和指出一些container的基本配置,这只是我关于Unity的学习心得和笔记,希望能够大家多交流相互学习 ...
- unity, editorWindow lose data when enter play mode
我写了个editorWindow,其中有个成员变量m_x,在创建editorWindow的时候为m_x赋的值,而在editorWindow的OnGUI里把m_x显示出来. 当我开着这个editorWi ...
- unity, editorWindow update计时
对于editorWindow,Time.deltaTime不起作用,所以需用下面方法对update进行计时: public class myEditorWindow : EditorWindow{ p ...
- Unity EditorWindow知识记录
1.创建EditorWindow using UnityEditor; using UnityEngine; public class ZZEditorWindow : EditorWindow { ...
- Unity 黑暗之光 笔记 第三章
第三章 角色控制 1.创建游戏运行场景并导入素材资源 2.创建和管理标签 1 //const 表明这个是一个共有的不可变的变量 2 public const string ground = &qu ...
随机推荐
- Java 泛型快速排序 以sdut 1196为例
oj链接:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1196 Java中,Arrays.so ...
- 将UIImage保存到iOS照片库和对应程序沙盒中-b
1.保存到iOS照片库需要引入QuartzCore.framework框架,具体代码如下:.h文件#import <QuartzCore/QuartzCore.h>UIImageView ...
- POJ 2409 Let it Bead(Polya定理)
点我看题目 题意 :给你c种颜色的n个珠子,问你可以组成多少种形式. 思路 :polya定理的应用,与1286差不多一样,代码一改就可以交....POJ 1286题解 #include <std ...
- JavaScript 将字符串转化为json对象
var json = eval('(' + data + ')'); 其中data为字符串数据
- relink:在Linux/UNIX平台上relink Oracle软件(转)
当操作系统升级后.操作系统打完补丁后.安装完Oracle补丁之后和relink过程中出现问题时,都会用到relink方法来保证Oracle软件的正常使用.本文介绍一下relink方法的使用. 1. ...
- bzoj1023
研究了一下仙人掌首先,仙人掌虽然不是树,但却有很强的树的既视感如果把每个环都看做一个点,那么他就是一棵树当然这不能直接缩环,因为环和环可以有一个交点如果是树,求直径都会做,令f[i]表示i到子树的最长 ...
- SharePoint 2010中使用Visual Studio 2010进行方便快速的Web Part开发
转:http://www.cnblogs.com/fatwhale/archive/2010/02/24/1672633.html 在Visual Studio 2010中, 已经集成了用于Shar ...
- 基础题:HDU 5122 K.Bro Sorting
Matt's friend K.Bro is an ACMer.Yesterday, K.Bro learnt an algorithm: Bubble sort. Bubble sort will ...
- Toad 中的compare使用方法
1.首先连接要对比后执行的数据库 2.设置对比内容 3.对比后的执行脚本
- javascript 和jqurry详解
javascript写的图表库,收费 highcharts jqurry有两个图标函数不收费,好用 Flot.PlotKit与MochiKit 官网下载 http://www.flotcharts.o ...