Unity Editor 编辑器扩展 十 Handle控件
2016-12-22 01:51
1261 查看
目录
Handle控件
按钮控制柄窗口
创建HandleTest.cs脚本,挂载到一个控物体上,然后在Editor文件夹下创建如下脚本:
选择这个控物体时,就会出现上图的效果。
本文链接:http://blog.csdn.net/WarrenMondeville/article/details/53802111
Handle控件
按钮控制柄窗口
Handle控件
按钮,控制柄,窗口
效果见图:创建HandleTest.cs脚本,挂载到一个控物体上,然后在Editor文件夹下创建如下脚本:
using UnityEngine; using UnityEditor; [CustomEditor (typeof(HandleTest))] public class HandleInspector : Editor { int windowID = 1234; Rect windowRect; void OnSceneGUI () { // 1.物体控制柄 var component = target as HandleTest; PositionHandle2 (component); PositionHandle (component.transform); // 2.控制按钮 HandleButton (); // 3.控制窗口 GUIWindow (); } void PositionHandle2 (HandleTest component) { var transform = component.transform; if (Tools.current == Tool.Move) { transform.rotation = Handles.RotationHandle (transform.rotation, transform.position); } else if (Tools.current == Tool.Rotate) { transform.position = Handles.PositionHandle (transform.position, transform.rotation); } Handles.color = Color.blue; Handles.DrawAAPolyLine (component.vertex); PositionHandle (component.transform); } static void HandleButton () { Handles.BeginGUI (); GUILayout.Button ("Button", GUILayout.Width (50)); Handles.EndGUI (); using (new HandleGUIScope ()) { GUILayout.Button ("Button", GUILayout.Width (50)); } } //添加控制窗口 void GUIWindow () { windowRect = GUILayout.Window (windowID, windowRect, id => { GUI.contentColor = Color.green; EditorGUILayout.LabelField ("Label"); EditorGUILayout.ColorField (Color.cyan); EditorGUILayout.ToggleLeft ("Toggle", false); GUILayout.Button ("Button"); GUI.DragWindow (); }, "Window", GUILayout.Width (100)); } //控制柄 Vector3 PositionHandle (Transform transform) { var size = 1; var position = transform.position; Handles.color = Handles.xAxisColor; position = Handles.Slider (position, transform.right, size, Handles.CircleCap, 1); //X 軸 Handles.color = Color.cyan; position = Handles.Slider (position, transform.up); //Y 軸 Handles.color = Color.black; position = Handles.Slider (position, transform.forward); //Z 軸 transform.position = Handles.FreeMoveHandle ( transform.position, transform.rotation, size, Vector3.one, Handles.RectangleCap); transform.rotation = Handles.FreeRotateHandle ( transform.rotation, transform.position, 2); return position; } } public class HandleGUIScope : GUI.Scope { public HandleGUIScope () { Handles.BeginGUI (); } protected override void CloseScope () { Handles.EndGUI (); } }
选择这个控物体时,就会出现上图的效果。
本文链接:http://blog.csdn.net/WarrenMondeville/article/details/53802111
相关文章推荐
- Unity Editor 编辑器扩展 六 EditorWindow
- UnityEditor扩展 - 编辑器中的内置属性Attribute
- Unity Editor 编辑器扩展 七 创建脚本模版
- Unity扩展编辑器--类型1:Editor Windows
- Unity Editor 编辑器扩展 十一 Inspector可排序列表
- 【Unity编辑器】EditorWindow扩展-SubWindow
- Unity Editor 编辑器扩展三 Unity Editor 数据持久化及Editor窗口的初识
- Unity Editor 编辑器扩展 十三 自定义创建资源
- UnityEditor扩展编辑器实现从场景中渲染得到Cubemap
- Unity Editor Toolbar 编辑器扩展
- [cb]Unity Editor Toolbar 编辑器扩展
- Unity Editor 编辑器扩展 十五 提取NGUI 的Transform ResetPosition 功能
- Unity Editor 编辑器扩展 八 Undo
- Unity Editor 编辑器扩展 五 EditorGUI
- Unity编辑器扩展之EditorWindow
- Unity之EditorGUILayout-显示控件禁止对控件进行操作
- 【转载】Unity3d UnityEditor编辑器定制和开发插件
- Unity 编辑器扩展自定义窗体
- Unity编辑器扩展Texture显示选择框
- Unity 编辑器扩展 场景视图内控制对象