- Home /
C# Problem Creating List of Texture2Ds
Hi everyone. I'm trying to create a generic list of texture2Ds using the function AssetPreview.GetAssetPreview to create the images. Ive checked this function to see if it properly returns a preview of an asset, which it does, but when i try to use it in a foreach loop, it starts acting up. It populates the the list, but leaves many of the slots with blank images. And everytime i generate the list, different slot are left blank.
Any help would be greatly appreciated, I've been trying to find a solution for ever d:
Heres the code btw.
Create a list of prefabs:
public static void PrefabListCreator(){
PrefabList.Clear();
DirectoryInfo PrefabDi = new DirectoryInfo(PrefabPath);
FileInfo[] PrefabFi = PrefabDi.GetFiles(); //Array Of Files At Directory
foreach(FileInfo Fi in PrefabFi){ //For Each File In Array Of files
GameObject newgameobject = (GameObject)AssetDatabase.LoadAssetAtPath(PrefabPath + "/" + Fi.Name,typeof (GameObject)); // Create new Game Object, Equals File Fi From Array
if(Fi.Name.Contains(".meta")){ //Skip Meta Files
}
else{
PrefabList.Add(newgameobject); // Add Object To PrefabList
}
}
PrefabPreviewListCreator(); // Fires the function below
}
Create a list of assetpreviews using the prefab list:
public static void PrefabPreviewListCreator(){
PrefabPreviews.Clear(); //Clears the list were using to start from scratch
foreach(GameObject GO in PrefabList){ // for each game object in the prefab list
Texture2D assetPreview = AssetPreview.GetAssetPreview(GO); //create asset preview
PrefabPreviews.Add(assetPreview); //add preview to list
Debug.Log(GO.name + " " + "was added to previews, index -" + " " );
}
}
I then just plug the asset preview list into the function GUI.SelectionGrid to create the grid of images.
Your answer
Follow this Question
Related Questions
C# List foreach problem 1 Answer
How do you interate through a JSON object with a foreach loop to add each element to a list? 0 Answers
Iterating through nulls in legacy-style Animation component 0 Answers
foreach a array inside a generic list 1 Answer
How can I use foreach and a list of vector3s to reset the positions of all child objects? 1 Answer