Find All Assets by Type

Hi, I need to find all assets by their type no matter if they are active or not.

the reason is, because I made my custom Object Field Script for custom finding criteria.
this AssetsFinder can filter scene or asset objects and filter them by components which they have.

Resources.FindObjectsOfTypeAll should do the trick. But it doesn’t, because it works only on previously selected assets.
If I restart the Editor, it would not found the assets before I click on them. Why ?
This is an huge problem.

The purpose is that our team should see only relevant prefabs or game objects which have only relevant components.
How this can be done ?

Jaroslav Stehlik - Team Leader At Silicon Jelly.
http://www.siliconjelly.com

I figured it out with my selft implementation of searching trhu assets. Works perfect.

protected static function getAllEditorAssets():GameObject[]
    {
    var tempObjects:Array = new Array();
    var directory:DirectoryInfo = new DirectoryInfo(Application.dataPath);
    var goFileInfo:FileInfo[] = directory.GetFiles("*.prefab", SearchOption.AllDirectories);
    var i:uint = 0; var goFileInfoLength:uint = goFileInfo.length;
    var tempGoFileInfo:FileInfo; var tempFilePath:String; var assetIndex:int;
    var tempGO:GameObject;
    for(i = 0; i < goFileInfoLength; i++)
    {
        tempGoFileInfo = goFileInfo *as FileInfo;*
 *if(tempGoFileInfo == null) continue;* 
 *tempFilePath = tempGoFileInfo.FullName;*
 *assetIndex = tempFilePath.IndexOf("Assets/");*
 *//assetIndex = tempFilePath.IndexOf("Assets\\");*
 *if (assetIndex < 0) assetIndex = 0;* 
 *tempFilePath = tempFilePath.Substring(assetIndex, tempFilePath.length - assetIndex);*
 *//tempFilePath = tempFilePath.Replace('\\', '/');*
 *tempGO = AssetDatabase.LoadAssetAtPath(tempFilePath, GameObject) as GameObject;*
 *if(tempGO == null) continue;*
 *tempObjects.push(tempGO);*
 *}*
 *return tempObjects.ToBuiltin(GameObject) as GameObject[];*
*}*
*```*

Converted to c#

     /// <summary>
    /// Used to get assets of a certain type and file extension from entire project
    /// </summary>
    /// <param name="type">The type to retrieve. eg typeof(GameObject).</param>
    /// <param name="fileExtension">The file extention the type uses eg ".prefab".</param>
    /// <returns>An Object array of assets.</returns>
    public static Object[] GetAssetsOfType(System.Type type, string fileExtension)
    {
    List<Object> tempObjects = new List<Object>();
    DirectoryInfo directory = new DirectoryInfo(Application.dataPath);
    FileInfo[] goFileInfo = directory.GetFiles("*" + fileExtension, SearchOption.AllDirectories);
     
    int i = 0; int goFileInfoLength = goFileInfo.Length;
    FileInfo tempGoFileInfo; string tempFilePath;
    Object tempGO;
    for (; i < goFileInfoLength; i++)
    {
    tempGoFileInfo = goFileInfo*;*

if (tempGoFileInfo == null)
continue;

tempFilePath = tempGoFileInfo.FullName;
tempFilePath = tempFilePath.Replace(@"", “/”).Replace(Application.dataPath, “Assets”);

Debug.Log(tempFilePath + "
" + Application.dataPath);

tempGO = AssetDatabase.LoadAssetAtPath(tempFilePath, typeof(Object)) as Object;
if (tempGO == null)
{
Debug.LogWarning(“Skipping Null”);
continue;
}
else if (tempGO.GetType() != type)
{
Debug.LogWarning("Skipping " + tempGO.GetType().ToString());
continue;
}

tempObjects.Add(tempGO);
}

return tempObjects.ToArray();
}

a little improvement:
deleting unnecessary logs and fixing summary (file extension should give without dot) and writing as generic type.

        /// <summary>
        /// Used to get assets of a certain type and file extension from entire project
        /// </summary>
        /// <param name="T">The type to retrieve.</param>
        /// <param name="fileExtension">The file extention the type uses eg "prefab".</param>
        /// <returns>An Object array of assets.</returns>
        private static List<T> GetAssetsOfType<T>(string fileExtension)
        {
            List<T> tempObjects = new List<T>();
            DirectoryInfo directory = new DirectoryInfo(Application.dataPath);
            FileInfo[] goFileInfo = directory.GetFiles("*" + fileExtension, SearchOption.AllDirectories);
      
            int i = 0; int goFileInfoLength = goFileInfo.Length;
            FileInfo tempGoFileInfo; 
            string tempFilePath;
            Object tempGO;
            for (; i < goFileInfoLength; i++)
            {
                tempGoFileInfo = goFileInfo*;*

if (tempGoFileInfo == null)
continue;

tempFilePath = tempGoFileInfo.FullName;
tempFilePath = tempFilePath.Replace(@"", “/”).Replace(Application.dataPath, “Assets”);

tempGO = AssetDatabase.LoadAssetAtPath(tempFilePath, typeof(T));

if (tempGO is T obj)
{
tempObjects.Add(obj);
}
}

return tempObjects;
}