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系统的安全设计与架构
Android系统的安全设计与架构 一.安全策略 1.Android 的总体架构由5个主要层次上的组件构成,这5层是:Android应用层. Android框架层.Dalvik虚拟机层.用户空间原生代 ...
- Xcode7.3中SKAudioNode"诡异"初始化的解决
大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请多提意见,如果觉得不错请多多支持点赞.谢谢! hopy ;) 我没有在之前版本的Xcode中测试,不过很多人反映SKAudi ...
- 漏洞挖局利器-Fuzz技术介绍
模糊测试的定义 模糊测试定义为"通过向应用提供非预期的输入并监控输出中的异常来发现软件中的故障(faults)的方法". 典型而言,模糊测试利用自动化或是半自动化的方法重复地向应用 ...
- 1git命令的使用,查看git仓库状态,添加文件到git跟踪,git提交,查看git分支,查看git仓库日志信息,切换git分支,解决git分支合并后出现冲突的问题
1新建一个存储git的文件夹,命令是: toto@toto-K45VD:~$ mkdir gitfolder 2初始化一个git仓库,命令是: toto@toto-K45VD:~$cd gitfold ...
- Android Multimedia框架总结(七)C++中MediaPlayer的C/S架构补充及MediaService介绍
转载请把头部出处链接和尾部二维码一起转载,本文出自逆流的鱼,文章链接: http://blog.csdn.net/hejjunlin/article/details/52465168 前面一篇主要介绍 ...
- 没有文件扩展“.js”的脚本引擎问题解决
安装MinGW的时候提示没有文件扩展".js"的脚本引擎. 原因:系统安装Dreamwear.UltraEdit.EditPlus后修改了.js文件的默认打开方式.当想直接执行js ...
- css模块化及CSS Modules使用详解
什么是css模块化? 为了理解css模块化思想,我们首先了解下,什么是模块化,在百度百科上的解释是,在系统的结构中,模块是可组合.分解和更换的单元.模块化是一种处理复杂系统分解成为更好的可管理模块的方 ...
- DBoW2应用
图像对应的bag-of-words向量\(v_t\) 假设词典总共有\(W\)个单词,那么每一幅图像能够用一个\(W\)维的向量表示 \((t_1, t_2, t_3, ..., t_W)\)其中 \ ...
- iOS中 iOS10 权限崩溃问题 韩俊强的CSDN博客
iOS10 权限崩溃问题 每日更新关注:http://weibo.com/hanjunqiang 新浪微博! 今天 手机升级了 iOS10 Beta,然后用正在开发的项目 装了个ipa包,发现点击有 ...
- 05 Activity 跳转传值
第一个Activity: package com.fmyboke; import java.io.Serializable; import java.util.ArrayList; import ja ...