打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
unity3d 根据指定的Assets下的文件夹路径 返回这个路径下的所有文件名,unity3dassets

unity3d 根据指定的Assets下的文件夹路径 返回这个路径下的所有文件名,unity3dassets


 

using UnityEngine;using System.Collections;using System.Collections.Generic;using System.IO;
<pre class="csharp" name="code">	public static List<string> nameArray = new List<string>();

	/// <summary>	/// 根据指定的 Assets下的文件路径 返回这个路径下的所有文件名//	/// </summary>	/// <returns>文件名数组</returns>	/// <param name="path">Assets下“一"级路径</param>	/// <param name="pattern">筛选文件后缀名的条件.</param>	/// <typeparam name="T">函数模板的类型名t</typeparam>	void GetObjectNameToArray<T>(string path, string pattern)	{   		string objPath = Application.dataPath + "/" + path;  		string[] directoryEntries;  		try   		{  			//返回指定的目录中文件和子目录的名称的数组或空数组			directoryEntries = System.IO.Directory.GetFileSystemEntries(objPath);   			for(int i = 0; i < directoryEntries.Length ; i ++){  				string p = directoryEntries[i];  				//得到要求目录下的文件或者文件夹(一级的)//				string[] tempPaths = StringExtention.SplitWithString(p,"/Assets/"+path+"\\"); 							//tempPaths 分割后的不可能为空,只要directoryEntries不为空//				if(tempPaths[1].EndsWith(".meta"))					continue;				string[] pathSplit = StringExtention.SplitWithString(tempPaths[1],".");  				//文件				if(pathSplit.Length > 1)				{  					nameArray.Add(pathSplit[0]); 				}				//遍历子目录下 递归吧!				else				{					GetObjectNameToArray<T> (path+"/"+pathSplit[0], "pattern");						continue;				}			} 		}  		catch (System.IO.DirectoryNotFoundException)   		{  			Debug.Log("The path encapsulated in the " + objPath + "Directory object does not exist.");  		} 	}  
	void Start () {		//TextAsset[] texts = LoadAsset<TextAsset> ("/CreateScriptDialog/Editor", "cs");		//GetObjectNameToArray<string> ("uSequencer/Example Scenes", "xxx");   //可以实现嵌套遍历		GetObjectNameToArray<string> ("uSequencer", "xxx");   //可以实现嵌套遍历		foreach (string str in nameArray) {			Debug.Log(str);		}	}
 
<pre class="csharp" name="code">/// <summary>/// 自定义的字符串分割的方法/// </summary>public class StringExtention {  	public static string[] SplitWithString(string sourceString, string splitString){		string tempSourceString = sourceString;		List<string> arrayList = new List<string>();  		string s = string.Empty;  		while (sourceString.IndexOf(splitString) > -1)  //分割		{  			s = sourceString.Substring(0, sourceString.IndexOf(splitString));  			sourceString = sourceString.Substring(sourceString.IndexOf(splitString) + splitString.Length);  			arrayList.Add(s);  		} 		arrayList.Add(sourceString); 		return arrayList.ToArray();  	}  } 




怎获取assets文件夹的路径??

InputStream inStream = context.getAssets().open("assets下的路径(不包含assets)/文件名");
 

Unity3D 4x C#脚本怎读取Resources目录下所有文件的文件名

无法读取,Unity没有提供这个功能。你可以建立一个list文件,里面记录所有文件的文件名,然后用Resources.load来读取这个文件来获得所有文件的文件名。我觉得你需要的遍历文件名功能,可能这个函数能用的上Resources.FindObjectsOfTypeAll,列出某种类型的所有Object
 

原文地址:http://www.bkjia.com/Androidjc/899403.html

 
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
【新提醒】【Unity实用小工具或脚本
delphi删除文件和文件夹
使用AdMob
Unity5 如何做资源管理和增量更新
【Unity&DragonBones】DragonBones运行库导入Unity工程文件详细教程以及解决办法
Unity3d资源反编译(DisUnity)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服