I need to
-
drag and drop GameObject to ObjectField.
-
drag and drop a group of GameObjects to list name.
The main problem is either do 1 or 2 work. I need the function same as unity List Inspector for future devolvement. Code as follow.
static SerializedProperty ThisList; public override void OnInspectorGUI() { ThisList = serializedObject.FindProperty("G");//List name call G serializedObject.Update(); Show(ThisList); serializedObject.ApplyModifiedProperties(); } public static void Show(SerializedProperty list) { EditorGUILayout.PropertyField(list); EditorGUI.indentLevel += 1; if (list.isExpanded) { EditorGUILayout.PropertyField(list.FindPropertyRelative("Array.size")); ShowElements(list); } EditorGUI.indentLevel -= 1; } private static GameObject[] a =new GameObject[50000]; private static void ShowElements(SerializedProperty list) { //This code can drag and drop GameObject to ObjectField. for (int i = 0; i < list.arraySize; i++) { list.GetArrayElementAtIndex(i).objectReferenceValue = EditorGUILayout.ObjectField("OBj", list.GetArrayElementAtIndex(i).objectReferenceValue, typeof(GameObject)); } //This code can drag and drop a group of GameObjects to list name. if (Event.current.type == EventType.DragUpdated) { DragAndDrop.visualMode = DragAndDropVisualMode.Copy; Event.current.Use(); } else if (Event.current.type == EventType.DragPerform) { for (int j = 0; j < DragAndDrop.objectReferences.Length; j++) { a[j] = (DragAndDrop.objectReferences[j] as GameObject); } Event.current.Use(); } }
However, it not work when both codes together.
If -> EditorGUILayout.PropertyField(list, true); I can get the same result as the unity function. but I cant Custom the List. (such as add name, change position, add button…)