LoadAssetAtPath 与 Load 的区别
2014-11-14 19:55
155 查看
一、官方的文档
上面已经解释的很清楚了,接下来我做个实验来验证一下。
二、试验代码
Resources.LoadAssetAtPath Returns a resource at an asset path (Editor Only). This function always return null in the standalone player or web player. This is useful for quickly accessing an asset for use in the editor only Resources.Load Loads an asset stored at path in a Resources folder. Returns the asset at path if it can be found otherwise returns null. Only objects of type will be returned if this parameter is supplied. The path is relative to any Resources folder inside the Assets folder of your project, extensions must be omitted
上面已经解释的很清楚了,接下来我做个实验来验证一下。
二、试验代码
public enum UpDecorationEnum { Flower_Category1, Olive_Category2, Man_Category3, Woman_Category4 } void UnitTest() { Random_Sprite_SpecificEnum(UpDecorationEnum.Flower_Category1); } public static void Random_Sprite_SpecificEnum(UpDecorationEnum specific) { string DataPath = Application.dataPath + "/Resources/Environment/Line_Up/Up/" + specific.ToString(); DirectoryInfo directoryinfo = new DirectoryInfo(DataPath); FileInfo[] fileinfo = directoryinfo.GetFiles("*.png"); List<Sprite> list = new List<Sprite>(); foreach (var item in fileinfo) { //Window Editor // Flower@sprite.png //Debug.Log(item.Name); // E:\Unity3D Project\MenSa_Academy_2\Client\MenSa_Academy // \Assets\Resources\Environment\Line_Up\Up\Flower_Category1\Flower@sprite.png //Debug.Log(item.FullName); // Assets\Resources\Environment\Line_Up\Up\Flower_Category1\Flower@sprite.png //Debug.Log(DataPathToAssetPath(item.FullName)); // Environment/Line_Up/Up/Flower_Category1/Flower@sprite // Debug.Log(DataPathToResourcesPath(item.FullName)); /// 这个在android 下 是 不行的 使用 DataPathToAssetPath 下面两种都是可以的 // Assets\Resources\Environment\Line_Up\Up\Flower_Category1\Flower@sprite.png // Assets/Resources/Environment/Line_Up/Up/Flower_Category1/Flower@sprite.png //Sprite tmp = Resources.LoadAssetAtPath<Sprite>(DataPathToAssetPath(item.FullName)); /// 全平台适用 只能使用 DataPathToResourcesPath1路径 Sprite tmp = Resources.Load<Sprite>(DataPathToResourcesPath(item.FullName)); if (tmp == null) Debug.Log("Null"); else list.Add(tmp); } Debug.Log("Random_Sprite_SpecificEnum" + list.Count); } public static string DataPathToAssetPath(string path) { if (Application.platform == RuntimePlatform.WindowsEditor) return path.Substring(path.IndexOf("Assets\\")); else return path.Substring(path.IndexOf("Assets/")); } public static string DataPathToResourcesPath(string path) { // E:\Unity3D Project\MenSa_Academy_2\Client\MenSa_Academy // \Assets\Resources\Environment\Line_Up\Up\Flower_Category1\Flower@sprite.png if (Application.platform == RuntimePlatform.WindowsEditor){ // Environment\Line_Up\Up\Flower_Category1\Flower@sprite.png string result = path.Substring(path.IndexOf("Environment\\")); // Environment/Line_Up/Up/Flower_Category1/Flower@sprite.png string result1 = result.Replace("\\","/"); // Environment/Line_Up/Up/Flower_Category1/Flower@sprite int index = result1.LastIndexOf('.'); string result2 = result1.Substring(0, index); return result2; } else return path.Substring(path.IndexOf("Environment/")); }
相关文章推荐
- 关于Resources.LoadAssetAtPath
- Resources.Load 与 Resources.LoadAssetAtPath 注意
- Failed to load Info.plist from bundle at path /.....
- NSFileManager的subpathsAtPath:和contentsOfDirectoryAtPath:error:的相同点和区别
- Failed to load Info.plist from bundle at path
- Unity中 动态加载 Resources.Load()和Asset Bundle 的区别
- Unity AssetImporter.GetAtPath 用法
- hibernate持久化方法get和load的区别
- ActiveReport提示cann't load path,不能刷新数据
- Hibernate中关于get()和load()方法检索的区别
- 用DropDownList+ObjectDataSource在Page_Load中SelectedIndex和SelectedValue的区别
- hibernate中load,get;find,iterator;merge,saveOrUpdate,lock的区别
- how to load XNA contents at runtime
- java.io.File 中 getPath(), getAbsolutePath() 和 getCanonicalPath() 三个方法的区别
- Adding Library or Classpath at runtime
- 0day-java load dynamic library from any path(java加载任意目录库文件)
- Hibernate 中 get与load方法区别
- AT&T与INTEL的汇编语言语法的区别
- Page_LoadComplete和Page_Load有区别吗
- File中的属性nativePath跟url的区别