在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. 【SSH系列】-- hibernate基本原理&&入门demo

        什么是hibernate?      hibernate在英文中是冬眠的意思,当冬季来临,世界万物开始准备冬眠,但是程序猿这种动物好像不冬眠,因为需求变了,要改bug,冬眠,对于对象来说就是持 ...

  2. activiti processEngineLifecycleListener使用

    1.1.1. 前言 实际开发中,有需求如下: 第一:项目启动部署的时候,我们需要监控activiti 工作流引擎是否真正的已经实例化启动了,这里说的是工作流引擎的启动,不是流程实例的启动,对此要特别说 ...

  3. Blue Path(基于cocos2dx 3.0)

    猴子原创,欢迎转载.转载请注明: 转载自Cocos2D开发网–Cocos2Dev.com,谢谢! 原文地址: http://www.cocos2dev.com/?p=498 iTunes下载:http ...

  4. 最简单的基于DirectShow的示例:获取Filter信息

    ===================================================== 最简单的基于DirectShow的示例文章列表: 最简单的基于DirectShow的示例:视 ...

  5. C语言--指针函数和函数指针

    指针函数和函数指针 指针函数其实是一个简称,是指带指针的函数,它本质上是一个函数,只是返回的是某种类型的指针.其定义的格式为: 类型标识符 *函数名(参数表)  函数指针,从本质上说是一个指针,只是它 ...

  6. listview下拉刷新上拉加载扩展(三)-仿最新版美团外卖

    本篇是基于上篇listview下拉刷新上拉加载扩展(二)-仿美团外卖改造而来,主要调整了headview的布局,并加了两个背景动画,看似高大上,其实很简单: as源码地址:http://downloa ...

  7. 给你的流添加缓冲装置——字节块ByteChunk

    这是一个很重要的一个字节数组处理缓冲工具,它封装了字节缓冲器及对字节缓冲区的操作,包括对缓冲区的写入.读取.扩展缓冲区大小等等,另外还提供相应字符编码的转码操作.此工具让缓冲操作变得更加方便,除了缓冲 ...

  8. 用 Freemarker 生成 word 文档

     阅读目录 添加图片 自定义载入模板 1.       用word写一个需要导出的word模板,然后存为xml格式. 2.       将xml中需要动态修改内容的地方,换成freemarker的 ...

  9. AnimatedPathView实现自定义图片标签

    老早用过小红书app,对于他们客户端笔记这块的设计非常喜欢,恰好去年在小红书的竞争对手公司,公司基于产品的考虑和产品的发展,也需要将app社交化,于是在社区分享这块多多少少参照了小红书的设计,这里面就 ...

  10. Android官方命令深入分析之etc1tool

    etc1tool是一个命令行工具,可以将PNG图像压缩为etc1标准,并且可以进行解压缩. 用法: etc1tool infile [--help | --encode | --encodeNoHea ...