Handles就是在SceneView里画一些能响应用户操作的几何图案,并影响指定的变量数值。

Handles类的接口大致分为以下几种

1. Draw:绘制元几何体,如点、线、面等
DrawAAPolyLine Draw anti-aliased line specified with point array and width. DrawBezier Draw textured bezier line through start and end points with the given tangents. To get an anti-aliased effect use a texture that is 1x2 pixels with one transparent white pixel and one opaque white pixel. The bezier curve will be swept using this texture.
DrawLine Draw a line from p1 to p2.
DrawPolyLine Draw a line going through the list of all points.
DrawSolidArc Draw a circular sector (pie piece) in 3D space.
DrawSolidDisc Draw a solid flat disc in 3D space.
DrawSolidRectangleWithOutline Draw a solid outlined rectangle in 3D space.
DrawWireArc Draw a circular arc in 3D space.
DrawWireDisc Draw the outline of a flat disc in 3D space.

2. Handle:可视化操作数值,比如Vector3,Vector2,float等
DoPositionHandle 类似对象移动的三向操作器 DoRotationHandle 类似对象旋转的三向圆环操作器
DoScaleHandle 类似对象缩放的三轴操作器
FreeMoveHandle Make an unconstrained movement handle.
FreeRotateHandle Make an unconstrained rotation handle.
PositionHandle Make a 3D Scene view position handle.
RadiusHandle Make a Scene view radius handle.
RotationHandle Make a Scene view rotation handle.
ScaleHandle Make a Scene view scale handle.
ScaleValueHandle Make a single-float draggable handle.

3. Caps:绘制多边形几何体,比如方块,点精灵,球形,圆锥等
ArrowCap Draw an arrow like those used by the move tool. SphereCap Draw a Sphere. Pass this into handle functions.
CircleCap Draw a camera-facing Circle. Pass this into handle functions.
ConeCap Draw a Cone. Pass this into handle functions.
CubeCap Draw a cube. Pass this into handle functions.
CylinderCap Draw a Cylinder. Pass this into handle functions.
DotCap Draw a camera-facing dot. Pass this into handle functions.
RectangleCap 画个矩形
SelectionFrame Draw a camera facing selection frame.

4. 2DGUI:用GUILayout或EditorGUILayout代替吧
BeginGUI Begin a 2D GUI block inside the 3D handle GUI. EndGUI End a 2D GUI block and get back to the 3D handle GUI.
Slider2D Slide a handle in a 2D plane.

5. Camera:摄像机
DrawCamera Draws a camera inside a rectangle. SetCameraSet the current camera so all Handles and Gizmos are draw with its settings.
ClearCamera Clears the camera.
SnapValue Rounds the value val to the closest multiple of snap (snap can only be posiive)

测试代码

using UnityEngine;
using System.Collections;public class SceneTag : MonoBehaviour
{public Vector3 vectorPoint = Vector3.zero;public Vector3 vectorPoint2 = Vector3.zero;public float shieldArea = 5;public Quaternion rot = Quaternion.identity;
}
using UnityEngine;
using UnityEditor;
using System.Collections;
using System;
using System.Text;[CustomEditor(typeof(SceneTag))]
public class SceneEditor : Editor
{void OnSceneGUI(){Test_Handles();Test_Event();}private static void Test_Event(){Vector2 mousePosition = Event.current.mousePosition;StringBuilder sb = new StringBuilder();sb.AppendFormat("({0},{1})", mousePosition.x, mousePosition.y);//Debug.Log(sb.ToString());}private void Test_Handles(){SceneTag scene = target as SceneTag;Test_Color(scene);//Test_Button(scene);Test_ArrowCap(scene);Test_CircleCap(scene);Test_ChangeValue(scene);Test_DrawAAPolyLine(scene);Test_DrawSolidArc(scene);Test_ScaleValueHandle(scene);Test_FreeRotateHandle(scene);Test_FreeMoveHandle(scene);Test_BeginGUI(scene);if (GUI.changed)EditorUtility.SetDirty(target);}private static void Test_FreeMoveHandle(SceneTag scene){scene.vectorPoint = Handles.FreeMoveHandle(scene.vectorPoint,Quaternion.identity,2.0f,Vector3.zero,Handles.ArrowCap);}private static void Test_FreeRotateHandle(SceneTag scene){scene.transform.rotation = Handles.FreeRotateHandle(scene.transform.rotation, scene.transform.position, 0.5f);}private static void Test_ScaleValueHandle(SceneTag scene){scene.shieldArea= Handles.ScaleValueHandle(scene.shieldArea,scene.transform.position + scene.transform.forward * scene.shieldArea,scene.transform.rotation,1,Handles.ConeCap,1);}private static void Test_DrawSolidArc(SceneTag scene){Handles.color = new Color(1, 1, 1, 0.2f);Handles.DrawSolidArc(scene.transform.position,scene.transform.up,-scene.transform.right,270,scene.shieldArea);Handles.color = Color.white;scene.shieldArea =Handles.ScaleValueHandle(scene.shieldArea,scene.transform.position + scene.transform.forward * scene.shieldArea,scene.transform.rotation,1,Handles.ConeCap,1);}private static void Test_DrawAAPolyLine(SceneTag scene){Vector3[] positions = new Vector3[]{new Vector3(2,0,0),new Vector3(2,1,0),new Vector3(2,1,1),new Vector3(1,2,1),new Vector3(1,2,2),};for (int i = 0; i < positions.Length; ++i){positions[i] += scene.transform.position;}Handles.DrawAAPolyLine(positions);}private static void Test_ChangeValue(SceneTag scene){scene.rot =Handles.Disc(scene.rot,scene.transform.position,new Vector3(1, 1, 0),5,false,1);scene.vectorPoint = Handles.DoPositionHandle(scene.vectorPoint, Quaternion.identity);scene.vectorPoint2 = Handles.DoPositionHandle(scene.vectorPoint2, Quaternion.identity);}private static void Test_CircleCap(SceneTag scene){float circleSize = 1;Handles.color = Color.red;Handles.CircleCap(0,scene.transform.position + new Vector3(5, 0, 0),scene.transform.rotation,circleSize);Handles.color = Color.green;Handles.CircleCap(0,scene.transform.position + new Vector3(0, 5, 0),scene.transform.rotation,circleSize);Handles.color = Color.blue;Handles.CircleCap(0,scene.transform.position + new Vector3(0, 0, 5),scene.transform.rotation,circleSize);Handles.color = Color.red;Vector3 newpos = scene.transform.position + new Vector3(5, 0, 0);circleSize = HandleUtility.GetHandleSize(newpos);Handles.CircleCap(0,newpos,scene.transform.rotation,circleSize);Handles.color = Color.green;newpos = scene.transform.position + new Vector3(0, 5, 0);circleSize = HandleUtility.GetHandleSize(newpos);Handles.CircleCap(0,newpos,scene.transform.rotation,circleSize);Handles.color = Color.blue;newpos = scene.transform.position + new Vector3(0, 0, 5);circleSize = HandleUtility.GetHandleSize(newpos);Handles.CircleCap(0,newpos,scene.transform.rotation,circleSize);}// 3D按钮还会因为视角问题呈现不一样的大小。;// 而且按钮的当前状态也更新不及时,逗么?;private static void Test_Button(SceneTag scene){Handles.Button(scene.transform.position + new Vector3(0, 2, 0),Quaternion.identity,3,3,Handles.RectangleCap);}private static void Test_BeginGUI(SceneTag scene){Handles.color = Color.blue;Handles.Label(scene.transform.position + Vector3.up * 2,scene.transform.position.ToString() + "\nShieldArea: " +scene.shieldArea.ToString());Handles.color = Color.red;Handles.DrawWireArc(scene.transform.position,scene.transform.up,-scene.transform.right,180,scene.shieldArea);scene.shieldArea =Handles.ScaleValueHandle(scene.shieldArea,scene.transform.position + scene.transform.forward * scene.shieldArea,scene.transform.rotation,1,Handles.ConeCap,1);// GUI相关的绘制需要在Handles的绘制之后,否则会被覆盖掉;// 使用Handles.BeginGUI会导致无法旋转摄像机,原因不详;GUILayout.BeginArea(new Rect(Screen.width - 100, Screen.height - 80, 90, 50));//Handles.BeginGUI(new Rect(Screen.width - 100, Screen.height - 80, 90, 50));try{float a = float.Parse(GUILayout.TextField(scene.shieldArea.ToString()));scene.shieldArea = a;}catch (System.Exception ex){}if (GUILayout.Button("Reset Area"))scene.shieldArea = 5;//Handles.EndGUI();GUILayout.EndArea();}private static void Test_ArrowCap(SceneTag scene){float arrowSize = 1;Handles.color = Color.red;Handles.ArrowCap(0,scene.transform.position + new Vector3(5, 0, 0),scene.transform.rotation,arrowSize);Handles.color = Color.green;Handles.ArrowCap(0,scene.transform.position + new Vector3(0, 5, 0),scene.transform.rotation,arrowSize);Handles.color = Color.blue;Handles.ArrowCap(0,scene.transform.position + new Vector3(0, 0, 5),scene.transform.rotation,arrowSize);}private void Test_Color(SceneTag scene){Handles.color = Color.magenta;scene.vectorPoint = Handles.Slider(scene.vectorPoint,Vector3.zero - scene.transform.position);}}

Unity的Handles类相关推荐

  1. Unity应用Handles画线,方便查看点间的路径

    今天工作碰到一个实现NPC巡逻的功能需求,需要程序实现相关逻辑,并且能够让策划自由配置NPC巡逻路径和NPC交互功能. 这里我就想记录一下我利用Unity的Handles画线的功能实现路径可视化的一种 ...

  2. Unity C#工具类 ArrayHelper

    Unity C#工具类 ArrayHelper 功能介绍 C#下传统的数组不支持Linq库,无法方便的进行查询,查找最值,批量获取等操作,利用泛型制作通用的ArrayHelper工具类,使得数组也像L ...

  3. Unity中Time类详解

    一:前言 Unity中时间类 二:常用 --Time.time 从游戏开始后所运行的时间,会受时间缩放比例的影响 --Time.unscaledTime 从游戏开始后所运行的时间,不受时间缩放比例的影 ...

  4. ML-Agents与训练达不到目的AI的斗争史-如何用unity训练一个类吸血鬼幸存者自动躲避AI(探讨,暂时非成功经验)1.0

    问题:如何用unity训练一个类吸血鬼幸存者自动躲避AI. 我的想法: 应该抓住问题的根源解决:类吸血鬼幸存者游戏的躲避的目的是使血量维持一个健康值,所以我的逻辑是对训练的AI所有奖励(AddRewa ...

  5. 详解Unity中Time类的用法与深入探究

    前言 在游戏世界中,时间无疑是最为重要的参数,它是游戏世界能否正常运转的关键.一旦它出错,轻则卡顿,重则游戏世界崩坏.在使用Unity引擎创造的世界中,Time类无疑是必须要掌握的一个类,它是控制时间 ...

  6. Unity模拟经营类游戏Demo部分代码及技术总结

    7月份自己做了一个模拟经营类的游戏Demo,在此总结UI.库存系统.交易系统.游戏循环等相关内容的代码和实现. 实现效果预览 目录 UI 库存系统 交易系统 游戏循环 UI 本项目的UI通过Unity ...

  7. Unity 之 Ping类简析尝试使用

    Ping 什么意思??? [来自百度百科的诠释:] Ping是Windows.Unix和Linux系统下的一个命令.ping也属于一个通信协议,是TCP/IP协议的一部分.利用"ping&q ...

  8. Unity基础—Transform类

    Transform类是Unity脚本编辑的一个基础且重要的类,所以我们下面一起来学习一下这个类. 一.成员变量 position:在世界空间坐标transform的位置. localPosition: ...

  9. 【Unity】 节奏类游戏的表盘卡点功能

    目录 1:前言 2:开始  ---(方案一根据音频数据自动生成节奏点) 2.1:功能实现选择---音频可视化 2.2:结论-(结果不准确) 3:游戏表盘的实现----(方案二自给自足,自动输入用时自动 ...

最新文章

  1. CLR via C#(第3版):.net中的定时器整理总结
  2. String和StringBuilder
  3. Mysql查询的一些操作(查表名,查字段名,查当月,查一周,查当天)
  4. 2.4带通采样的实际问题
  5. keil2c语言使用教程,Keil教程(2)
  6. nagios学习笔记(二)
  7. 汇编 begin_【精品】小学作文500字汇编九篇
  8. 一篇文章教会你使用Python中三种简单的函数
  9. 【OCR技术】字符识别技术总览
  10. heuristic algorithm(启发式算法)
  11. 百战程序员JavaWeb系列教程-监听器视频教程
  12. mysql分布式集群实现原理
  13. 强大的矢量绘图软件Sketch
  14. 嵌入式系统是不是计算机系统,开发必知:嵌入式系统对比计算机系统
  15. SSM和SSH框架对比
  16. (31)Java基础语法 --接口
  17. 基于Selenium实现网易云音乐的登录
  18. RequestMapping的映射URL模板
  19. Java面向对象(OOP)--面向过程 面向对象 OOP详解
  20. 大学要考的证书英语计算机,大学里必考的证书盘点 英语四六级、计算机证书上榜...

热门文章

  1. Zookeeper的领导者选举机制解析
  2. Verification和Validation傻傻分不清楚?
  3. 盒子模型基本介绍及知识点
  4. 软件相关技术及其在国内的应用
  5. 关于Tomcat黄叉的解决方案
  6. 某车联网App 通讯协议加密分析(四) Trace Code
  7. 【胖虎的逆向之路】03——Android一代壳脱壳办法罗列实操
  8. UBUNTU教程之菜鸟飞飞
  9. Vitis开发笔记:将镜像刻录到SD卡
  10. [渝粤教育] 辽宁建筑职业学院 Web服务器端应用开发 参考 资料