/************************************************************************************************************************/ private static int CheckCommand <T>(ref T selected) { var id = GUIUtility.GetControlID(FocusType.Passive); ObjectPickerWindow.TryGetPickedObject(id, ref selected); return(id); }
/************************************************************************************************************************/ /// <summary>Draws a field (using GUILayout) which lets you pick an object from a list and returns the selected object.</summary> public static T DrawLayout <T>(T selected, Func <List <T> > getOptions, int suggestions, Func <T, GUIContent> getLabel, Func <T> getDragAndDrop, GUIStyle style, params GUILayoutOption[] layoutOptions) { var id = CheckCommand(ref selected); if (GUILayout.Button(getLabel(selected), style, layoutOptions)) { ObjectPickerWindow.Show(id, selected, getOptions(), suggestions, getLabel); } CheckDragAndDrop(GUILayoutUtility.GetLastRect(), ref selected, getOptions, getDragAndDrop); return(selected); }
/************************************************************************************************************************/ #region Main Drawing Methods /************************************************************************************************************************/ /// <summary>Draws a field which lets you pick an object from a list and returns the selected object.</summary> public static T Draw <T>(Rect area, T selected, Func <List <T> > getOptions, int suggestions, Func <T, GUIContent> getLabel, Func <T> getDragAndDrop, GUIStyle style) { var id = CheckCommand(ref selected); if (GUI.Button(area, getLabel(selected), style)) { ObjectPickerWindow.Show(id, selected, getOptions(), suggestions, getLabel); } CheckDragAndDrop(area, ref selected, getOptions, getDragAndDrop); return(selected); }