Unity Editor 编写unity插件类
2015-10-26 22:39
477 查看
在unity写了一个编辑类,基于iTweenpath插件,为了更方便的操作iTweenpath,顺便练习UnityEditor的操作,写了一个CreateiTweenPath,放在Editor文件夹中。
点击GameObject/CreatePath,显示一下界面,点击即可创建路径
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】NGUI核心组件之UIPanel
- 【NGUI】Unity使用Resources加载NGUI的图片
- 基于Unity行为树设计与实现的尝试
- Unity游戏开发使用Assetbundle加载场景实战
- unity3d之UIPlayTween。
- 基于Unity-NGUI的可重用列表
- (unity)用SQLite Manager工具写好的数据库sqlite文件如何随着发布导入安卓手机
- 【Unity】在安卓手机上使用SQLite
- Unity3D中使用easyroad3d插件 删除道路
- unity3d 调用Start 注意
- Unity5 VS UE4
- Unity UGUI——Rect Transform包裹(Anchor Presets)
- Unity 5 中的全局光照技术详解
- Unity3D课程系列上线--《unity 常用组件分析》
- Unity之图片高光处理
- Unity3D 学习笔记3——了解U3D引擎的操作面板和各种工具
- Unity5.0标准资源包
- 【笨木头Unity】入门之旅004:地形初初初级介绍
- Unity3D之将图片转成NormalMap
- Unity3d 应用系统分析