Legacy Documentation: Version 2018.1 (Go to current version)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Handles.DrawSolidRectangleWithOutline

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static method DrawSolidRectangleWithOutline(verts: Vector3[], faceColor: Color, outlineColor: Color): void;
public static void DrawSolidRectangleWithOutline(Vector3[] verts, Color faceColor, Color outlineColor);

Parameters

vertsThe 4 vertices of the rectangle in world coordinates.
faceColorThe color of the rectangle's face.
outlineColorThe outline color of the rectangle.

Description

Draw a solid outlined rectangle in 3D space.


Solid rectangle with a black outline in the Scene View.

// Create a semi transparent rectangle that lets you modify
// the "range" var that resides in "SolidRectangleExample.js"

@CustomEditor (SolidRectangleExample) class DrawSolidRectangle extends Editor { function OnSceneGUI () { var pos : Vector3 = target.transform.position;

var verts : Vector3[] = [Vector3(pos.x - target.range,pos.y,pos.z-target.range), Vector3(pos.x-target.range,pos.y,pos.z + target.range), Vector3(pos.x+target.range,pos.y,pos.z + target.range), Vector3(pos.x+target.range,pos.y,pos.z-target.range)]; Handles.DrawSolidRectangleWithOutline(verts, Color(1,1,1,0.2), Color(0,0,0,1));

for(var posCube : Vector3 in verts) target.range = Handles.ScaleValueHandle(target.range, posCube, Quaternion.identity, 1, Handles.CubeCap, 1); } }
// 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); } } }

And the script attached to this Handle:

//SolidRectangleExample.js

var range : float = 5;
using UnityEngine;

public class SolidRectangleExample : MonoBehaviour { public float range = 5; }
对文档有任何疑问,请移步至开发者社区提问,我们将尽快为您解答