Version 2.1.0.0

Odin has a dedicated attribute overview with examples

PreviewFieldAttribute 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)]
public class PreviewFieldAttribute : Attribute, _Attribute

Draws a square ObjectField which renders a preview for UnityEngine.Object types. This object field also adds support for drag and drop, dragging an object to another square object field, swaps the values. If you hold down control while letting go it will replace the value, And you can control + click the object field to quickly delete the value it holds.

These object fields can also be selectively enabled and customized globally from the Odin preferences window.

Inheritance
  • System.Object
  • System.Attribute
  • PreviewFieldAttribute
Example

The following example shows how PreviewField is applied to a few property fields.

public MyComponent : MonoBehaviour
{
	[PreviewField]
	public UnityEngine.Object SomeObject;

	[PreviewField]
	public Texture SomeTexture;

	[HorizontalGroup, HideLabel, PreviewField(30)]
	public Material A, B, C, D, F;
}
See Also

Constructors

PreviewFieldAttribute()
Draws a square object field which renders a preview for UnityEngine.Object type objects.
public PreviewFieldAttribute()
PreviewFieldAttribute(ObjectFieldAlignment)
Draws a square object field which renders a preview for UnityEngine.Object type objects.
public PreviewFieldAttribute(ObjectFieldAlignment alignment)
Parameters
ObjectFieldAlignment alignment

The alignment of the preview field.

PreviewFieldAttribute(Single)
Draws a square object field which renders a preview for UnityEngine.Object type objects.
public PreviewFieldAttribute(float height)
Parameters
System.Single height

The height of the preview field.

PreviewFieldAttribute(Single, ObjectFieldAlignment)
Draws a square object field which renders a preview for UnityEngine.Object type objects.
public PreviewFieldAttribute(float height, ObjectFieldAlignment alignment)
Parameters
System.Single height

The height of the preview field.

ObjectFieldAlignment alignment

The alignment of the preview field.

Fields

Alignment
Left aligned.
public ObjectFieldAlignment Alignment
AlignmentHasValue
Whether an alignment value is specified.
public bool AlignmentHasValue
Height
The height of the object field
public float Height