言語: 日本語
  • C#
  • JS
  • Boo

スクリプト言語

お好みのスクリプト言語を選択すると、サンプルコードがその言語で表示されます。

Editor.CreateEditor

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

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static function CreateEditor(objects: Object[], editorType: Type = null): Editor;
public static Editor CreateEditor(Object[] objects, Type editorType = null);
public static def CreateEditor(objects as Object[], editorType as Type = null) as Editor

Description

objects または複数の objects のためのカスタムエディタを作成します

デフォルトでは CustomEditor が一致する適切なエディタが選択されます。 もし editorType が指定された場合、その型のエディタが代わりに作成されます。 オブジェクトに対してカスタムエディタが定義されてない場合は null を返します。 wayPoint 配列の複数の Transform を編集するには WaypointPathEditor スクリプトを検討して下さい。

import System.Linq;

@CustomEditor (WaypointPath)
class WaypointPathEditor extends Editor {
	
	var currentTransformEditor;
	var waypoints : Transform[];
	var selectedTransform :Transform;
	var optionsList : String[];
	var index = 0;
	var myWayPath : WaypointPath; 

	function GetWaypoints () {
		var myWayPath = target as WaypointPath;
		
		// Gets only the valid objects from WaypointPath
		if (myWayPath.wayPointArray != null) {
			waypoints = myWayPath.wayPointArray.Where (function(obj) { return obj != null; }).ToArray ();
			optionsList = waypoints.Select (function(obj, index){index.ToString () + ". " + obj.name;}).ToArray ();	
		}	
	}
	
	function OnInspectorGUI () {
		GetWaypoints ();
		DrawDefaultInspector ();
		EditorGUILayout.Space ();
		EditorGUI.BeginChangeCheck ();
		
		if (optionsList != null)
			index = EditorGUILayout.Popup ("Select Waypoint", index, optionsList);
		
		if (EditorGUI.EndChangeCheck ()) {
			var tmpEditor;
			if (index < waypoints.Length) {
				selectedTransform = waypoints[index];

				//Creates an Editor for selected Component from a Popup
				tmpEditor = Editor.CreateEditor (selectedTransform);
			} else {
				selectedTransform = null;
			}
			
			// If there isn't a Transform currently selected then destroy the existing editor
			if (currentTransformEditor != null) {
				DestroyImmediate (currentTransformEditor);
			}
			
			currentTransformEditor = tmpEditor;
		}

		//Shows the created Editor beneath CustomEditor
		if (currentTransformEditor != null && selectedTransform != null) {
			currentTransformEditor.OnInspectorGUI ();
		}
	}
}

そしてスクリプトは waypath ゲームオブェクトにアタッチされてます:

//WaypointPath.js
// This is not an editor script.
var wayPointArray : Transform[];