Version: 5.3 (switch to 5.4b)
IdiomaEnglish
  • C#
  • JS

Idioma de script

Selecciona tu lenguaje de programación favorito. Todos los fragmentos de código serán mostrados en este lenguaje.

Editor.CreateEditor

Sugiere un cambio

¡Éxito!

Gracias por ayudarnos a mejorar la calidad de la documentación de Unity. A pesar de que no podemos aceptar todas las sugerencias, leemos cada cambio propuesto por nuestros usuarios y actualizaremos los que sean aplicables.

Cerrar

No se puedo enviar

Por alguna razón su cambio sugerido no pudo ser enviado. Por favor <a>intente nuevamente</a> en unos minutos. Gracias por tomarse un tiempo para ayudarnos a mejorar la calidad de la documentación de Unity.

Cerrar

Cancelar

Cambiar al Manual
public static function CreateEditor(targetObject: Object, editorType: Type = null): Editor;
public static Editor CreateEditor(Object targetObject, Type editorType = null);
public static function CreateEditor(targetObject: Object, editorType: Type = null): Editor;
public static Editor CreateEditor(Object targetObject, Type editorType = null);
public static function CreateEditor(targetObjects: Object[], editorType: Type = null): Editor;
public static Editor CreateEditor(Object[] targetObjects, Type editorType = null);
public static function CreateEditor(targetObjects: Object[], editorType: Type = null): Editor;
public static Editor CreateEditor(Object[] targetObjects, Type editorType = null);

Parámetros

objects All objects must be of same exact type.

Descripción

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.


        
using UnityEditor;
using UnityEngine;
using System.Collections;

[CustomEditor(typeof(WaypointPath))] public class WaypointPathEditor : Editor { Editor currentTransformEditor; Transform[] waypoints; Transform selectedTransform; string[] optionsList; int index = 0; WaypointPath myWayPath; void GetWaypoints() { myWayPath = target as WaypointPath;

if (myWayPath.wayPointArray != null) { optionsList = new string[myWayPath.wayPointArray.Length];

for (int i = 0; i < optionsList.Length; i++) { optionsList[i] = myWayPath.wayPointArray[i].name; } } } public override void OnInspectorGUI () { GetWaypoints (); DrawDefaultInspector (); EditorGUILayout.Space (); EditorGUI.BeginChangeCheck (); if (optionsList != null) index = EditorGUILayout.Popup ("Select Waypoint", index, optionsList); if (EditorGUI.EndChangeCheck ()) { Editor tmpEditor = null;

if (index < myWayPath.wayPointArray.Length) { selectedTransform = myWayPath.wayPointArray[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:


        
using UnityEngine;
using System.Collections;

// Note: this is not an editor script. public class WaypointPath : MonoBehaviour { public Transform[] wayPointArray; }