When viewing a gameObject in the inspector view that has a MeshRenderer, you’re able to lock the inspector, select multiple Materials from the project view, and drag them all into the materials slot and they will all populate the list instead of having to populate them one at a time.
I’m wondering if it’s possible to do this in a custom editor window?
I’m able to show and populate a list of materials one-at-a-time currently with the following code:
public class MultiMaterialSelectorExample : EditorWindow
{
[SerializeField]
List<Material> materials;
[MenuItem("Window/UI Toolkit/MultiMaterialSelectorExample")]
public static void ShowExample()
{
MultiMaterialSelectorExample wnd = GetWindow<MultiMaterialSelectorExample>();
wnd.materials = new();
wnd.titleContent = new GUIContent("MultiMaterialSelectorExample");
}
public void CreateGUI()
{
// Each editor window contains a root VisualElement object
VisualElement root = rootVisualElement;
// Import UXML
var visualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/_Internal/Tools/Editor/MultiMaterialSelectorExample.uxml");
VisualElement uxmlTree = visualTree.Instantiate();
root.Add(uxmlTree);
var materialPropField = uxmlTree.Q(name: "materials-prop") as PropertyField;
// Where I'm binding the property list:
SerializedObject serializedObj = new(this);
SerializedProperty prop = serializedObj.FindProperty("materials");
materialPropField.BindProperty(prop);
materialPropField.Bind(serializedObj);
}
}
I’ve used a semi-hacky approach to avoid having to write a ListView from scratch, but is there any native functionality that would allow me to get this working with a PropertyField/ListView, or will I need to do some trickery where I hide an ObjectField over the list label and then populate the list with the dragged elements?