zhangwenjie 121a338d00 feat: 项目源码 | 1 年之前 | |
---|---|---|
.. | ||
Documentation~ | 1 年之前 | |
Editor | 1 年之前 | |
Samples~ | 1 年之前 | |
Tests | 1 年之前 | |
CHANGELOG.md | 1 年之前 | |
CHANGELOG.md.meta | 1 年之前 | |
Editor.meta | 1 年之前 | |
LICENSE.md | 1 年之前 | |
LICENSE.md.meta | 1 年之前 | |
README.md | 1 年之前 | |
README.md.meta | 1 年之前 | |
Tests.meta | 1 年之前 | |
Third Party Notices.md | 1 年之前 | |
Third Party Notices.md.meta | 1 年之前 | |
package.json | 1 年之前 | |
package.json.meta | 1 年之前 |
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.
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 );
}
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"
}
}
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.
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" );
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 );
}
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 );
This version of Searcher is compatible with the following versions of the Unity Editor:
Searcher version 1.0 includes the following known limitations:
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. |