在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插件类的更多相关文章

  1. [Editor]Unity Editor类常用方法

    Editor文档资料 Unity教程之-Unity Attribute的使用总结:http://www.unity.5helpyou.com/3550.html 利用unity3d属性来设置Inspe ...

  2. 如何实现Windows Phone代码与Unity相互通信(插件方式)

    原地址:http://www.cnblogs.com/petto/p/3915943.html 一些废话 原文地址: http://imwper.com/unity/petto/%E5%A6%82%E ...

  3. Android Studio如何导出可供Unity使用的aar插件详解

    http://www.cnblogs.com/xtqqkss/p/6387271.html 前言 项目之前使用Eclipse导出的jar文件来做与Android交互,最近因为工作需要需使用Androi ...

  4. 转载unity编辑器xml数据库插件

    unity编辑器xml数据库插件 注:9月9日更新,其中MyXML.cs中有一句代码写错,查找功能失误,文中已经修改! 注:9月1日更新说明:xml存储结构,因为在用xml之前不知道正规的xml数据结 ...

  5. Unity协程(Coroutine)管理类——TaskManager工具分享

    博客分类: Unity3D插件学习,工具分享 源码分析   Unity协程(Coroutine)管理类——TaskManager工具分享 By D.S.Qiu 尊重他人的劳动,支持原创,转载请注明出处 ...

  6. Unity Editor 下创建Lua和Text文件

    预览 在Project视图中,扩展右键菜单,右键 – Create - Text File 创建一个Text文件,或者Lua文件. 关键点 获取当前选择的路径,以Assets路径开头 var sele ...

  7. Unity 自动生成组件索引类工具

    Unity 自动生成组件索引类工具 需求由来 我们在写UI类时 需要获取预设中的组件 joystick = transform.Find("joystick"); backgrou ...

  8. 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 ...

  9. 【Unity】6.6 Random类

    分类:Unity.C#.VS2015 创建日期:2016-04-20 一.简介 Unity引擎提供的Random类可以用来生成随机数.随机点或旋转角度. 1.成员变量 seed:设置用于随机数生成器的 ...

随机推荐

  1. Dynamics CRM2013 从外部系统取到CRM系统的用户头像

    CRM从2013开始引入了entityimage的概念,具体这个字段怎么设置的,图像是怎么上传的这里就不谈了.说实在的这玩意在项目中没啥用,所以也没去关注,直到最近遇到了个难题,要在外部系统去获取这个 ...

  2. Android简易实战教程--第三十四话《 自定义SeekBar以及里面的一些小知识》

    转载本专栏文章,请注明出处尊重原创:博客地址http://blog.csdn.net/qq_32059827/article/details/52849676:小杨的博客 许多应用可能需要加入进度,例 ...

  3. 使用OpenCV读、操作、写图像并与bash合作对某个目录下所有图像进行类似处理

    我门要对某个目录下所有图像文件进行统一处理,如果图像的数量过多,那么手动地一张张处理就会显得有些麻烦.本文使用OpenCV和bash来完成我们指定的任务. 任务 将目录A下的所有统一格式的jpg图像变 ...

  4. Android 网络图片加载之cude 框架

    偶然发现了这个框架,阿里图片加载用的这个框架.非常简单操作步骤. 1.首先下载软件包,直接搜Cube ImageLoader 这个. 2.加入jar文件 3.使用前的配置: public class ...

  5. [Vim]新建python文件自动添加python header

    使用vim脚本来实现的,使用了模板,几行代码就能实现很实用. ~/.vimrc 中的代码 "auto add pyhton header --start autocmd BufNewFile ...

  6. 模拟DbUtils实现接口回调机制

    想必大家都用过apache 的DbUtils吧,这个简单的对JDBC的封装小框架真的是非常非常的适合新手的学习呢.逻辑上也不是很复杂,难度刚刚好. 下面我就模仿它来实现一个字符串的处理小框架. 思路 ...

  7. SYBASE的select into与insert into使用和区别

    对于表的部分或全部字段的复制,Sybase数据库提供了两种方式:select into和insert into. select into: 语法:select  value1, value2, val ...

  8. Android初级教程通过简要分析“土司”源码,来自实现定义土司理论探讨

    由于系统自带的土司瞬间即逝,而且非常难看.因此我们就希望自定义自己的土司风格.有些实例就是基于自定义土司完成的,例如金山卫士的火箭发射,基本原理就是个土司.但是在做出自己的土司风格之前,还是要简要分析 ...

  9. Servlet编程实例-servlet学习之旅(三)

    LoginServlet代码: public class LoginServlet extends HttpServlet{ @Override protected void service(Http ...

  10. Android的ToggleButton和Switch以及AnalogColok和DigitalColok的用法-android学习之旅(二十)

    ToggleButton 和Switch简介 ToggleButton 和Switch都是继承了Button,所以他们的属性设置和Button差不多. 分别支持的属性 ToggleButton 的属性 ...