// DrawListItem for ReorderableList protected void DrawListItem(EditorReorderableList <UnityEngine.Object> list, UnityEngine.Object item) { UnityEngine.Object unityItem = item; if (item is ShelfSceneReference) { unityItem = (item as ShelfSceneReference).Resolve(); } var originalColor = GUI.color; GUI.color = (unityItem != null ? originalColor : new Color(1.0f, 1.0f, 1.0f, 0.5f)); var originalBackground = GUI.backgroundColor; if (list.IsSelected(item)) { GUI.backgroundColor = new Color(0.8f, 0.8f, 0.8f, 1f); } var mainRect = EditorGUILayout.BeginHorizontal(GUI.skin.box); { GUILayout.Label(ListItemContent(list, item), GUILayout.ExpandWidth(true), GUILayout.Height(SHELF_ITEM_HEIGHT)); // Add component to game object for mono scripts if (item is MonoScript && Selection.activeGameObject != null && GUILayout.Button("a", "label", GUILayout.Width(10))) { var comp = Selection.activeGameObject.AddComponent((item as MonoScript).GetClass()); // RegisterCreatedObjectUndo only works for non-persistent objects (?!) if (!EditorUtility.IsPersistent(comp)) { Undo.RegisterCreatedObjectUndo(comp, "Add Component"); } // Instantiate prefabs } else if (item is GameObject && EditorUtility.IsPersistent(item) && GUILayout.Button("n", GUILayout.Width(20))) { TextEditor textEditor = new TextEditor(); textEditor.text = item.name; textEditor.OnFocus(); textEditor.Copy(); } if (GUILayout.Button("x", GUILayout.Width(20))) { list.HandleListItemRemove(item); } } EditorGUILayout.EndHorizontal(); GUI.color = originalColor; GUI.backgroundColor = originalBackground; list.HandleListItemClick(mainRect, item); }
// Default delegate for drawing list items protected static void DrawListItem(EditorReorderableList <T> list, T item) { var originalBackground = GUI.backgroundColor; if (list.Selection.Contains(item)) { GUI.backgroundColor = new Color(0.8f, 0.8f, 0.8f, 1f); } EditorGUILayout.BeginHorizontal(GUI.skin.box); GUILayout.Label(list.listItemContentCallback(list, item), GUILayout.ExpandWidth(true)); if (GUILayout.Button("x", GUIStyle.none, GUILayout.Width(10))) { list.HandleListItemRemove(item); } EditorGUILayout.EndHorizontal(); GUI.backgroundColor = originalBackground; list.HandleListItemClick(GUILayoutUtility.GetLastRect(), item); }