Giter VIP home page Giter VIP logo

com.unity.searcher's Introduction

Searcher

Use the Searcher package to quickly search a large list of items via a popup window. For example, use Searcher to find, select, and put down a new node in a graph. The Searcher package also includes samples and tests.

Features

GitHub Logo GitHub Logo

  • Popup Window Placement
  • Tree View
  • Keyboard Navigation
  • Quick Search
  • Auto-Complete
  • Match Highlighting
  • Multiple Databases

Quick Usage Example

void OnMouseDown( MouseDownEvent evt )
{
    var items = new List<SearcherItem>
    {
        new SearcherItem( "Books", "Description", new List<SearcherItem>()
        {
            new SearcherItem( "Dune" ),
        } )
    };
    items[0].AddChild( new SearcherItem( "Ender's Game" ) );

    SearcherWindow.Show(
        this, // this EditorWindow
        items, "Optional Title",
        item => { Debug.Log( item.name ); return /*close window?*/ true; },
        evt.mousePosition );
}

Installing the Package

Open this file in your project:

Packages/manifest.json

Add this to the dependencies array (makes sure to change the version string to your current version):

"com.unity.searcher": "4.0.0-preview"

For example, if this it he only package you depend on, you should have something like this (makes sure to change the version string to your current version):

{
    "dependencies": {
        "com.unity.searcher": "4.0.0-preview"
    }
}

Enabling the Samples and Tests

Right now, it seems Samples and Tests only show for local packages, meaning you cloned this repo inside your Packages folder. Given you've done that, open this file in your project:

Packages/manifest.json

Add a testables list with the package name so you get something like this (makes sure to change the version string to your current version):

{
    "dependencies": {
        "com.unity.searcher": "4.0.0-preview"
    },
    "testables" : [ "com.unity.searcher" ]
}

You should see a new top-level menu called Searcher and you should see Searcher tests in Test Runner.

Searcher Creation from Database

var bookItems = new List<SearcherItem> { new SearcherItem( "Books" ) };
var foodItems = new List<SearcherItem> { new SearcherItem( "Foods" ) };

// Create databases.
var databaseDir = Application.dataPath + "/../Library/Searcher";
var bookDatabase = SearcherDatabase.Create( bookItems, databaseDir + "/Books" );
var foodDatabase = SearcherDatabase.Create( foodItems, databaseDir + "/Foods" );

// At a later time, load database from disk.
bookDatabase = SearcherDatabase.Load( databaseDir + "/Books" );

var searcher = new Searcher(
    new SearcherDatabase[]{ foodDatabase, bookDatabase },
    "Optional Title" );

Popup Window or Create Control

Searcher m_Searcher;

void OnMouseDown( MouseDownEvent evt ) { // Popup window...
   SearcherWindow.Show( this, m_Searcher,
       item => { Debug.Log( item.name ); return /*close window?*/ true; },
       evt.mousePosition );
}

// ...or create SearcherControl VisualElement
void OnEnable() { // ...or create SearcherControl VisualElement
   var searcherControl = new SearcherControl();
   searcherControl.Setup( m_Searcher, item => Debug.Log( item.name ) );
   this.GetRootVisualContainer().Add( searcherControl );
}

Customize the UI via ISearcherAdapter

public interface ISearcherAdapter {
   VisualElement MakeItem();
   VisualElement Bind( VisualElement target, SearcherItem item,
                       ItemExpanderState expanderState, string text );
   string title { get; }
   bool hasDetailsPanel { get; }
   void DisplaySelectionDetails( VisualElement detailsPanel, SearcherItem o );
   void DisplayNoSelectionDetails( VisualElement detailsPanel );
   void InitDetailsPanel( VisualElement detailsPanel );
}

var bookDatabase = SearcherDatabase.Load( Application.dataPath + "/Books" );
var myAdapter = new MyAdapter(); // class MyAdapter : ISearcherAdapter
var searcher = new Searcher( bookDatabase, myAdapter );

Technical details

Requirements

This version of Searcher is compatible with the following versions of the Unity Editor:

  • 2019.1 and later (recommended)

Known limitations

Searcher version 1.0 includes the following known limitations:

  • Only works with .Net 4.0

Package contents

The following table indicates the main folders of the package:

Location Description
Editor/Resources Contains images used in the UI.
Editor/Searcher Contains Searcher source files.
Samples Contains the samples.
Tests Contains the tests.

com.unity.searcher's People

Contributors

goshikhar 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.