Version: 5.3 (switch to 5.4b)
IdiomaEnglish
  • C#
  • JS

Idioma de script

Selecciona tu lenguaje de programación favorito. Todos los fragmentos de código serán mostrados en este lenguaje.

AssetDatabase.FindAssets

Sugiere un cambio

¡Éxito!

Gracias por ayudarnos a mejorar la calidad de la documentación de Unity. A pesar de que no podemos aceptar todas las sugerencias, leemos cada cambio propuesto por nuestros usuarios y actualizaremos los que sean aplicables.

Cerrar

No se puedo enviar

Por alguna razón su cambio sugerido no pudo ser enviado. Por favor <a>intente nuevamente</a> en unos minutos. Gracias por tomarse un tiempo para ayudarnos a mejorar la calidad de la documentación de Unity.

Cerrar

Cancelar

Cambiar al Manual
public static function FindAssets(filter: string): string[];
public static string[] FindAssets(string filter);
public static function FindAssets(filter: string, searchInFolders: string[]): string[];
public static string[] FindAssets(string filter, string[] searchInFolders);

Parámetros

filter The filter string can contain search data for: names, asset labels and types (class names).
searchInFolders Specifying one or more folders will limit the searching to these folders and their child folders (and is faster than searching all assets).

Valor de retorno

string[] Array of matching asset GUIDs.

Descripción

Search the asset database using a search filter string.

You can search for names, lables and types (classnames).


'name': filter assets by their filename (without extension). Words separated by whitespace are treated as separate name searches. Use quotes for grouping multiple words into a single search.


'labels': Use the keyword 'l'. Filtering by more than one label will return assets if just one asset label is matched (OR'ed)


'types': Use the keyword 't'. Filtering by more than one type will return assets if just one type is matched (OR'ed). Types can be either builtin types e.g 'Texture2D' or user script class names. If all assets are wanted: use 'Object' as all assets derive from Object.

Searching is case insensitive

Use AssetDatabase.GUIDToAssetPath to get assetpaths and e.g AssetDatabase.LoadAssetAtPath to load an asset.

@MenuItem("Test/FindAssetsUsingSearchFilter")
static function FindAssetsUsingSearchFilter ()
{
	// Find all assets labelled with 'concrete' :
	var guids = AssetDatabase.FindAssets ("l:concrete", null);
	for (var guid in guids)
		Debug.Log (AssetDatabase.GUIDToAssetPath(guid));

// Find all Texture2Ds that have 'co' in their filename, that are labelled with 'concrete' or 'architecture' and are placed in 'MyAwesomeProps' folder var guids2 = AssetDatabase.FindAssets ("co l:concrete l:architecture t:texture2D", ["Assets/MyAwesomeProps"]); for (var guid in guids2) Debug.Log (AssetDatabase.GUIDToAssetPath(guid)); }
using UnityEngine;
using UnityEditor;

public class Example {

[MenuItem("Test/FindAssetsUsingSearchFilter")] static void FindAssetsUsingSearchFilter() { // Find all assets labelled with 'concrete' : string[] guids = AssetDatabase.FindAssets ("l:concrete");

foreach (string guid in guids) { Debug.Log (AssetDatabase.GUIDToAssetPath(guid)); }

// Find all Texture2Ds that have 'co' in their filename, that are labelled with 'concrete' or 'architecture' and are placed in 'MyAwesomeProps' folder string[] lookFor = new string[] {"Assets/MyAwesomeProps"}; string[] guids2 = AssetDatabase.FindAssets ("co l:concrete l:architecture t:texture2D", lookFor);

foreach (string guid in guids2) { Debug.Log (AssetDatabase.GUIDToAssetPath(guid)); } } }