Unity gets the number of files of a specified type under a folder

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.