usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;usingUnityEditor;usingSirenix.OdinInspector;usingSirenix.Utilities.Editor;publicclassDemo:SerializedMonoBehaviour{ [ListDrawerSettings(HideAddButton = true, OnTitleBarGUI = "RenderAddButton")]publicList<DemoElement>DemoList; [System.NonSerialized]privateint_controlID; [System.NonSerialized]privatebool_pickerActive=false;// Custom List add button that opens object pickervoidRenderAddButton(){if(SirenixEditorGUI.ToolbarButton(EditorIcons.Checkmark)){_controlID=GUIUtility.GetControlID(FocusType.Passive);_pickerActive=true;EditorGUIUtility.ShowObjectPicker<Material>(null,false,"",_controlID);}}// Handle if we have the picked object [OnInspectorGUI, PropertyOrder(int.MaxValue)]voidHandlePickedObject(){if(HavePickedObject()){Materialmat=EditorGUIUtility.GetObjectPickerObject()asMaterial;if(mat==null)Debug.Log("INVALID OBJECT");else{Debug.Log("VALID OBJECT!");DemoList.Add(newDemoElement(mat));}}}// Check if we have a valid item from the object pickerboolHavePickedObject(){if(Event.current.commandName!="ObjectSelectorClosed")returnfalse;if(EditorGUIUtility.GetObjectPickerControlID()!=_controlID)returnfalse;if(!_pickerActive)returnfalse;_pickerActive=false;returntrue;} [System.Serializable]publicclassDemoElement{publicDemoElement(Materialmat){Mat=mat;} [HorizontalGroup, HideLabel, DisplayAsString]publicstringData="Some Other Data"; [HorizontalGroup, HideLabel]publicMaterialMat;}}
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.