verts | 世界坐标中的矩形的 4 个顶点。 |
faceColor | 矩形面的颜色。 |
outlineColor | 矩形的轮廓颜色。 |
在 3D 空间中绘制一个实心轮廓矩形。
\ 场景视图中带有黑色轮廓的实心矩形。
// Create a semi transparent rectangle that lets you modify // the "range" that resides in "SolidRectangleExample.cs" using System.Collections.Generic; using UnityEngine; using UnityEditor;
[CustomEditor(typeof(SolidRectangleExample))] public class DrawSolidRectangle : Editor { void OnSceneGUI() { SolidRectangleExample t = target as SolidRectangleExample; Vector3 pos = t.transform.position;
Vector3[] verts = new Vector3[] { new Vector3(pos.x - t.range, pos.y, pos.z - t.range), new Vector3(pos.x - t.range, pos.y, pos.z + t.range), new Vector3(pos.x + t.range, pos.y, pos.z + t.range), new Vector3(pos.x + t.range, pos.y, pos.z - t.range) };
Handles.DrawSolidRectangleWithOutline(verts, new Color(0.5f, 0.5f, 0.5f, 0.1f), new Color(0, 0, 0, 1));
foreach (Vector3 posCube in verts) { t.range = Handles.ScaleValueHandle(t.range, posCube, Quaternion.identity, 1.0f, Handles.CubeHandleCap, 1.0f); } } }
附加到此手柄的脚本:
using UnityEngine;
public class SolidRectangleExample : MonoBehaviour { public float range = 5; }