Giter Club home page Giter Club logo

asset-search's Introduction

asset-search

Asset Search Attribute for Unity

Note: this project will no longer be updated as this code has migrated to Search-Windows. To use the new version, uninstall this version and install Search Windows, then change LS.Attributes to LS.SearchWindows in your using statements.

Use this attribute on your serialized object fields to add a button that opens a search window for your assets based on the type. The search window will keep elements sorted by the folder structure.
This can be used with Generics (which usually can't use the quick search on the normal object field!) and interfaces (though there are some drawbacks to this). You can also use a property name for a type.

Examples

General Usage

//...
using UnityEngine;
using LS.Attributes;

public class Example : MonoBehavior
{
  [SerializeField]
  [AssetSearch] //Creates a search window button that filters for Sprites in Assets
  Sprite sprite;
}

Generics

  public class AssetVariable<T> : ScriptableObject 
  {
    public T Value;
  }

  public class Example : MonoBehavior
  {
    [SerializeField]
    [AssetSearch] //Creates a search button that filters for AssetVariable<int>'s in Assets 
    AssetVariable<int> test;
  }

Interfaces

  public interface ITest 
  {
    void Do();
  }
  
  public class TestBase : ScriptableObject, ITest
  {
    public override void Do() 
    {
      Debug.Log("TestBase");
    }
  }
  
  public class Example : MonoBehavior
  {
    [SerializeField]
    [AssetSearch(typeof(ITest)]
    ScriptableObject ITestObject;
    
    void Start()
    {
      (ITestObject as ITest)?.Do();
    }
  }

Note: this WON'T work because interfaces aren't serialized

  public class Example : MonoBehavior
  {
    [SerializeField]
    [AssetSearch]
    ITest ITestObject;
    
    //do stuff with ITestObject
  }

Property

  public class GenericReference<T>
  {
    [SerializeField]
    [AssetSearch(typePropertyName: nameof(ReferenceType))] //will get type from the property ReferenceType 
    Object _value;
    
    Type ReferenceType => typeof(T);
    
    public T Value
    {
      get => (T)_value;
      set => _value = (Object)value;
    }
  }
  
  public interface ITest 
  {
    void Do();
  }
  
  public class Example : MonoBehavior
  {
    [SerializeField]
    GenericReference<ITest> variable;
    
    void Start()
    {
      variable.Value.Do();
    }
  }

Install

Use the Unity Package Manager (UPM) to add this project from Git URL.

asset-search's People

Contributors

niashi24 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.