Search Unity

Weeding out Preview Textures with LoadAllAssetsAtPath()

Discussion in 'Editor & General Support' started by Jonathan Czeck, Nov 11, 2009.

  1. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    Code (csharp):
    1.     static ArrayList GatherAssetsRecursivelyAtPath(string folderPath, Type theType, ArrayList list) {
    2.         string[] files = Directory.GetFiles(folderPath);
    3.        
    4.         foreach (string file in files) {
    5.             UnityEngine.Object[] objs = AssetDatabase.LoadAllAssetsAtPath(file);
    6.             foreach (UnityEngine.Object obj in objs) {
    7.                 if (obj.GetType() == theType) {
    8.                     if (obj.GetType() != typeof(Texture2D) || (obj.GetType() == typeof(Texture2D)  obj.name != "Preview Texture")) // Isn't there a better way to do this?     
    9.                         list.Add(obj);
    10.                 }
    11.             }
    12.         }
    13.        
    14.         foreach (string directory in Directory.GetDirectories(folderPath)) {
    15.             GatherAssetsRecursivelyAtPath(directory, theType, list);
    16.         }
    17.        
    18.         return list;
    19.     }
    20.  
    When I load up all Texture2D at a path, I get the preview textures along with it. That'd be all fine and good if I wanted them, but in this case I don't. Is there a non-hacky way to skip them?

    The specific line I'm referring to is the one commented "Isn't there a better way to do this?"

    Thanks,
    -Jon