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.DrawDottedLines

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 DrawDottedLines(lineSegments: Vector3[], screenSpaceSize: float): void;
public static void DrawDottedLines(Vector3[] lineSegments, float screenSpaceSize);

Parameters

lineSegmentsA list of pairs of points that represent the start and end of line segments.
screenSpaceSizeThe size in pixels for the lengths of the line segments and the gaps between them.

Description

Draw a list of dotted line segments.

"Draw multiple dotted lines in sceneview.".

#pragma strict
// Draw lines to the connected game objects that a script has.
// if the target object doesn't have any game objects attached
// then it draws a line from the object to 0,0,0.
@CustomEditor(ConnectedLineObjects)
class ConnectDottedLineHandle extends Editor {
	var dashSize: float = 4.0f;
	function OnSceneGUI() {
		var connectedObjects: ConnectedLineObjects = target as ConnectedLineObjects;
		if (connectedObjects.objs == null || connectedObjects.objs.Length == 0)return ;
		// we store the start and end points of the line segments in this array
		var lineSegments: Vector3[] = new Vector3[connectedObjects.objs.Length * 2];
		var lastObject: int = connectedObjects.objs.Length - 1;
		var prevPoint: Vector3;
		if (connectedObjects.objs[lastObject]) {
			prevPoint = connectedObjects.objs[lastObject].transform.position;
		}
		else {
			prevPoint = Vector3.zero;
		}
		var pointIndex: int = 0;
		for (var currObjectIndex: int = 0; currObjectIndex < connectedObjects.objs.Length; currObjectIndex++) {
			// find the position of our connected object and store it
			var currPoint: Vector3;
			if (connectedObjects.objs[currObjectIndex]) {
				currPoint = connectedObjects.objs[currObjectIndex].transform.position;
			}
			else {
				currPoint = Vector3.zero;
			}
			// store the starting point of the line segment
			lineSegments[pointIndex] = prevPoint;
			pointIndex++;
			// store the ending point of the line segment
			lineSegments[pointIndex] = currPoint;
			pointIndex++;
			prevPoint = currPoint;
		}
		Handles.DrawDottedLines(lineSegments, dashSize);
	}
}
// Draw lines to the connected game objects that a script has.
// if the target object doesn't have any game objects attached
// then it draws a line from the object to 0,0,0.

using UnityEditor; using UnityEngine; using System.Collections.Generic;

[CustomEditor(typeof(ConnectedLineObjects))] class ConnectDottedLineHandle : Editor { float dashSize = 4.0f; void OnSceneGUI() { ConnectedLineObjects connectedObjects = target as ConnectedLineObjects; if (connectedObjects.objs == null || connectedObjects.objs.Length == 0) return; // we store the start and end points of the line segments in this array Vector3[] lineSegments = new Vector3[connectedObjects.objs.Length * 2];

int lastObject = connectedObjects.objs.Length - 1; Vector3 prevPoint; if (connectedObjects.objs[lastObject]) { prevPoint = connectedObjects.objs[lastObject].transform.position; } else { prevPoint = Vector3.zero; } int pointIndex = 0; for (int currObjectIndex = 0; currObjectIndex < connectedObjects.objs.Length; currObjectIndex++) { // find the position of our connected object and store it Vector3 currPoint; if (connectedObjects.objs[currObjectIndex]) { currPoint = connectedObjects.objs[currObjectIndex].transform.position; } else { currPoint = Vector3.zero; }

// store the starting point of the line segment lineSegments[pointIndex] = prevPoint; pointIndex++;

// store the ending point of the line segment lineSegments[pointIndex] = currPoint; pointIndex++;

prevPoint = currPoint; } Handles.DrawDottedLines(lineSegments, dashSize); } }

And the script attached to this Handle:

//ConnectedObjects.js

public var objs: GameObject[] = null;
using UnityEngine;
using System.Collections;

public class ConnectedLineObjects : MonoBehaviour { public GameObject[] objs = null; }

public static method DrawDottedLines(points: Vector3[], segmentIndices: int[], screenSpaceSize: float): void;
public static void DrawDottedLines(Vector3[] points, int[] segmentIndices, float screenSpaceSize);

Parameters

pointsA list of points.
segmentIndicesA list of pairs of indices to the start and end points of the line segments.
screenSpaceSizeThe size in pixels for the lengths of the line segments and the gaps between them.

Description

Draw a list of indexed dotted line segments.

#pragma strict
// Draw lines to the connected game objects that a script has.
// If the target object doesn't have any game objects attached
// then it draws a line from the object to (0, 0, 0).
@CustomEditor(ConnectedLinesObjects)
class ConnectDottedLinesHandle extends Editor {
	var dashSize: float = 4.0f;
	function OnSceneGUI() {
		var connectedObjects: ConnectedLinesObjects = target as ConnectedLinesObjects;
		if (connectedObjects.objs == null || connectedObjects.objs.Length == 0)return ;
		// we store the points of the line segments in this array
		var points: Vector3[] = new Vector3[connectedObjects.objs.Length];
		// the index to the start and the end point
		var segmentIndices: int[] = new int[connectedObjects.objs.Length * 2];
		// create the points and line segments indices
		var prevIndex: int = connectedObjects.objs.Length - 1;
		var pointIndex: int = 0;
		var segmentIndex: int = 0;
		for (var currIndex: int = 0; currIndex < connectedObjects.objs.Length; currIndex++) {
			// find the position of our connected object and store it
			if (connectedObjects.objs[pointIndex]) {
				points[pointIndex] = connectedObjects.objs[currIndex].transform.position;
			}
			else {
				points[pointIndex] = Vector3.zero;
			}
			// the index to the start of the line segment
			segmentIndices[segmentIndex] = prevIndex;
			segmentIndex++;
			// the index to the end of the line segment
			segmentIndices[segmentIndex] = pointIndex;
			segmentIndex++;
			pointIndex++;
			prevIndex = currIndex;
		}
		Handles.DrawDottedLines(points, segmentIndices, dashSize);
	}
}
// Draw lines to the connected game objects that a script has.
// If the target object doesn't have any game objects attached
// then it draws a line from the object to (0, 0, 0).

using UnityEditor; using UnityEngine; using System.Collections.Generic;

[CustomEditor(typeof(ConnectedLinesObjects))] class ConnectDottedLinesHandle : Editor { float dashSize = 4.0f; void OnSceneGUI() { ConnectedLinesObjects connectedObjects = target as ConnectedLinesObjects; if (connectedObjects.objs == null || connectedObjects.objs.Length == 0) return;

// we store the points of the line segments in this array Vector3[] points = new Vector3[connectedObjects.objs.Length];

// for each line segment we need two indices into the points array: // the index to the start and the end point int[] segmentIndices = new int[connectedObjects.objs.Length * 2];

// create the points and line segments indices int prevIndex = connectedObjects.objs.Length - 1; int pointIndex = 0; int segmentIndex = 0; for (int currIndex = 0; currIndex < connectedObjects.objs.Length; currIndex++) { // find the position of our connected object and store it if (connectedObjects.objs[pointIndex]) { points[pointIndex] = connectedObjects.objs[currIndex].transform.position; } else { points[pointIndex] = Vector3.zero; }

// the index to the start of the line segment segmentIndices[segmentIndex] = prevIndex; segmentIndex++;

// the index to the end of the line segment segmentIndices[segmentIndex] = pointIndex; segmentIndex++;

pointIndex++; prevIndex = currIndex; } Handles.DrawDottedLines(points, segmentIndices, dashSize); } }

And the script attached to this Handle:

//ConnectedObjects.js

public var objs: GameObject[] = null;
using UnityEngine;
using System.Collections;

public class ConnectedLinesObjects : MonoBehaviour { public GameObject[] objs = null; }

Did you find this page useful? Please give it a rating: