Make a custom editor for obj
or objects
.
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 (); } } }
//WaypointPath.js // This is not an editor script. var wayPointArray : Transform[];