Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Attributes.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions Attributes/Spiney.SubclassSelector.Runtime.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "Spiney.SubclassSelector.Runtime",
"rootNamespace": "",
"references": [],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
7 changes: 7 additions & 0 deletions Attributes/Spiney.SubclassSelector.Runtime.asmdef.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

119 changes: 61 additions & 58 deletions Attributes/SubclassPathAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,81 +1,84 @@
using System;

/// <summary>
/// Use this attribute on plain class types to determine their path when using <see cref="SubclassSelectorAttribute"/>.
/// </summary>
[System.Diagnostics.Conditional("UNITY_EDITOR")]
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public sealed class SubclassPathAttribute : Attribute
namespace Spiney.SubclassSelector
{
#region Constructors

/// <summary>
/// Empty constructor. The types names in <see cref="SubclassSelectorAttribute"/> will not be modified.
/// </summary>
public SubclassPathAttribute() { }

/// <summary>
/// Determines the path for types displayed in <see cref="SubclassPathAttribute"/>.
/// The default type name will be used.
/// Use this attribute on plain class types to determine their path when using <see cref="SubclassSelectorAttribute"/>.
/// </summary>
/// <param name="path">The path for this type.</param>
public SubclassPathAttribute(string path)
[System.Diagnostics.Conditional("UNITY_EDITOR")]
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public sealed class SubclassPathAttribute : Attribute
{
SubClassPath = path;
}
#region Constructors

/// <summary>
/// Determines both the path and the display name for types displayed in <see cref="SubclassSelectorAttribute"/>.
/// </summary>
/// <param name="path">The path for this type.</param>
/// <param name="subclassName">The display name for this type.</param>
public SubclassPathAttribute(string path, string subclassName)
{
SubClassPath = path;
SubClassName = subclassName;
}
/// <summary>
/// Empty constructor. The types names in <see cref="SubclassSelectorAttribute"/> will not be modified.
/// </summary>
public SubclassPathAttribute() { }

/// <summary>
/// Determines the path for types displayed in <see cref="SubclassPathAttribute"/>.
/// The default type name will be used.
/// </summary>
/// <param name="path">The path for this type.</param>
public SubclassPathAttribute(string path)
{
SubClassPath = path;
}

#endregion
/// <summary>
/// Determines both the path and the display name for types displayed in <see cref="SubclassSelectorAttribute"/>.
/// </summary>
/// <param name="path">The path for this type.</param>
/// <param name="subclassName">The display name for this type.</param>
public SubclassPathAttribute(string path, string subclassName)
{
SubClassPath = path;
SubClassName = subclassName;
}

#region Internal Members
#endregion

private string _subClassPath = string.Empty;
#region Internal Members

private string _subClassName = string.Empty;
private string _subClassPath = string.Empty;

#endregion
private string _subClassName = string.Empty;

#region Properties
#endregion

/// <summary>
/// The path for this type as used by <see cref="SubclassSelectorAttribute"/>.
/// </summary>
public string SubClassPath
{
get => _subClassPath;
set
#region Properties

/// <summary>
/// The path for this type as used by <see cref="SubclassSelectorAttribute"/>.
/// </summary>
public string SubClassPath
{
HasSubClassPath = !string.IsNullOrEmpty(value);
_subClassPath = value;
get => _subClassPath;
set
{
HasSubClassPath = !string.IsNullOrEmpty(value);
_subClassPath = value;
}
}
}

/// <summary>
/// The display name for this type as used by <see cref="SubclassSelectorAttribute"/>.
/// </summary>
public string SubClassName
{
get => _subClassName;
set
/// <summary>
/// The display name for this type as used by <see cref="SubclassSelectorAttribute"/>.
/// </summary>
public string SubClassName
{
HasSubClassName = !string.IsNullOrEmpty(value);
_subClassName = value;
get => _subClassName;
set
{
HasSubClassName = !string.IsNullOrEmpty(value);
_subClassName = value;
}
}
}

public bool HasSubClassPath { get; private set; } = false;
public bool HasSubClassPath { get; private set; } = false;

public bool HasSubClassName { get; private set; } = false;
public bool HasSubClassName { get; private set; } = false;

#endregion
#endregion
}
}
11 changes: 11 additions & 0 deletions Attributes/SubclassPathAttribute.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

163 changes: 83 additions & 80 deletions Attributes/SubclassSelectorAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,91 +1,94 @@
using System;

/// <summary>
/// Attribute that allows you to easily select from among the subclsses of a non-Unity Object, polymorphic reference value.
/// Supports both singular fields and collections of any type that Odin supports.
/// </summary>
[System.Diagnostics.Conditional("UNITY_EDITOR")]
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]
public sealed class SubclassSelectorAttribute : Attribute
namespace Spiney.SubclassSelector
{
#region Constructor

public SubclassSelectorAttribute() { }

#endregion

#region Internal Members

private string _customTypeFilter = string.Empty;

private bool _hasCustomTypeFilter = false;

#endregion

#region Properties

/// <summary>
/// If false, duplicate won't be selectable in the collection selector, or collection element dropdowns.
/// </summary>
/// <remarks>
/// Only affects collections. True by default.
/// </remarks>
public bool AllowDuplicates { get; set; } = true;

/// <summary>
/// Will hide the Odin default object reference picker if true as it it has been
/// decorated with <see cref="Sirenix.OdinInspector.HideReferenceObjectPickerAttribute"/>.
/// </summary>
/// <remarks>
/// True by default.
/// </remarks>
public bool HideReferencePicker { get; set; } = true;

/// <summary>
/// If true, <see cref="Sirenix.OdinInspector.TypeFilterAttribute"/> dropdowns will be drawn at the top
/// of each list element.
/// Attribute that allows you to easily select from among the subclsses of a non-Unity Object, polymorphic reference value.
/// Supports both singular fields and collections of any type that Odin supports.
/// </summary>
/// <remarks>
/// Only affects collections. False by default.
/// </remarks>
public bool DrawDropdownForListElements { get; set; } = false;

/// <summary>
/// If true, will draw a BoxGroup-style box around each element of a collection.
/// </summary>
/// <remarks>
/// False by default. Only affects collections.
/// </remarks>
public bool DrawBoxForListElements { get; set; } = false;

/// <summary>
/// If true, will hide the class' label as if it had been decorated with <see cref="Sirenix.OdinInspector.HideLabelAttribute"/>.
/// </summary>
/// <remarks>
/// Only affects non-collection fields. True by default.
/// </remarks>
public bool HideClassLabel { get; set; } = true;

/// <summary>
/// Provide a value resolver expression to filter types after the intial collection of subtypes has been generated.
/// </summary>
/// <remarks>
/// Abstract types are already filtered.
/// </remarks>
public string CustomTypeFilter
[System.Diagnostics.Conditional("UNITY_EDITOR")]
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]
public sealed class SubclassSelectorAttribute : Attribute
{
get => _customTypeFilter;
set
#region Constructor

public SubclassSelectorAttribute() { }

#endregion

#region Internal Members

private string _customTypeFilter = string.Empty;

private bool _hasCustomTypeFilter = false;

#endregion

#region Properties

/// <summary>
/// If false, duplicate won't be selectable in the collection selector, or collection element dropdowns.
/// </summary>
/// <remarks>
/// Only affects collections. True by default.
/// </remarks>
public bool AllowDuplicates { get; set; } = true;

/// <summary>
/// Will hide the Odin default object reference picker if true as it it has been
/// decorated with <see cref="Sirenix.OdinInspector.HideReferenceObjectPickerAttribute"/>.
/// </summary>
/// <remarks>
/// True by default.
/// </remarks>
public bool HideReferencePicker { get; set; } = true;

/// <summary>
/// If true, <see cref="Sirenix.OdinInspector.TypeFilterAttribute"/> dropdowns will be drawn at the top
/// of each list element.
/// </summary>
/// <remarks>
/// Only affects collections. False by default.
/// </remarks>
public bool DrawDropdownForListElements { get; set; } = false;

/// <summary>
/// If true, will draw a BoxGroup-style box around each element of a collection.
/// </summary>
/// <remarks>
/// False by default. Only affects collections.
/// </remarks>
public bool DrawBoxForListElements { get; set; } = false;

/// <summary>
/// If true, will hide the class' label as if it had been decorated with <see cref="Sirenix.OdinInspector.HideLabelAttribute"/>.
/// </summary>
/// <remarks>
/// Only affects non-collection fields. True by default.
/// </remarks>
public bool HideClassLabel { get; set; } = true;

/// <summary>
/// Provide a value resolver expression to filter types after the intial collection of subtypes has been generated.
/// </summary>
/// <remarks>
/// Abstract types are already filtered.
/// </remarks>
public string CustomTypeFilter
{
_hasCustomTypeFilter = !string.IsNullOrEmpty(value);
_customTypeFilter = value;
get => _customTypeFilter;
set
{
_hasCustomTypeFilter = !string.IsNullOrEmpty(value);
_customTypeFilter = value;
}
}
}

/// <summary>
/// Is there a custom type filter expression?
/// </summary>
public bool HasCustomTypeFilter => _hasCustomTypeFilter;
/// <summary>
/// Is there a custom type filter expression?
/// </summary>
public bool HasCustomTypeFilter => _hasCustomTypeFilter;

#endregion
#endregion
}
}
11 changes: 11 additions & 0 deletions Attributes/SubclassSelectorAttribute.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading