using System; using System.Collections.Generic; using System.Text; namespace Sirenix.OdinInspector { [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] public class LabelTextAttribute : System.Attribute { public LabelTextAttribute(string value) { } } [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] public class SerializeFieldAttribute : System.Attribute { public SerializeFieldAttribute() { } } [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] public class SuffixLabelAttribute : System.Attribute { public SuffixLabelAttribute(string value) { } public SuffixLabelAttribute(string value,bool overly) { } } [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] public class HideInInspectorAttribute : System.Attribute { public HideInInspectorAttribute() { } } [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] public class ButtonAttribute : System.Attribute { public ButtonAttribute(string value) { } } [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] public class ButtonGroupAttribute : System.Attribute { public ButtonGroupAttribute(string value) { } } [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] public class FoldoutGroupAttribute : System.Attribute { public FoldoutGroupAttribute(string value) { } } [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] public class PropertyRangeAttribute : System.Attribute { public PropertyRangeAttribute(double min, double max) { } } [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] public class HideLabelAttribute : System.Attribute { public HideLabelAttribute() { } } [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] public class PropertySpaceAttribute : System.Attribute { public PropertySpaceAttribute() { } } [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] public class PropertyOrderAttribute : System.Attribute { public PropertyOrderAttribute(int order) { } } public enum TitleAlignments { /// Title and subtitle left aligned. Left, /// Title and subtitle centered aligned. Centered, /// Title and subtitle right aligned. Right, /// Title on the left, subtitle on the right. Split, } public class TitleAttribute : Attribute { /// /// The title displayed above the property in the inspector. /// public string Title; /// Optional subtitle. public string Subtitle; /// /// If true the title will be displayed with a bold font. /// public bool Bold; /// /// Gets a value indicating whether or not to draw a horizontal line below the title. /// public bool HorizontalLine; /// Title alignment. public TitleAlignments TitleAlignment; /// Creates a title above any property in the inspector. /// The title displayed above the property in the inspector. /// Optional subtitle /// Title alignment /// Horizontal line /// If true the title will be drawn with a bold font. public TitleAttribute( string title, string subtitle = null, TitleAlignments titleAlignment = TitleAlignments.Left, bool horizontalLine = true, bool bold = true) { this.Title = title ?? "null"; this.Subtitle = subtitle; this.Bold = bold; this.TitleAlignment = titleAlignment; this.HorizontalLine = horizontalLine; } } public enum DictionaryDisplayOptions { ExpandedFoldout, OneLine, } [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] public class DictionaryDrawerSettings : System.Attribute { public string KeyLabel; public string ValueLabel; public DictionaryDisplayOptions DisplayMode; public DictionaryDrawerSettings() { } } [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] public class TitleGroup : System.Attribute { public TitleGroup(string value) { } } [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] public class LabelWidthAttribute : System.Attribute { public LabelWidthAttribute(int value) { } } [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] public class ShowIfAttribute : System.Attribute { public ShowIfAttribute(string value) { } public ShowIfAttribute(string name, object value) { } } [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] public class InfoBoxAttribute : System.Attribute { public InfoBoxAttribute(string value) { } public InfoBoxAttribute(string value, InfoMessageType infoMessageType) { } } public enum InfoMessageType { Error } [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] public class TabGroupAttribute : System.Attribute { public TabGroupAttribute(string value) { } } [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] public class HideInEditorModeAttribute : System.Attribute { public HideInEditorModeAttribute() { } } [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] public class ShowInInspectorAttribute : System.Attribute { public ShowInInspectorAttribute() { } } [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] public class ListDrawerSettingsAttribute : System.Attribute { public bool ShowItemCount; public bool ShowIndexLabels; public ListDrawerSettingsAttribute() { } } [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] public class GUIColorAttribute : System.Attribute { public GUIColorAttribute(float r, float g, float b, float a = 0) { } } [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] public class ReadOnlyAttribute : System.Attribute { public ReadOnlyAttribute() { } } [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] public class MultiLinePropertyAttribute : System.Attribute { public MultiLinePropertyAttribute(int value) { } } [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] public class HorizontalGroupAttribute : System.Attribute { public HorizontalGroupAttribute() { } } [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] public class HideIfAttribute : System.Attribute { public HideIfAttribute(string value, object m) { } } [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] public class DisableInEditorModeAttribute : System.Attribute { } [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] public class EnumToggleButtonsAttribute : System.Attribute { } [AttributeUsage(AttributeTargets.All, AllowMultiple = true)] public class MinValueAttribute : System.Attribute { public MinValueAttribute(int i) { } } public class BoxGroupAttribute : PropertyGroupAttribute { /// /// If true a label for the group will be drawn on top. /// public bool ShowLabel; /// /// If true the header label will be places in the center of the group header. Otherwise it will be in left side. /// public bool CenterLabel; /// Adds the property to the specified box group. /// The box group. /// If true a label will be drawn for the group. /// If set to true the header label will be centered. /// The order of the group in the inspector. public BoxGroupAttribute(string group, bool showLabel = true, bool centerLabel = false, int order = 0) : base(group, order) { this.ShowLabel = showLabel; this.CenterLabel = centerLabel; } /// /// Initializes a new instance of the class. Use the other constructor overloads in order to show a header-label on the box group. /// public BoxGroupAttribute() : this("_DefaultBoxGroup", false, false, 0) { } /// Combines the box group with another group. /// The other group. protected override void CombineValuesWith(PropertyGroupAttribute other) { BoxGroupAttribute boxGroupAttribute = other as BoxGroupAttribute; if (!this.ShowLabel || !boxGroupAttribute.ShowLabel) { this.ShowLabel = false; boxGroupAttribute.ShowLabel = false; } this.CenterLabel |= boxGroupAttribute.CenterLabel; } } public class ValueDropdownAttribute : Attribute { /// /// Name of any field, property or method member that implements IList. E.g. arrays or Lists. /// public string MemberName; /// /// The number of items before enabling search. Default is 10. /// public int NumberOfItemsBeforeEnablingSearch; /// False by default. public bool IsUniqueList; /// /// True by default. If the ValueDropdown attribute is applied to a list, then disabling this, /// will render all child elements normally without using the ValueDropdown. The ValueDropdown will /// still show up when you click the add button on the list drawer, unless is true. /// public bool DrawDropdownForListElements; /// False by default. public bool DisableListAddButtonBehaviour; /// /// If the ValueDropdown attribute is applied to a list, and is set to true, then enabling this, /// will exclude existing values, instead of rendering a checkbox indicating whether the item is already included or not. /// public bool ExcludeExistingValuesInList; /// /// If the dropdown renders a tree-view, then setting this to true will ensure everything is expanded by default. /// public bool ExpandAllMenuItems; /// /// If true, instead of replacing the drawer with a wide dropdown-field, the dropdown button will be a little button, drawn next to the other drawer. /// public bool AppendNextDrawer; /// /// Disables the the GUI for the appended drawer. False by default. /// public bool DisableGUIInAppendedDrawer; /// /// By default, a single click selects and confirms the selection. /// public bool DoubleClickToConfirm; /// By default, the dropdown will create a tree view. public bool FlattenTreeView; /// /// Gets or sets the width of the dropdown. Default is zero. /// public int DropdownWidth; /// /// Gets or sets the height of the dropdown. Default is zero. /// public int DropdownHeight; /// /// Gets or sets the title for the dropdown. Null by default. /// public string DropdownTitle; /// False by default. public bool SortDropdownItems; /// Whether to draw all child properties in a foldout. public bool HideChildProperties; /// Creates a dropdown menu for a property. /// Name of any field, property or method member that implements IList. E.g. arrays or Lists. public ValueDropdownAttribute(string memberName) { this.NumberOfItemsBeforeEnablingSearch = 10; this.MemberName = memberName; this.DrawDropdownForListElements = true; } } public sealed class OnValueChangedAttribute : Attribute { /// Name of callback member function. public string MethodName; /// /// Whether to invoke the method when a child value of the property is changed. /// public bool IncludeChildren; /// /// Adds a callback for when the property's value is changed. /// /// Name of the method. /// Whether to invoke the method when a child value of the property is changed. public OnValueChangedAttribute(string methodName, bool includeChildren = false) { this.MethodName = methodName; this.IncludeChildren = includeChildren; } } public class HideReferenceObjectPickerAttribute : Attribute { } public abstract class PropertyGroupAttribute : Attribute { /// The ID used to grouping properties together. public string GroupID; /// /// The name of the group. This is the last part of the group ID if there is a path, otherwise it is just the group ID. /// public string GroupName; /// The order of the group. public int Order; /// /// Initializes a new instance of the class. /// /// The group identifier. /// The group order. public PropertyGroupAttribute(string groupId, int order) { this.GroupID = groupId; this.Order = order; int num = groupId.LastIndexOf('/'); this.GroupName = num < 0 || num >= groupId.Length ? groupId : groupId.Substring(num + 1); } /// /// Initializes a new instance of the class. /// /// The group identifier. public PropertyGroupAttribute(string groupId) : this(groupId, 0) { } /// /// Combines this attribute with another attribute of the same type. /// This method invokes the virtual method to invoke custom combine logic. /// All group attributes are combined to one attribute used by a single OdinGroupDrawer. /// Example: protected override void CombineValuesWith(PropertyGroupAttribute other) { this.Title = this.Title ?? (other as MyGroupAttribute).Title; } /// /// The attribute to combine with. /// The instance that the method was invoked on. /// The argument 'other' was null. /// /// Attributes to combine are not of the same type. /// or /// PropertyGroupAttributes to combine must have the same group id. /// public PropertyGroupAttribute Combine(PropertyGroupAttribute other) { if (other == null) throw new ArgumentNullException(nameof(other)); if (other.GetType() != this.GetType()) throw new ArgumentException("Attributes to combine are not of the same type."); if (other.GroupID != this.GroupID) throw new ArgumentException("PropertyGroupAttributes to combine must have the same group id."); if (this.Order == 0) this.Order = other.Order; else if (other.Order != 0) this.Order = Math.Min(this.Order, other.Order); this.CombineValuesWith(other); return this; } /// /// Override this method to add custom combine logic to your group attribute. This method determines how your group's parameters combine when spread across multiple attribute declarations in the same class. /// Remember, in .NET, member order is not guaranteed, so you never know which order your attributes will be combined in. /// /// The attribute to combine with. This parameter is guaranteed to be of the correct attribute type. /// /// This example shows how attributes are combined. /// /// protected override void CombineValuesWith(PropertyGroupAttribute other) /// { /// // The given attribute parameter is *guaranteed* to be of type BoxGroupAttribute. /// var attr = other as BoxGroupAttribute; /// /// // If this attribute has no label, we the other group's label, thus preserving the label across combines. /// if (this.Label == null) /// { /// this.Label = attr.Label; /// } /// /// // Combine ShowLabel and CenterLabel parameters. /// this.ShowLabel |= attr.ShowLabel; /// this.CenterLabel |= attr.CenterLabel; /// } /// /// protected virtual void CombineValuesWith(PropertyGroupAttribute other) { } } public sealed class TextAreaAttribute : PropertyAttribute { /// /// The minimum amount of lines the text area will use. /// public readonly int minLines; /// /// The maximum amount of lines the text area can show before it starts using a scrollbar. /// public readonly int maxLines; /// /// Attribute to make a string be edited with a height-flexible and scrollable text area. /// /// The minimum amount of lines the text area will use. /// The maximum amount of lines the text area can show before it starts using a scrollbar. public TextAreaAttribute() { this.minLines = 3; this.maxLines = 3; } /// /// Attribute to make a string be edited with a height-flexible and scrollable text area. /// /// The minimum amount of lines the text area will use. /// The maximum amount of lines the text area can show before it starts using a scrollbar. public TextAreaAttribute(int minLines, int maxLines) { this.minLines = minLines; this.maxLines = maxLines; } } public abstract class PropertyAttribute : Attribute { /// /// Optional field to specify the order that multiple DecorationDrawers should be drawn in. /// public int order { get; set; } } }