- Home /
EditorGUILayout.ObjectField for Array
How can I emulate the native Inspector behaviour associated with public arrays?
Particularly I'm interested in enabling the drag and drop of multiple objects (multiple selection) into the array controller.
Thanks
Comment
I also need exactly the same thing. I hope someone answers. $$anonymous$$y case is to be able to connect a Tranform[] or List to an object field.
Answer by ForceMagic · May 25, 2016 at 04:50 PM
I've seen this code, might be helpful if someone end up here as I did (even after 4 years)
https://gist.github.com/bzgeb/3800350
using UnityEngine;
using System.Collections;
using UnityEditor;
[CustomEditor (typeof(TriggerContainer))]
public class TriggerContainerEditor : Editor
{
private SerializedObject obj;
public void OnEnable ()
{
obj = new SerializedObject (target);
}
public override void OnInspectorGUI ()
{
DrawDefaultInspector ();
EditorGUILayout.Space ();
DropAreaGUI ();
}
public void DropAreaGUI ()
{
Event evt = Event.current;
Rect drop_area = GUILayoutUtility.GetRect (0.0f, 50.0f, GUILayout.ExpandWidth (true));
GUI.Box (drop_area, "Add Trigger");
switch (evt.type) {
case EventType.DragUpdated:
case EventType.DragPerform:
if (!drop_area.Contains (evt.mousePosition))
return;
DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
if (evt.type == EventType.DragPerform) {
DragAndDrop.AcceptDrag ();
foreach (Object dragged_object in DragAndDrop.objectReferences) {
// Do On Drag Stuff here
}
}
break;
}
}
}