There are a lot of pictures in the folder, all of them are. png format, if one of the dragged to the script feel very troublesome, wrote a traverse added cars, variable is list<sprite>
The code is as Follows:
usingunityengine;usingsystem.io;usingSystem.Collections.Generic; public classnewbehaviourscript:monobehaviour{PrivateList<texture> cars =NewList<texture>(); voidStart () {getcarimage (); } public voidgetcarimage () {stringPath = Application.datapath +"/resources/car/"; if(directory.exists (path)) {//Get file InformationDirectoryInfo Direction =NewDirectoryInfo (path); fileinfo[] Files= Direction. GetFiles ("*", searchoption.alldirectories); Print (files. Length); for(inti =0; I < Files. Length; i++) { //filter out temporary files if(files[i]. Name.endswith (". Meta")) { Continue; } Print (files[i]. Extension); //This is a name extension//get a file name without an extension stringName =path.getfilenamewithoutextension (files[i]. ToString ()); Print (name); //Fileinfo.name is the name returned with the extensionCars. ADD ((Texture) Resources.load ("car/"+ name,typeof(Sprite))); } } }}
Unity gets the number of files of a specified type under a folder