Skip to content

schwapo/ObjectPreview

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 

Repository files navigation

ObjectPreview

$${\color{Goldenrod}\textnormal{Deprecated! \ Nearly \ all \ of \ these \ improvements \ are \ now \ integrated \ into \ Odin \ Inspector.}}$$

Draws object previews similar to Odin's PreviewField attribute, but with more configurability.

Installation

Simply put the downloaded ObjectPreview folder in your project and start using the attribute as shown in the examples. You can move the files, but make sure that ObjectPreviewAttribute.cs is not in an editor folder or it will be removed during build, causing errors.

Examples

// SomeScriptableObject.cs
public class SomeScriptableObject : ScriptableObject
{
    public Texture2D preview;
}

// SomeMonoBehaviour.cs
public class SomeMonoBehaviour : MonoBehaviour
{
    // We don't provide a preview string to resolve, so it looks for a field 
    // named "preview" on the object first If that also fails, the object's 
    // default asset thumbnail is used.
    [ObjectPreview]
    public SomeScriptableObject SomeSO;

    // We pass a property name as the value for the Preview parameter.
    // We then use the returned value of this property as our preview image.
    [ObjectPreview(Preview = nameof(GameObjectPreview))]
    public GameObject SomeObject;

    // We pass a method name as the value for the Selectables parameter.
    // We then use the returned value of this method as our selectable values.
    [ObjectPreview(Selectables = nameof(GetSelectables))]
    public Texture2D SomeOtherObject;

    private Texture2D GameObjectPreview => 
        Resources.Load<Texture2D>("Odin Inspector Logo");

    private IEnumerable<Texture2D> GetSelectables() => 
        AssetDatabase.FindAssets("t:Texture2D")
            .Select(AssetDatabase.GUIDToAssetPath)
            .Select(AssetDatabase.LoadAssetAtPath<Texture2D>);
}

Parameters

Parameter Description Default Type
Height Determines the width and height of the square preview Configurable in Odin preferences. float
Alignment Determines the position of the preview image Configurable in Odin preferences. ObjectFieldAlignment
FilterMode Determines the filter mode that is used when the preview image is displayed FilterMode.Point FilterMode
Transparent Determines if the preview should have a transparent background instead of grey boxes false bool
Tooltip Determines the tooltip that is displayed when you move the mouse over the preview image null string
Selectables A resolved string that determines which values can be selected for this preview field. Setting this parameter automatically adds a selection button that allows you to select one of the selectable values. Setting this will also disable drag and drop to ensure that only selectable values are set. null string / ValueResolver
Preview A Resolved string that determines the image that gets used as a preview. If no value is provided it will first try to find a property called preview on the target object if that also fails it will use the assets default thumbnail. "@$value.preview" string / ValueResolver

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages