Unity的Handles类

更新时间:2023-06-04 12:55:34 阅读: 评论:0

Unity的Handles类
Handles就是在SceneView⾥画⼀些能响应⽤户操作的⼏何图案,并影响指定的变量数值。
Handles类的接⼝⼤致分为以下⼏种
1. Draw:绘制元⼏何体,如点、线、⾯等
DrawAAPolyLine Draw anti-aliad 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-aliad effect u 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 ctor (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 tho ud 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 lection 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 ttings.
ClearCamera Clears the camera.
SnapValue Rounds the value val to the clost multiple of snap (snap can only be posiive)
测试代码
using UnityEngine;
using System.Collections;
public class SceneTag : MonoBehaviour
{
public Vector3 vectorPoint = ;
public Vector3 vectorPoint2 = ;
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 mouPosition = uPosition;
StringBuilder sb =new StringBuilder();
sb.AppendFormat("({0},{1})"
, mouPosition.x
, mouPosition.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,
<,
Handles.ArrowCap);
}
private static void Test_FreeRotateHandle(SceneTag scene)
{
private static void Test_ScaleValueHandle(SceneTag scene)
{
scene.shieldArea
= Handles.ScaleValueHandle(scene.shieldArea,
1,
Handles.ConeCap,
1);
}
private static void Test_DrawSolidArc(SceneTag scene)
{
Handles.ansform.position,
-ansform.right,
270,
scene.shieldArea);
scene.shieldArea =
Handles.ScaleValueHandle(scene.shieldArea,
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]+= ansform.position;
}
Handles.DrawAAPolyLine(positions);
}
private static void Test_ChangeValue(SceneTag scene)
{
< =
Handles.,
new Vector3(1,1,0),
5,
fal,
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.CircleCap(0,
circleSize);
Handles.CircleCap(0,
circleSize);
Handles.CircleCap(0,
circleSize);
Vector3 newpos = ansform.position +new Vector3(5,0,0);  circleSize = HandleUtility.GetHandleSize(newpos);
Handles.CircleCap(0,
newpos,
circleSize);
newpos = ansform.position +new Vector3(0,5,0);
circleSize = HandleUtility.GetHandleSize(newpos);毛丰美
Handles.CircleCap(0,
newpos,
6寸手机
circleSize);
newpos = ansform.position +new Vector3(0,0,5);
circleSize = HandleUtility.GetHandleSize(newpos);
Handles.CircleCap(0,
newpos,
circleSize);
}
// 3D按钮还会因为视⾓问题呈现不⼀样的⼤⼩。;
// ⽽且按钮的当前状态也更新不及时,逗么?;
private static void Test_Button(SceneTag scene)
{
Handles.ansform.position +new Vector3(0,2,0),        Quaternion.identity,
3,
3,
Handles.RectangleCap);
}
private static void Test_BeginGUI(SceneTag scene)
{
Handles.ansform.position + Vector3.up *2,
scene.shieldArea.ToString());
Handles.ansform.position,
-ansform.right,
180,
scene.shieldArea);
scene.shieldArea =
Handles.ScaleValueHandle(scene.shieldArea,
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.Par(GUILayout.TextField(scene.shieldArea.ToString()));
平缓的反义词scene.shieldArea = a;
}
catch(System.Exception ex)
{
}
if(GUILayout.Button("Ret Area"))
scene.shieldArea =5;
//Handles.EndGUI();
GUILayout.EndArea();
}
private static void Test_ArrowCap(SceneTag scene)
{
float arrowSize =1;
Handles.ArrowCap(0,
arrowSize);
Handles.ArrowCap(0,
arrowSize);
Handles.ArrowCap(0,
arrowSize);
}
private void Test_Color(SceneTag scene)
{
scene.vectorPoint = Handles.Slider(scene.vectorPoint,
< - ansform.position);
}
}

本文发布于:2023-06-04 12:55:34,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/985497.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:操作   对象   旋转   绘制
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图