一:功能

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 笔记的更多相关文章

  1. C#程序员整理的Unity 3D笔记(十):Unity3D的位移、旋转的3D数学模型

    遇到一个想做的功能,但是实现不了,核心原因是因为对U3D的3D数学概念没有灵活吃透.故再次系统学习之—第三次学习3D数学. 本次,希望实现的功能很简单: 如在小地图中,希望可以动态画出Player当前 ...

  2. [Unity Shader笔记]渲染路径--Forward渲染路径

    [Unity Shader笔记]渲染路径--Forward渲染路径 (2014-04-22 20:08:25) 转载▼ 标签: shader unity renderingpath forward 游 ...

  3. unity入门笔记

    我于2010年4月1日硕士毕业加入完美时空, 至今5年整.刚刚从一家公司的微端(就是端游技术+页游思想, 具体点就是c++开发, directX渲染, 资源采取所需才会下载)项目的前端主程职位离职, ...

  4. [Unity菜鸟] 笔记2 —— 问题篇

    记录在学习<Unity 3.x 游戏开发 经典教材>时遇到的各种问题与笔记 1. 初始不能降低Terrain的高度,需要到Terrain设置的第二个按钮中将Height从0调高 (注意:最 ...

  5. 微软企业库Unity学习笔记

    本文主要介绍: 关于Unity container配置,注册映射关系.类型,单实例.已存在对象和指出一些container的基本配置,这只是我关于Unity的学习心得和笔记,希望能够大家多交流相互学习 ...

  6. unity, editorWindow lose data when enter play mode

    我写了个editorWindow,其中有个成员变量m_x,在创建editorWindow的时候为m_x赋的值,而在editorWindow的OnGUI里把m_x显示出来. 当我开着这个editorWi ...

  7. unity, editorWindow update计时

    对于editorWindow,Time.deltaTime不起作用,所以需用下面方法对update进行计时: public class myEditorWindow : EditorWindow{ p ...

  8. Unity EditorWindow知识记录

    1.创建EditorWindow using UnityEditor; using UnityEngine; public class ZZEditorWindow : EditorWindow { ...

  9. Unity 黑暗之光 笔记 第三章

    第三章 角色控制   1.创建游戏运行场景并导入素材资源 2.创建和管理标签 1 //const 表明这个是一个共有的不可变的变量 2 public const string ground = &qu ...

随机推荐

  1. (转载)delphi 把图片存入数据库

    delphi 把图片存入数据库 procedure TForm1.Button1Click(Sender: TObject); // 插入图片过程var Stream:TMemoryStream;be ...

  2. Omnithreadlibary学习(1)-异步执行

    program main; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils, OtlParallel; begin Parallel.Async( ...

  3. Python 集合(set)使用

    1.python的set和其他语言类似, 是一个无序不重复元素集, 基本功能包括关系测试和消除重复元素. 集合对象还支持union(联合), intersection(交), difference(差 ...

  4. ubuntu下的软件安装

    1.软件安装 最近开始将个人电脑由windows换成linux,第一步就是会装一些个人软件,以前玩linux都是用yum或者apt-get来进行安装. 下面介绍一下如何从官网下载文件并且安装的方法. ...

  5. 强大DevExpress,Winform LookUpEdit 实现多列查询 gridview弹出下拉选择 z

    关键代码请参考http://www.devexpress.com/Support/Center/p/K18333.aspx 最新DEMO 下载 The current GridLookUpEdit's ...

  6. HDU 1394 Minimum Inversion Number 线段树

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=1394 没看到多组输入,WA了一万次...... 其实很简单,有人暴力过得,我感觉归并排序.二叉排序树求逆 ...

  7. POJ 3273 Monthly Expense 二分枚举

    题目:http://poj.org/problem?id=3273 二分枚举,据说是经典题,看了题解才做的,暂时还没有完全理解.. #include <stdio.h> #include ...

  8. utube视频落地

    utube视频落地 简单粗暴的方法: 利用视频下载网站的网页版进行处理. 比如需要下载的视频的url是vid_url, 需要用到的web服务的url是web_service vid_url='http ...

  9. 隐藏 Status Bar

    iOS6和iOS7在隐藏 Status Bar 三种方式比较: Storyboard 界面上选中UIViewController,最右边Simulated Metrics找到 Status Bar 设 ...

  10. 【技术贴】解决 myeclipse打不开报错an error has occurred, see .

    方法1.右键选中快捷方式属性选项,在快捷方式页,目标一项最后加上-clean选项,如C:\MyEclipse6\eclipse.exe -clean. 然后重新启动一下MyEclipse. 方法2. ...