Scan to get the full file path. This simple thing has caused me to do it for two days. I first looked at resources and then assetbundle and www. Later I was surprised to see editorutility. openfilepanel.,
But still notRight. Finally, the experts said C # could solve this problem. I went to view C # And read the file class first. Then I saw the Directory class and finally understood that
YesDirectory. getfiles (Path: string ),Directory. getfiles (Path: String, pattern: string) and directory. getfiles (Path: String, pattern: String, searchoption)
Get files in three pathsPath Method. both the first and second methods can run, but the third method can work on a computer (except a system disk, it cannot run on a mobile phone ~~~~, What should I do?
No way. There is another one in C #.Directory. getdirectories (Path: string) is used to obtain the sub-directory in the path. Therefore, I wrote a recursive function. Although it still does not work on the system disk, it achieves the desired effect on the mobile phone.
import system. io; import system. collections; var www: WWW; var files: String []; var file: arraylist; function start () {file = new arraylist (); he ("/sdcard /", "*. PNG ", file); print (file. count);} function Update () {If (input. getkey (keycode. escape) {application. quit () ;}} function ongui () {GUI. label (rect (100,100,100,100), file. count + "----" + files. length);} function he (Path: strin G, pattern: String, Al: arraylist) {// if Al uses string [], an error is returned, indicating that your array is not large enough, so I use arraylist if (path! = NULL) {var F1: String [] = directory. getfiles (path, pattern); For (VAR F11: String in F1) {Al. add (F11);} var D1: String [] = directory. getdirectories (PATH); For (VAR D11: String in D1) {var F2: String [] = directory. getfiles (D11, pattern); For (VAR f22: String in F2) {Al. add (f22) ;}he (D11, pattern, Al) ;}}
Sorry, the above content was written yesterday. I tried it on the mobile phone and the system disk, but it still didn't work. I threw an exception and finally got it done with try-catch. belowCodeYou can run:
Function he (Path: String, pattern: String, Al: arraylist) {If (path! = NULL) {var F1: String [] = directory. getfiles (path, pattern); var D1: String []; for (VAR F11: String in F1) {Al. add (F11);} Try {d1 = directory. getdirectories (PATH); For (VAR D11: String in D1) {try {he (D11, pattern, Al);} catch (exception) {}} catch (exception) {}}}
Unity3d is really nice ~~~~, Although I am used to writing code with JS, all C # functions can be used in Js ~~~~, Msdn is also very good. Thank you ~~~~~