Version 3.3.1.2

Odin has a dedicated attribute overview with examples

DisplayAsStringAttribute class

Namespace: Sirenix.OdinInspector
Assembly: Sirenix.OdinInspector.Attributes
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Parameter | AttributeTargets.Delegate | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter | AttributeTargets.All, AllowMultiple = false, Inherited = true)]
[Conditional("UNITY_EDITOR")]
public sealed class DisplayAsStringAttribute : Attribute, _Attribute

DisplayAsString is used on any property, and displays a string in the inspector as text.

Use this for when you want to show a string in the inspector, but not allow for any editing.

Inheritance
  • System.Object
  • System.Attribute
  • DisplayAsStringAttribute
Remarks

DisplayAsString uses the property's ToString method to display the property as a string.

Example

The following example shows how DisplayAsString is used to display a string property as text in the inspector.

public class MyComponent : MonoBehaviour
   {
       [DisplayAsString]
       public string MyInt = 5;

       // You can combine with HideLabelAttribute to display a message in the inspector.
       [DisplayAsString, HideLabel]
       public string MyMessage = "This string will be displayed as text in the inspector";

       [DisplayAsString(false)]
       public string InlineMessage = "This string is very long, but has been configured to not overflow.";
   }

Constructors

DisplayAsStringAttribute()
Displays the property as a string in the inspector.
public DisplayAsStringAttribute()
DisplayAsStringAttribute(Boolean)
Displays the property as a string in the inspector.
public DisplayAsStringAttribute(bool overflow)
Parameters
System.Boolean overflow

Value indicating if the string should overflow past the available space, or expand to multiple lines when there's not enough horizontal space.

DisplayAsStringAttribute(Boolean, Int32)
Displays the property as a string in the inspector.
public DisplayAsStringAttribute(bool overflow, int fontSize)
Parameters
System.Boolean overflow

Value indicating if the string should overflow past the available space, or expand to multiple lines when there's not enough horizontal space.

System.Int32 fontSize

The size of the font.

DisplayAsStringAttribute(Boolean, Int32, Boolean)
Displays the property as a string in the inspector.
public DisplayAsStringAttribute(bool overflow, int fontSize, bool enableRichText)
Parameters
System.Boolean overflow

Value indicating if the string should overflow past the available space, or expand to multiple lines when there's not enough horizontal space.

System.Int32 fontSize

The size of the font.

System.Boolean enableRichText

If true the string will support rich text.

DisplayAsStringAttribute(Boolean, Int32, TextAlignment)
Displays the property as a string in the inspector.
public DisplayAsStringAttribute(bool overflow, int fontSize, TextAlignment alignment)
Parameters
System.Boolean overflow

Value indicating if the string should overflow past the available space, or expand to multiple lines when there's not enough horizontal space.

System.Int32 fontSize

The size of the font.

UnityEngine.TextAlignment alignment

How the string should be aligned.

DisplayAsStringAttribute(Boolean, Int32, TextAlignment, Boolean)
Displays the property as a string in the inspector.
public DisplayAsStringAttribute(bool overflow, int fontSize, TextAlignment alignment, bool enableRichText)
Parameters
System.Boolean overflow

Value indicating if the string should overflow past the available space, or expand to multiple lines when there's not enough horizontal space.

System.Int32 fontSize

The size of the font.

UnityEngine.TextAlignment alignment

How the string should be aligned.

System.Boolean enableRichText

If true the string will support rich text.

DisplayAsStringAttribute(Boolean, TextAlignment)
Displays the property as a string in the inspector.
public DisplayAsStringAttribute(bool overflow, TextAlignment alignment)
Parameters
System.Boolean overflow

Value indicating if the string should overflow past the available space, or expand to multiple lines when there's not enough horizontal space.

UnityEngine.TextAlignment alignment

How the string should be aligned.

DisplayAsStringAttribute(Boolean, TextAlignment, Boolean)
Displays the property as a string in the inspector.
public DisplayAsStringAttribute(bool overflow, TextAlignment alignment, bool enableRichText)
Parameters
System.Boolean overflow

Value indicating if the string should overflow past the available space, or expand to multiple lines when there's not enough horizontal space.

UnityEngine.TextAlignment alignment

How the string should be aligned.

System.Boolean enableRichText

If true the string will support rich text.

DisplayAsStringAttribute(Int32)
Displays the property as a string in the inspector.
public DisplayAsStringAttribute(int fontSize)
Parameters
System.Int32 fontSize

The size of the font.

DisplayAsStringAttribute(Int32, Boolean)
Displays the property as a string in the inspector.
public DisplayAsStringAttribute(int fontSize, bool enableRichText)
Parameters
System.Int32 fontSize

The size of the font.

System.Boolean enableRichText

If true the string will support rich text.

DisplayAsStringAttribute(Int32, TextAlignment)
Displays the property as a string in the inspector.
public DisplayAsStringAttribute(int fontSize, TextAlignment alignment)
Parameters
System.Int32 fontSize

The size of the font.

UnityEngine.TextAlignment alignment

How the string should be aligned.

DisplayAsStringAttribute(Int32, TextAlignment, Boolean)
Displays the property as a string in the inspector.
public DisplayAsStringAttribute(int fontSize, TextAlignment alignment, bool enableRichText)
Parameters
System.Int32 fontSize

The size of the font.

UnityEngine.TextAlignment alignment

How the string should be aligned.

System.Boolean enableRichText

If true the string will support rich text.

DisplayAsStringAttribute(TextAlignment)
Displays the property as a string in the inspector.
public DisplayAsStringAttribute(TextAlignment alignment)
Parameters
UnityEngine.TextAlignment alignment

How the string should be aligned.

DisplayAsStringAttribute(TextAlignment, Boolean)
Displays the property as a string in the inspector.
public DisplayAsStringAttribute(TextAlignment alignment, bool enableRichText)
Parameters
UnityEngine.TextAlignment alignment

How the string should be aligned.

System.Boolean enableRichText

If true the string will support rich text.

Fields

Alignment
How the string should be aligned.
public TextAlignment Alignment
EnableRichText
If true the string will support rich text.
public bool EnableRichText
FontSize
The size of the font.
public int FontSize
Format
String for formatting the value. Type must implement the IFormattable interface.
public string Format
Overflow
If true, the string will overflow past the drawn space and be clipped when there's not enough space for the text. If false the string will expand to multiple lines, if there's not enough space when drawn.
public bool Overflow