一:功能

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. workerman安装

    1.workerman安装 workerman是php的一个socket框架,简化了socket编程,已经为很多企业所用,今天在centos的ngix+php下安装了workerman,过程记录如下. ...

  2. nRF52系列——nRF52832来袭

    nRF52系列——nRF52832来袭 Nordic凭借着在无线技术的数十年深耕,推出第一个μBlue芯片-- nRF8001.其低功耗等特性在当时吸引了无数厂商的目光,并将这产品应用到多个领域,再之 ...

  3. asp.net中Web使用Socket

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  4. skiplist 跳表(1)

    最近学习中遇到一种新的数据结构,很实用,搬过来学习. 原文地址:skiplist 跳表   为什么选择跳表 目前经常使用的平衡数据结构有:B树,红黑树,AVL树,Splay Tree, Treep等. ...

  5. Discuz帖子列表页无法ajax加载下一页问题

    上周末抽空重构了一下JX3PVE的PVE栏目,只上线了宏库栏目,结果出了一堆Bug.奈何公司这段时间都在搞完美假期这专题,太忙也没去处理.这不是周末拿时间来看一下. 发现其中有一个是点“下一页”aja ...

  6. 【C#】动态加载dll程序集

    原文:http://www.cnblogs.com/bomo/archive/2013/03/01/2938165.html 很多时候我们需要用到引用其他程序集,有些程序集是.Net生成的,可以支持反 ...

  7. nutch 索引

    nutch开发环境搭建     nutch-1.3导入eclipse     nutch-1.7导入eclipse nutch部署     nutch-1.3linux下部署     nutch-1. ...

  8. What does it mean for an algorithm to be fair

    What does it mean for an algorithm to be fair In 2014 the White House commissioned a 90-day study th ...

  9. Linux ln命令 - 建立文件/目录链接

    转自Linux ln命令 - 建立文件/目录链接 1. 使用方式:ln [option] source_file dist_file                     -f 建立时,将同档案名删 ...

  10. Android 给ListView设置Adapter

    Adapter: class MyAdapter extends BaseAdapter { private List<Person> personList; public MyAdapt ...