lineSegments | 線分の開始と終了を示す 1 組になった点の配列 |
含まれる線分を描画します。
"Draw multiple lines in sceneview.".
// 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(ConnectedObjects))] class ConnectLineHandle : Editor { void OnSceneGUI() { ConnectedObjects connectedObjects = target as ConnectedObjects; 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.DrawLines(lineSegments); } }
このハンドルにアタッチしているスクリプト
using UnityEngine; using System.Collections;
public class ConnectedObjects : MonoBehaviour { public GameObject[] objs = null; }
points | ポイントのリスト |
segmentIndices | 線分の開始と終了を示す 1 組になった点のインデックスの配列 |
リストにあるインデックス化された線分を描画します。
// 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(ConnectedLinePointsObjects))] class ConnectLinePointsHandle : Editor { void OnSceneGUI() { ConnectedLinePointsObjects connectedObjects = target as ConnectedLinePointsObjects; 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.DrawLines(points, segmentIndices); } }
このハンドルにアタッチしているスクリプト
using UnityEngine;
using System.Collections; public class ConnectedLinePointsObjects : MonoBehaviour { public GameObject[] objs = null; }
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.