Version: 2022.3

Handles.DrawWireArc

切换到手册
public static void DrawWireArc (Vector3 center, Vector3 normal, Vector3 from, float angle, float radius, float thickness= 0.0f);

参数

center The center of the circle in world space.
normal The normal of the circle in world space.
from 圆周上的点相对于圆心的方向,即圆弧的起点。
angle 圆弧的角度(以度为单位)。
radius The radius of the circle in world space units.
thickness Line thickness in UI points (zero thickness draws single-pixel line).

描述

Draws a circular arc in 3D space.

The Handles.color and Handles.matrix properties colorize and additionally transform the arc position. Unity ignores DrawWireArc (that is, nothing happens) when the current GUI event type is not Repaint.

\ 场景视图中的线弧。

using UnityEditor;
using UnityEngine;
using System.Collections;

//this class should exist somewhere in your project public class WireArcExample : MonoBehaviour { public float shieldArea; }

// Create a 180 degrees wire arc with a ScaleValueHandle attached to the disc // that lets you modify the "shieldArea" value in the WireArcExample [CustomEditor(typeof(WireArcExample))] public class DrawWireArc : Editor { void OnSceneGUI() { Handles.color = Color.red; WireArcExample myObj = (WireArcExample)target; Handles.DrawWireArc(myObj.transform.position, myObj.transform.up, -myObj.transform.right, 180, myObj.shieldArea); myObj.shieldArea = (float)Handles.ScaleValueHandle(myObj.shieldArea, myObj.transform.position + myObj.transform.forward * myObj.shieldArea, myObj.transform.rotation, 1, Handles.ConeHandleCap, 1); } }

You can use HandleUtility.GetHandleSize to calculate a suitable size for a manipulator handle.

Arc line thickness can be optionally set. Zero thickness draws a one-pixel line. Larger thickness values express line thickness in UI points. For example, a thickness of 1.0 could be two pixels wide on screen if the display zoom is 200% (see EditorGUIUtility.pixelsPerPoint).


Arcs of varying thickness.

using UnityEngine;
using UnityEditor;

public class ExampleScript : MonoBehaviour { }

// Display arcs of various angles and thickness in the scene view [CustomEditor(typeof(ExampleScript))] public class ExampleEditor : Editor { public void OnSceneGUI() { var t = target as ExampleScript; var tr = t.transform; var position = tr.position; Handles.color = Color.yellow; for (int i = 0; i < 10; ++i) { var center = position; var start = Vector3.left; var normal = Vector3.forward; var radius = 3 - i * 0.3f; var angle = 40 + 30 * i; Handles.DrawWireArc(center, normal, start, angle, radius, i); } } }