verts | 矩形で使用するワールド座標の 4 つの頂点 |
faceColor | 矩形の面の色 |
outlineColor | 矩形のアウトラインの色 |
3D 空間に太い実線の矩形を描画します。
Solid rectangle with a black outline in the Scene View.
この例を使用するには、以下のスクリプトを Assets/Editor フォルダーに保存します。
using UnityEngine; using UnityEditor;
[CustomEditor(typeof(DrawSolidRect))] public class DrawSolidRectEditor : Editor { void OnSceneGUI() { DrawSolidRect t = target as DrawSolidRect;
Handles.color = Color.blue; Handles.Label(t.transform.position + Vector3.up * 2, t.transform.position.ToString() + "\nRange: " + t.range.ToString());
Handles.BeginGUI(); GUILayout.BeginArea(new Rect(Screen.width - 100, Screen.height - 80, 90, 50));
if (GUILayout.Button("Reset Range")) t.range = 5;
GUILayout.EndArea(); Handles.EndGUI();
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(1, 1, 1, 0.2f), new Color(0, 0, 0, 1)); Handles.color = Color.white;
foreach (Vector3 posCube in verts) t.range = Handles.ScaleValueHandle(t.range, posCube, Quaternion.identity, 1, Handles.CubeCap, 1); } }
このスクリプトを実線の矩形を表示したいオブジェクトに置きます。
using UnityEngine;
[ExecuteInEditMode] public class DrawSolidRect : MonoBehaviour { public float range = 5; }