Unity Editor 编写unity插件类
在unity写了一个编辑类,基于iTweenpath插件,为了更方便的操作iTweenpath,顺便练习UnityEditor的操作,写了一个CreateiTweenPath,放在Editor文件夹中。
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEditor; public class CreateiTweenPath :EditorWindow
{
[MenuItem("GameObject/CreatePath")]
static void main()
{
EditorWindow.GetWindow<CreateiTweenPath>("CreatePath");
} private Vector2 scrollVec2;
private Transform target=null;
private string pathName="new path 1";
private int nodeCount=2;
private int speed=7;
private Vector3[] nodes = new Vector3[]{Vector3.zero,new Vector3(10,0,0)};
private PathLoopType loopType=PathLoopType.once;
private Color pathColor = Color.cyan; void OnGUI()
{
scrollVec2=GUILayout.BeginScrollView(scrollVec2);
target=EditorGUILayout.ObjectField("移动物体:", target, typeof(Transform)) as Transform;
GUILayout.BeginHorizontal();
GUILayout.Label("路径名称:");
pathName=EditorGUILayout.TextField(pathName);
GUILayout.Label("速度:");
speed=EditorGUILayout.IntField(speed);
GUILayout.EndHorizontal();
loopType = (PathLoopType)EditorGUILayout.EnumPopup("循环类型:", loopType);
pathColor = EditorGUILayout.ColorField("路径颜色:", pathColor);
GUILayout.BeginHorizontal();
GUILayout.Label("路径节点数:");
nodeCount = EditorGUILayout.IntField(nodeCount);
GUILayout.EndHorizontal();
if (nodeCount > 0)
{
if (nodes.Length != nodeCount)
{
Vector3[] temp = nodes;
nodes = new Vector3[nodeCount];
for (int i = 0; i < temp.Length; i++)
{
if (i < nodes.Length)
nodes[i] = temp[i];
}
}
for (int i = 0; i < nodeCount; i++)
nodes[i] = EditorGUILayout.Vector3Field("节点 "+(i+1)+":",nodes[i]);
}
if (GUILayout.Button("创建"))
CreatePath();
GUILayout.EndScrollView();
} void CreatePath()
{
if (target == null)
{
EditorUtility.DisplayDialog("Error", "移动物体不能为null", "OK");
return;
}
if (pathName == null || pathName == "")
return;
GameObject go = new GameObject();
go.name = "iTweenPath_"+target.name;
go.AddComponent<iTweenPath>();
go.GetComponent<iTweenPath>().initialized = true;
go.GetComponent<iTweenPath>().pathName = pathName;
go.GetComponent<iTweenPath>().pathColor = pathColor;
go.GetComponent<iTweenPath>().nodeCount = nodeCount;
List<Vector3> listNodes = new List<Vector3>();
for (int i = 0; i < nodes.Length; i++)
listNodes.Add(nodes[i]);
go.GetComponent<iTweenPath>().nodes = listNodes; go.AddComponent<GoPath>();
go.GetComponent<GoPath>().target = target;
go.GetComponent<GoPath>().pathName = pathName;
go.GetComponent<GoPath>().speed = speed;
go.GetComponent<GoPath>().loopType = loopType; EditorWindow.GetWindow<CreateiTweenPath>().Close();
}
}
点击GameObject/CreatePath,显示一下界面,点击即可创建路径
Unity Editor 编写unity插件类的更多相关文章
- [Editor]Unity Editor类常用方法
Editor文档资料 Unity教程之-Unity Attribute的使用总结:http://www.unity.5helpyou.com/3550.html 利用unity3d属性来设置Inspe ...
- 如何实现Windows Phone代码与Unity相互通信(插件方式)
原地址:http://www.cnblogs.com/petto/p/3915943.html 一些废话 原文地址: http://imwper.com/unity/petto/%E5%A6%82%E ...
- Android Studio如何导出可供Unity使用的aar插件详解
http://www.cnblogs.com/xtqqkss/p/6387271.html 前言 项目之前使用Eclipse导出的jar文件来做与Android交互,最近因为工作需要需使用Androi ...
- 转载unity编辑器xml数据库插件
unity编辑器xml数据库插件 注:9月9日更新,其中MyXML.cs中有一句代码写错,查找功能失误,文中已经修改! 注:9月1日更新说明:xml存储结构,因为在用xml之前不知道正规的xml数据结 ...
- Unity协程(Coroutine)管理类——TaskManager工具分享
博客分类: Unity3D插件学习,工具分享 源码分析 Unity协程(Coroutine)管理类——TaskManager工具分享 By D.S.Qiu 尊重他人的劳动,支持原创,转载请注明出处 ...
- Unity Editor 下创建Lua和Text文件
预览 在Project视图中,扩展右键菜单,右键 – Create - Text File 创建一个Text文件,或者Lua文件. 关键点 获取当前选择的路径,以Assets路径开头 var sele ...
- Unity 自动生成组件索引类工具
Unity 自动生成组件索引类工具 需求由来 我们在写UI类时 需要获取预设中的组件 joystick = transform.Find("joystick"); backgrou ...
- Spine用于Timeline(NullReferenceException: Object reference not set to an instance of an object pine.Unity.Editor.AnimationReferenceAssetEditor.OnInspectorGUI ())
报错信息:Spine.Unity.Editor.AnimationReferenceAssetEditor.OnInspectorGUI () (at Assets/Extention/Spine/E ...
- 【Unity】6.6 Random类
分类:Unity.C#.VS2015 创建日期:2016-04-20 一.简介 Unity引擎提供的Random类可以用来生成随机数.随机点或旋转角度. 1.成员变量 seed:设置用于随机数生成器的 ...
随机推荐
- HTTP状态码总结
HTTP状态码(HTTP Status Code)是用以表示网页服务器HTTP响应状态的3位数字代码.有些 App 端接口与 HTML 接口用的是同一个,所以做移动端开发也有必要了解一下HTTP状态码 ...
- FORM调用FORM(标准调客户化&客户化调标准)并执行查询的实现研究
一.先来个比较简单的,标准FORM调用客户话FORM并执行查询 1.修改CUSTOM.PLL,使用 fnd_function.execute实现打开和传递参数 参考例子如下 PROCEDURE eve ...
- [线程]Thead 中传参数RuntimeError: thread.__init__() not called
在写一个多线程类的时候调用报错 RuntimeError: thread.__init__() not called class NotifyTread(threading.Thread): def ...
- SSL协议相关证书文件
密钥: 我理解是公钥+私钥的统称. 密钥对: 公钥(证书)和私钥成对存在.通信双方各持有自己的私钥和对方的公钥.自己的私钥需密切保护,而公钥是公开给对方的.在windows下,单独存在的公钥一般是后缀 ...
- 阻塞IO服务器模型之多线程服务器模型
针对单线程服务器模型的特点,我们可以对其进行改进,使之能对多个客户端同时进行响应.最简单的改进即是使用多线程(或多进程)服务器模型,在应用层级别,我们一般采用多线程模式.多线程能让多个客户端同时请求, ...
- CSDN发表文章后老是待审核的原因
最近开始在csdn上写文章,发现老是文章被 待审核 ,于是便在网上搜集了下网友们的反馈,最后做出以下的整理. 1.CSDN检测到文章中的链接大于5,就会将文章列为"待审核",这个其 ...
- 集合框架之Map接口
Map是将键映射到值的对象.一个映射不能包含重复的键:每个键最多只能映射到一个值. Map 接口提供三种collection视图,允许以键集.值集或键-值映射关系集的形式查看某个映射的内容.映射顺序定 ...
- UNIX网络编程——揭开网络编程常见API的面纱【下】
Linux网络编程数据收发的API流程分析 只要把数据在协议栈中的流动线路和脉络弄清楚了,关于协议栈的实现部分,理解起来就轻松多了.在网络编程章节的数据接收过程中,我们主要介绍过read ...
- Swift基础语法(常量变量、数据类型、元组、可选、断言)
本文来自Swift中文开发组,感谢翻译者的分享. 本文将分几部分对Swift对ios的语法做讲解.本文为第一节,主要讲解基础语法. 常量和变量 常量和变量把一个名字(比如maximumNumberOf ...
- myeclipse一直停留在Loading workbench界面上的处理办法
找到工作目录比如我的叫work,在.metadata中删掉以下两个文 件,再次重启myeclipse走一个! org.eclipse.ui.workbench org.eclipse.ui.workb ...