Created
July 25, 2018 03:26
-
-
Save yangruihan/7bc04f859d54dec032e8fcbfe73dd0f7 to your computer and use it in GitHub Desktop.
Unity Editor 获得某一目录下所有Prefab
This file contains hidden or 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
| public static List<GameObject> LoadDirectoryPrefab(string rootPath) | |
| { | |
| var dictoryInfo = new DirectoryInfo(rootPath); | |
| if (!dictoryInfo.Exists) return null; | |
| var ret = new List<GameObject>(); | |
| FileInfo[] fileInfos = dictoryInfo.GetFiles("*.prefab", SearchOption.AllDirectories); | |
| EditorUtility.DisplayProgressBar("加载Prefab中...", "开始加载", 0f); | |
| int i = 0; | |
| foreach (FileInfo files in fileInfos) | |
| { | |
| string path = files.FullName; | |
| #if UNITY_STANDALONE_WIN | |
| string assetPath = path.Substring(path.IndexOf("Assets\\")); | |
| #else | |
| string assetPath = path.Substring(path.IndexOf("Assets/")); | |
| #endif | |
| EditorUtility.DisplayProgressBar("加载Prefab中...", assetPath, ++i * 1.0f / fileInfos.Length); | |
| GameObject prefab = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath); | |
| ret.Add(prefab); | |
| } | |
| EditorUtility.ClearProgressBar(); | |
| return ret; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment