Created
April 16, 2012 09:43
-
-
Save fum1h1ro/2397362 to your computer and use it in GitHub Desktop.
Assetsフォルダのファイル一覧を取得する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
using System; | |
using System.IO; | |
// Assetsフォルダ以下を見てファイルを取得する系 | |
public class AssetDir { | |
public static string[] GetFiles(string path) { | |
string[] rawfiles = Directory.GetFiles(MakePath(path)); | |
string[] files = new string[rawfiles.Length]; | |
int idx = 0; | |
foreach (string s in rawfiles) | |
files[idx++] = Path.GetFileName(s); | |
return FilterIgnoreEntries(files); | |
} | |
// extに拡張子を与えると該当するファイルのみ取得します | |
// 拡張子リストを | で区切ると複数指定できます -> ".fbx|.prefab" | |
public static string[] GetFiles(string path, string ext) { | |
string[] files = GetFiles(path); | |
ext = ext.ToLower(); | |
string[] exts = ext.Split('|'); | |
string[] filtered = | |
Array.FindAll(files, | |
delegate(string name) { | |
return | |
Array.IndexOf(exts, Path.GetExtension(name).ToLower()) >= 0; | |
}); | |
return filtered; | |
} | |
private static string MakePath(string path) { | |
return Application.dataPath + "/" + path; | |
} | |
private static string[] FilterIgnoreEntries(string[] files) { | |
return | |
Array.FindAll(files, | |
delegate(string name) { | |
return | |
Path.GetFileName(name).IndexOf('.') != 0 && | |
Path.GetExtension(name).ToLower() != ".meta"; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ファイル名のみにしてみた