Version: 5.3 (switch to 5.4b)
IdiomaEnglish
  • C#
  • JS

Idioma de script

Selecciona tu lenguaje de programación favorito. Todos los fragmentos de código serán mostrados en este lenguaje.

Handles.DrawLines

Sugiere un cambio

¡Éxito!

Gracias por ayudarnos a mejorar la calidad de la documentación de Unity. A pesar de que no podemos aceptar todas las sugerencias, leemos cada cambio propuesto por nuestros usuarios y actualizaremos los que sean aplicables.

Cerrar

No se puedo enviar

Por alguna razón su cambio sugerido no pudo ser enviado. Por favor <a>intente nuevamente</a> en unos minutos. Gracias por tomarse un tiempo para ayudarnos a mejorar la calidad de la documentación de Unity.

Cerrar

Cancelar

Cambiar al Manual
public static function DrawLines(lineSegments: Vector3[]): void;
public static void DrawLines(Vector3[] lineSegments);

Parámetros

lineSegments A list of pairs of points that represent the start and end of line segments.

Descripción

Draw a list of line segments.

"Draw multiple lines in sceneview.".

The following example uses DrawLines to draw a line between objects defined in a list. To use this example, save the following script into the Assets/Editor folder:


        
using UnityEngine;
using UnityEditor;

[CustomEditor( typeof( DrawLines ) )] public class DrawLinesEditor : Editor { void OnSceneGUI( ) { DrawLines t = target as DrawLines;

if( t == null || t.GameObjects == null ) return;

Vector3[] lineSegments = new Vector3[t.GameObjects.Length * 2]; int pointIndex = 0;

for( int i = 0; i < t.GameObjects.Length - 1; i++ ) { if( t.GameObjects[i] != null && t.GameObjects[i+1] != null ) { lineSegments[pointIndex++] = t.GameObjects[i].transform.position; lineSegments[pointIndex++] = t.GameObjects[i+1].transform.position; } }

Handles.DrawLines( lineSegments ); } }

...then attach this script to the anchor object which you would like to see lines eminate from. Drop GameObjects you would like lines drawing to into the array in the script's inspector, and adjust the gap between the dotted lines accordingly:


        
using UnityEngine;

[ExecuteInEditMode] public class DrawLines : MonoBehaviour { public GameObject[] GameObjects; }

public static function DrawLines(points: Vector3[], segmentIndices: int[]): void;
public static void DrawLines(Vector3[] points, int[] segmentIndices);

Parámetros

points A list of points.
segmentIndices A list of pairs of indices to the start and end points of the line segments.

Descripción

Draw a list of indexed line segments.

The following example uses DrawDottedLines to draw a line between objects defined in a list. To use this example, save the following script into the Assets/Editor folder:


        
using UnityEngine;
using UnityEditor;

[CustomEditor( typeof( DrawLinesUsingPoints ) )] public class DrawLinesUsingPointsEditor : Editor { void OnSceneGUI( ) { DrawLinesUsingPoints t = target as DrawLinesUsingPoints;

if( t == null || t.GameObjects == null ) return;

Vector3[] points = new Vector3[t.GameObjects.Length]; int[] segmentIndices = new int[t.GameObjects.Length * 2]; int pointsIndex = 0;

for( int i = 0; i < t.GameObjects.Length; i++ ) { if( t.GameObjects[i] != null ) points[pointsIndex++] = t.GameObjects[i].transform.position; }

for( int i = 0; i < pointsIndex - 1; i++ ) { int segmentIndex = i * 2;

segmentIndices[segmentIndex] = i; segmentIndices[segmentIndex+1] = i+1; }

Handles.DrawLines(points, segmentIndices ); } }

...then attach this script to the anchor object which you would like to see lines eminate from. Drop GameObjects you would like lines drawing to into the array in the script's inspector, and adjust the gap between the dotted lines accordingly:


        
using UnityEngine;

[ExecuteInEditMode] public class DrawLinesUsingPoints : MonoBehaviour { public GameObject[] GameObjects; }