Version 3.3.0.1

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)]
[Conditional("UNITY_EDITOR")]
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.

PreviewFieldAttribute(String, ObjectFieldAlignment, FilterMode)
Draws a square object field which renders a preview for UnityEngine.Object type objects.
public PreviewFieldAttribute(string previewGetter, ObjectFieldAlignment alignment, FilterMode filterMode)
Parameters
System.String previewGetter

A resolved value that should resolve to the desired preview texture.

ObjectFieldAlignment alignment

The alignment of the preview field.

UnityEngine.FilterMode filterMode

The filter mode to be used for the preview texture.

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

A resolved value that should resolve to the desired preview texture.

System.Single height

The height of the preview field.

ObjectFieldAlignment alignment

The alignment of the preview field.

UnityEngine.FilterMode filterMode

The filter mode to be used for the preview texture.

PreviewFieldAttribute(String, Single, FilterMode)
Draws a square object field which renders a preview for UnityEngine.Object type objects.
public PreviewFieldAttribute(string previewGetter, float height, FilterMode filterMode)
Parameters
System.String previewGetter

A resolved value that should resolve to the desired preview texture.

System.Single height

The height of the preview field.

UnityEngine.FilterMode filterMode

The filter mode to be used for the preview texture.

PreviewFieldAttribute(String, FilterMode)
Draws a square object field which renders a preview for UnityEngine.Object type objects.
public PreviewFieldAttribute(string previewGetter, FilterMode filterMode)
Parameters
System.String previewGetter

A resolved value that should resolve to the desired preview texture.

UnityEngine.FilterMode filterMode

The filter mode to be used for the preview texture.

Fields

FilterMode
The FilterMode to be used for the preview.
public FilterMode FilterMode
Height
The height of the object field
public float Height

Properties

Alignment
Left aligned.
public ObjectFieldAlignment Alignment { get; set; }
AlignmentHasValue
Whether an alignment value is specified.
public bool AlignmentHasValue { get; }
PreviewGetter
A resolved value that should resolve to the desired preview texture.
public string PreviewGetter { get; set; }
PreviewGetterHasValue
public bool PreviewGetterHasValue { get; }