在unity写了一个编辑类,基于iTweenpath插件,为了更方便的操作iTweenpath,顺便练习UnityEditor的操作,写了一个CreateiTweenPath,放在Editor文件夹中。

  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEditor;
  5.  
  6. public class CreateiTweenPath :EditorWindow
  7. {
  8. [MenuItem("GameObject/CreatePath")]
  9. static void main()
  10. {
  11. EditorWindow.GetWindow<CreateiTweenPath>("CreatePath");
  12. }
  13.  
  14. private Vector2 scrollVec2;
  15. private Transform target=null;
  16. private string pathName="new path 1";
  17. private int nodeCount=2;
  18. private int speed=7;
  19. private Vector3[] nodes = new Vector3[]{Vector3.zero,new Vector3(10,0,0)};
  20. private PathLoopType loopType=PathLoopType.once;
  21. private Color pathColor = Color.cyan;
  22.  
  23. void OnGUI()
  24. {
  25. scrollVec2=GUILayout.BeginScrollView(scrollVec2);
  26. target=EditorGUILayout.ObjectField("移动物体:", target, typeof(Transform)) as Transform;
  27. GUILayout.BeginHorizontal();
  28. GUILayout.Label("路径名称:");
  29. pathName=EditorGUILayout.TextField(pathName);
  30. GUILayout.Label("速度:");
  31. speed=EditorGUILayout.IntField(speed);
  32. GUILayout.EndHorizontal();
  33. loopType = (PathLoopType)EditorGUILayout.EnumPopup("循环类型:", loopType);
  34. pathColor = EditorGUILayout.ColorField("路径颜色:", pathColor);
  35. GUILayout.BeginHorizontal();
  36. GUILayout.Label("路径节点数:");
  37. nodeCount = EditorGUILayout.IntField(nodeCount);
  38. GUILayout.EndHorizontal();
  39. if (nodeCount > 0)
  40. {
  41. if (nodes.Length != nodeCount)
  42. {
  43. Vector3[] temp = nodes;
  44. nodes = new Vector3[nodeCount];
  45. for (int i = 0; i < temp.Length; i++)
  46. {
  47. if (i < nodes.Length)
  48. nodes[i] = temp[i];
  49. }
  50. }
  51. for (int i = 0; i < nodeCount; i++)
  52. nodes[i] = EditorGUILayout.Vector3Field("节点 "+(i+1)+":",nodes[i]);
  53. }
  54. if (GUILayout.Button("创建"))
  55. CreatePath();
  56. GUILayout.EndScrollView();
  57. }
  58.  
  59. void CreatePath()
  60. {
  61. if (target == null)
  62. {
  63. EditorUtility.DisplayDialog("Error", "移动物体不能为null", "OK");
  64. return;
  65. }
  66. if (pathName == null || pathName == "")
  67. return;
  68. GameObject go = new GameObject();
  69. go.name = "iTweenPath_"+target.name;
  70. go.AddComponent<iTweenPath>();
  71. go.GetComponent<iTweenPath>().initialized = true;
  72. go.GetComponent<iTweenPath>().pathName = pathName;
  73. go.GetComponent<iTweenPath>().pathColor = pathColor;
  74. go.GetComponent<iTweenPath>().nodeCount = nodeCount;
  75. List<Vector3> listNodes = new List<Vector3>();
  76. for (int i = 0; i < nodes.Length; i++)
  77. listNodes.Add(nodes[i]);
  78. go.GetComponent<iTweenPath>().nodes = listNodes;
  79.  
  80. go.AddComponent<GoPath>();
  81. go.GetComponent<GoPath>().target = target;
  82. go.GetComponent<GoPath>().pathName = pathName;
  83. go.GetComponent<GoPath>().speed = speed;
  84. go.GetComponent<GoPath>().loopType = loopType;
  85.  
  86. EditorWindow.GetWindow<CreateiTweenPath>().Close();
  87. }
  88. }

点击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. 【安卓开发】Android系统中Parcelable和Serializable的区别

    http://greenrobot.me/devpost/android-parcelable-serializable/ 进行Android开发的时候,我们都知道不能将对象的引用传给Activiti ...

  2. [Mysql]由Data truncated for column联想到的sql_mode配置

    系统日志中出现了 ata truncated for column 'agent' at row 1 mysql出现这个问题的原因,无非就是字符集设置 或者是 字段过长导致的. mysql在初始化的时 ...

  3. FORM触发器

     FORM级触发器 PRE-FORM该触发器是在用户双击功能后,进入form前 WHEN-NEW-FORM-INSTANCE该触发器是在用户一进入form时执行 WHEN-FORM-NAVIGAT ...

  4. cenos安装jdk

    安装方式:手动安装 软件:jdk-7u79-linux-x64.tar.gz 官网下载地址:进行下载. 下载完成之后上传到我们的服务器,我使用的是cenos6.5阿里云系统.securecrt工具上传 ...

  5. 18 Loader 总结

    1. Loader 装载器 Android3.0以后出来的 它可以使Activity和Fragment 异步加载数据 变得简单(Loader里封装了AsyncTask) Loader特点: 1,对每一 ...

  6. Linux系统编程----孤儿进程

    什么是孤儿进程? 孤儿进程,  指在父进程退出后,而子进程还在运行,这个子进程就成了孤儿进程,这时由init进程(pid=1)接管 来看看例子: #include <stdio.h> #i ...

  7. Oracle启用scott用户

    先查询一下目前数据库是否有scott用户 select username,account_status from dba_users where username like '%SCOTT%'; 如果 ...

  8. Spark MLlib数据类型

        MLlib支持几种数据类型:本地向量(local vectors),和存储在一个简单机器中的矩阵(matrices),以及由一个或多个RDDs组成的分布式矩阵. 1,本地向量(Local Ve ...

  9. Java进阶(四)Java反射TypeToken解决泛型运行时类型擦除问题

    在开发时,遇到了下面这条语句,不懂,然习之. private List<MyZhuiHaoDetailModel> listLottery = new ArrayList<MyZhu ...

  10. (NO.00003)iOS游戏简单的机器人投射游戏成形记(二)

    打开Ai按需求依次绘制机器人身体,手臂和篮框: 因为是实验性质的游戏所以没必要在这上面花太多功夫,画出意思即可.虽然是2D游戏,但实际游戏中可以表现出伪3D的图形效果;尽管本猫这次画的游戏元素都是满满 ...