Legacy Documentation: Version 5.0
Language: English
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

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

Switch to Manual
public static function CreateEditor(targetObject: Object, editorType: iOS.ADBannerView.Type = null): Editor;
public static Editor CreateEditor(Object targetObject, iOS.ADBannerView.Type editorType = null);
public static function CreateEditor(targetObjects: Object[], editorType: iOS.ADBannerView.Type = null): Editor;
public static Editor CreateEditor(Object[] targetObjects, iOS.ADBannerView.Type editorType = null);

Parameters

objectsAll objects must be of same exact type.

Description

Make a custom editor for targetObject or targetObjects.

By default an appropriate editor is chosen that has a matching CustomEditor attribute. If an editorType is specified, an editor of that type is created instead. Use this if you have created multiple custom editors where each editor shows different properties of the object. Returns NULL if objects are of different types or if no approprate editor was found.

Consider a script WaypointPathEditor for editing the Transforms of a wayPoint array.

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 (); } } }

And the script attached to a waypath GameObject:

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