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:设置用于随机数生成器的 ...
随机推荐
- 【安卓开发】Android系统中Parcelable和Serializable的区别
http://greenrobot.me/devpost/android-parcelable-serializable/ 进行Android开发的时候,我们都知道不能将对象的引用传给Activiti ...
- [Mysql]由Data truncated for column联想到的sql_mode配置
系统日志中出现了 ata truncated for column 'agent' at row 1 mysql出现这个问题的原因,无非就是字符集设置 或者是 字段过长导致的. mysql在初始化的时 ...
- FORM触发器
FORM级触发器 PRE-FORM该触发器是在用户双击功能后,进入form前 WHEN-NEW-FORM-INSTANCE该触发器是在用户一进入form时执行 WHEN-FORM-NAVIGAT ...
- cenos安装jdk
安装方式:手动安装 软件:jdk-7u79-linux-x64.tar.gz 官网下载地址:进行下载. 下载完成之后上传到我们的服务器,我使用的是cenos6.5阿里云系统.securecrt工具上传 ...
- 18 Loader 总结
1. Loader 装载器 Android3.0以后出来的 它可以使Activity和Fragment 异步加载数据 变得简单(Loader里封装了AsyncTask) Loader特点: 1,对每一 ...
- Linux系统编程----孤儿进程
什么是孤儿进程? 孤儿进程, 指在父进程退出后,而子进程还在运行,这个子进程就成了孤儿进程,这时由init进程(pid=1)接管 来看看例子: #include <stdio.h> #i ...
- Oracle启用scott用户
先查询一下目前数据库是否有scott用户 select username,account_status from dba_users where username like '%SCOTT%'; 如果 ...
- Spark MLlib数据类型
MLlib支持几种数据类型:本地向量(local vectors),和存储在一个简单机器中的矩阵(matrices),以及由一个或多个RDDs组成的分布式矩阵. 1,本地向量(Local Ve ...
- Java进阶(四)Java反射TypeToken解决泛型运行时类型擦除问题
在开发时,遇到了下面这条语句,不懂,然习之. private List<MyZhuiHaoDetailModel> listLottery = new ArrayList<MyZhu ...
- (NO.00003)iOS游戏简单的机器人投射游戏成形记(二)
打开Ai按需求依次绘制机器人身体,手臂和篮框: 因为是实验性质的游戏所以没必要在这上面花太多功夫,画出意思即可.虽然是2D游戏,但实际游戏中可以表现出伪3D的图形效果;尽管本猫这次画的游戏元素都是满满 ...