Version: 5.3 (switch to 5.4b)
言語English
  • C#
  • JS

スクリプト言語

好きな言語を選択してください。選択した言語でスクリプトコードが表示されます。

Handles.DrawPolyLine

マニュアルに切り替える
public static void DrawPolyLine(params Vector3[] points);

パラメーター

説明

すべての points を通るラインを描画します。

注意: 画面サイズに対して固定サイズのハンドルを持ちたい場合、 HandleUtility.GetHandleSize を使用します。


シーンビューにあるすべてのオブジェクトを繋げるポリライン

以下の例では、シーンビューで複数のオブジェクト間に 1 本の線を描画するのに DrawPolyLine が使用されています。 この例を使用するには、以下のスクリプトを Assets/Editor フォルダーに保存します。

using UnityEngine;
using UnityEditor;

[CustomEditor( typeof( DrawConnectedLine ) )] public class DrawConnectedLineEditor : Editor { // Draw lines to the connected game objects that a script has. // if the target object doesnt have any game objects attached // then it draws a line from the Last checked object to 0,0,0

void OnSceneGUI( ) { DrawConnectedLine t = target as DrawConnectedLine;

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

Vector3[] positions = new Vector3[t.GameObjects.Length];

for( int i = 0; i < t.GameObjects.Length; i++ ) { if( t.GameObjects[i] != null ) positions[i] = t.GameObjects[i].transform.position; else positions[i] = Vector3.zero; }

Handles.DrawPolyLine( positions ); } }

以下のスクリプトをシーンのゲームオブジェクトにアタッチします。線を描画したいゲームオブジェクトをそれぞれに該当するゲームオブジェクト配列インスペクター上にドラッグアンドドロップします。

using UnityEngine;

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