在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. EJB通过ANT提高EJB应用的开发效率、开发具有本地接口的无状态bean、开发有状态bean

    把jboss集成进eclipse 关闭Jboss控制台按Ctrl+c,在MyEclipse→Servers→Jboss里面可以配置JBoss. 通过ANT提高EJB应用的开发效率 在HelloWorl ...

  2. [ExtJS5学习笔记]第二十七节 CMD打包错误 Error C2009: YUI Parse Error (identifier is a reserved word => debugger;)

    本文地址:http://blog.csdn.net/sushengmiyan/article/details/41242993 本文作者:sushengmiyan ------------------ ...

  3. 集合框架之Collections静态工具类

    Collections类提供了一些列静态的方法,用以更方便地操作集合类 排序机制 一个List可以通过下面的方法进行排序: Collections.sort(list); 如果List包含的是字符串, ...

  4. ORACLE数据库学习之数据库的优化

     数据库的优化 概述 影响数据库性能的因素包括:系统.数据库.网络. 数据库的优化包括:优化数据库磁盘I/O.优化回滚段.优化Rrdo日志.优化系统全局区.优化数据库对象. 监控数据库的性能: 在 ...

  5. Ubuntu下安装Texmaker的问题与解决方案

    在Ubuntu下安装好了texlive后,为了开发方便,希望再继续安装一个编辑器,用于方便的编辑latex文档. 而texmaker就是一个很好的工具. 问题1, 被安装了早期版本的latex 不管你 ...

  6. 一套强大的vim配置文件+详细注释

    phpchina折腾王独家配置,灰常牛叉的一套vim配置,另附有详细注释,自己折腾vim的时候可以参照其中的大部分设置进行一些个性化定制."是否兼容VI,compatible为兼容,noco ...

  7. 4.Lucene3.案例介绍,创建索引,查询等操作验证

     案例: Article.java package cn.toto.lucene.quickstart; publicclassArticle { privateintid; private St ...

  8. 【环境配置】配置maven

    Maven是基于项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具. Maven 除了以程序构建能力为特色之外,还提供高级项目管理工具.由于 Maven 的缺 ...

  9. EBS 客户表结构

     客户表/联系人/PARTY关联 HZ_PARTIES 客户账户表 HZ_CUST_ACCOUNTS SELECT hp.party_number --客户注册标识 , hp.party_name ...

  10. Dynamics CRM 2013 Homepage Ribbon 按钮引用多个Javascript资源

    在CRM的开发中ribbon的开发是比较重要的一环,很多客制化的功能都需要动用ribbon区,CRM2013中的名字已经改叫command bar了,但从老版本过来的人都还是习惯叫他ribbon. R ...