Namespace: | Sirenix.OdinInspector.Editor |
Assembly: | Sirenix.OdinInspector.Editor |
public abstract class OdinSelector<T> : ISelectionChangeListener
public class MySelector : OdinSelector<SomeType>
{
private readonly List<SomeType> source;
private readonly bool supportsMultiSelect;
public MySelector(List<SomeType> source, bool supportsMultiSelect)
{
this.source = source;
this.supportsMultiSelect = supportsMultiSelect;
}
protected override void BuildSelectionTree(OdinMenuTree tree)
{
tree.Config.DrawSearchToolbar = true;
tree.Selection.SupportsMultiSelect = this.supportsMultiSelect;
tree.Add("Defaults/None", null);
tree.Add("Defaults/A", new SomeType());
tree.Add("Defaults/B", new SomeType());
tree.AddRange(this.source, x => x.Path, x => x.SomeTexture);
}
[OnInspectorGUI]
private void DrawInfoAboutSelectedItem()
{
SomeType selected = this.GetCurrentSelection().FirstOrDefault();
if (selected != null)
{
GUILayout.Label("Name: " + selected.Name);
GUILayout.Label("Data: " + selected.Data);
}
}
}
Usage:
void OnGUI()
{
if (GUILayout.Button("Open My Selector"))
{
List<SomeType> source = this.GetListOfThingsToSelectFrom();
MySelector selector = new MySelector(source, false);
selector.SetSelection(this.someValue);
selector.SelectionCancelled += () => { }; // Occurs when the popup window is closed, and no slection was confirmed.
selector.SelectionChanged += col => { };
selector.SelectionConfirmed += col => this.someValue = col.FirstOrDefault();
selector.ShowInPopup(); // Returns the Odin Editor Window instance, in case you want to mess around with that as well.
}
}
// All Odin Selectors can be rendered anywhere with Odin.
[ShowInInspector]
MySelector inlineSelector;
protected OdinSelector()
public bool DrawConfirmSelectionButton
public OdinMenuTree SelectionTree { get; }
public virtual string Title { get; }
protected abstract void BuildSelectionTree(OdinMenuTree tree)
OdinMenuTree | tree |
protected virtual float DefaultWindowWidth()
System.Single |
[OnInspectorGUI]
[PropertyOrder(-1F)]
protected virtual void DrawSelectionTree()
public static IEnumerable<T> DrawSelectorDropdown(GUIContent label, string btnLabel, Func<Rect, OdinSelector<T>> createSelector, bool returnValuesOnSelectionChange, GUIStyle style = null, params GUILayoutOption[] options)
UnityEngine.GUIContent | label | |
System.String | btnLabel | |
System.Func<UnityEngine.Rect, OdinSelector<T>> | createSelector | |
System.Boolean | returnValuesOnSelectionChange | |
UnityEngine.GUIStyle | style | |
UnityEngine.GUILayoutOption[] | options |
System.Collections.Generic.IEnumerable<T> |
public static IEnumerable<T> DrawSelectorDropdown(GUIContent label, string btnLabel, Func<Rect, OdinSelector<T>> createSelector, GUIStyle style = null, params GUILayoutOption[] options)
UnityEngine.GUIContent | label | |
System.String | btnLabel | |
System.Func<UnityEngine.Rect, OdinSelector<T>> | createSelector | |
UnityEngine.GUIStyle | style | |
UnityEngine.GUILayoutOption[] | options |
System.Collections.Generic.IEnumerable<T> |
public static IEnumerable<T> DrawSelectorDropdown(GUIContent label, GUIContent btnLabel, Func<Rect, OdinSelector<T>> createSelector, bool returnValuesOnSelectionChange, GUIStyle style = null, params GUILayoutOption[] options)
UnityEngine.GUIContent | label | |
UnityEngine.GUIContent | btnLabel | |
System.Func<UnityEngine.Rect, OdinSelector<T>> | createSelector | |
System.Boolean | returnValuesOnSelectionChange | |
UnityEngine.GUIStyle | style | |
UnityEngine.GUILayoutOption[] | options |
System.Collections.Generic.IEnumerable<T> |
public static IEnumerable<T> DrawSelectorDropdown(GUIContent label, GUIContent btnLabel, Func<Rect, OdinSelector<T>> createSelector, GUIStyle style = null, params GUILayoutOption[] options)
UnityEngine.GUIContent | label | |
UnityEngine.GUIContent | btnLabel | |
System.Func<UnityEngine.Rect, OdinSelector<T>> | createSelector | |
UnityEngine.GUIStyle | style | |
UnityEngine.GUILayoutOption[] | options |
System.Collections.Generic.IEnumerable<T> |
public static IEnumerable<T> DrawSelectorDropdown(Rect rect, string btnLabel, Func<Rect, OdinSelector<T>> createSelector, bool returnValuesOnSelectionChange, GUIStyle style = null)
UnityEngine.Rect | rect | |
System.String | btnLabel | |
System.Func<UnityEngine.Rect, OdinSelector<T>> | createSelector | |
System.Boolean | returnValuesOnSelectionChange | |
UnityEngine.GUIStyle | style |
System.Collections.Generic.IEnumerable<T> |
public static IEnumerable<T> DrawSelectorDropdown(Rect rect, string btnLabel, Func<Rect, OdinSelector<T>> createSelector, GUIStyle style = null)
UnityEngine.Rect | rect | |
System.String | btnLabel | |
System.Func<UnityEngine.Rect, OdinSelector<T>> | createSelector | |
UnityEngine.GUIStyle | style |
System.Collections.Generic.IEnumerable<T> |
public static IEnumerable<T> DrawSelectorDropdown(Rect rect, GUIContent btnLabel, Func<Rect, OdinSelector<T>> createSelector, bool returnValuesOnSelectionChange, GUIStyle style = null, SdfIconType valueIcon = SdfIconType.None)
UnityEngine.Rect | rect | |
UnityEngine.GUIContent | btnLabel | |
System.Func<UnityEngine.Rect, OdinSelector<T>> | createSelector | |
System.Boolean | returnValuesOnSelectionChange | |
UnityEngine.GUIStyle | style | |
SdfIconType | valueIcon |
System.Collections.Generic.IEnumerable<T> |
public static IEnumerable<T> DrawSelectorDropdown(Rect rect, GUIContent btnLabel, Func<Rect, OdinSelector<T>> createSelector, GUIStyle style = null)
UnityEngine.Rect | rect | |
UnityEngine.GUIContent | btnLabel | |
System.Func<UnityEngine.Rect, OdinSelector<T>> | createSelector | |
UnityEngine.GUIStyle | style |
System.Collections.Generic.IEnumerable<T> |
protected virtual void DrawToolbar()
protected void DrawToolbarConfirmButton()
protected void DrawToolbarSearch()
protected void DrawToolbarTitle()
public void EnableSingleClickToSelect()
public virtual IEnumerable<T> GetCurrentSelection()
System.Collections.Generic.IEnumerable<T> |
public virtual bool IsValidSelection(IEnumerable<T> collection)
System.Collections.Generic.IEnumerable<T> | collection |
System.Boolean |
public void OnInspectorGUI()
protected void RebuildMenuTree()
public virtual void SetSelection(T selected)
T | selected |
public virtual void SetSelection(IEnumerable<T> selection)
System.Collections.Generic.IEnumerable<T> | selection |
public OdinEditorWindow ShowInPopup()
OdinEditorWindow |
public OdinEditorWindow ShowInPopup(float windowWidth)
System.Single | windowWidth |
OdinEditorWindow |
public OdinEditorWindow ShowInPopup(float width, float height)
System.Single | width | |
System.Single | height |
OdinEditorWindow |
public OdinEditorWindow ShowInPopup(Rect btnRect)
UnityEngine.Rect | btnRect |
OdinEditorWindow |
public OdinEditorWindow ShowInPopup(Rect btnRect, float windowWidth)
UnityEngine.Rect | btnRect | |
System.Single | windowWidth |
OdinEditorWindow |
public OdinEditorWindow ShowInPopup(Rect btnRect, Vector2 windowSize)
UnityEngine.Rect | btnRect | |
UnityEngine.Vector2 | windowSize |
OdinEditorWindow |
public OdinEditorWindow ShowInPopup(Vector2 position)
UnityEngine.Vector2 | position |
OdinEditorWindow |
public OdinEditorWindow ShowInPopup(Vector2 position, float windowWidth)
UnityEngine.Vector2 | position | |
System.Single | windowWidth |
OdinEditorWindow |
protected void TriggerSelectionChanged()
public event Action SelectionCancelled
public event Action<IEnumerable<T>> SelectionChanged
public event Action<IEnumerable<T>> SelectionConfirmed