パスツール

覚書。
いわゆるAIや自走オブジェクトを誘導するためのパスを生成するツール。エディタで楽できないかなーと思ったらできた。具体的には、始めのパスを一つ置いて、MakeChildボタンを押すとそのパスを親に持ったパスが複製+リネームされ配置される。あとは置きまくるだけ。
使い方は、CoursePathというmParentのListを持ったスクリプトを作り、あとは以下のスクリプトが書かれたファイルをAsset/Editorにぶち込む。

[CustomEditor(typeof(CoursePath))]
public sealed class CoursePathEditor : Editor
{
	public override void OnInspectorGUI()
	{
		base.OnInspectorGUI();
		if ( GUILayout.Button("Make Child", EditorStyles.miniButton ) )
		{
			GameObject parent = Selection.gameObjects[0];    // 現在のオブジェクト取得
			GameObject child = Instantiate( parent ) as GameObject;    // 複製
			if ( !child ) return;
			CoursePath path = child.GetComponent<CoursePath>();
			if ( path )
			{
				path.mParent.Clear();	
				path.mParent.Add( parent );    // 親に現在のオブジェクトを挿入
			}
			child.name = string.Format( "Path{0:000}", int.Parse( parent.name.Substring(4) ) + 1 );    // リネーム
			child.transform.parent = GameObject.Find("CoursePath").transform;	// CoursePathオブジェクトにぶら下げる
			Selection.activeGameObject = child;    // 新しいオブジェクトを選択

			Debug.Log("[CoursePath] Created new path named '" + child.name + "'.");
		}
	}
}


Undoはない。
もうちょっと機能拡張したらAssetStoreででも売り出すとかもアリかも(むしろ誰かが作ったものを使いたかった……)