一、官方的文档

  

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(, index); return result2; } else
return path.Substring(path.IndexOf("Environment/"));
}

LoadAssetAtPath 与 Load 的区别的更多相关文章

  1. Hibernate中session.get()和session.load()的区别

    -- 翻译自https://www.mkyong.com/hibernate/different-between-session-get-and-session-load/ 很多时候你会发现,使用Hi ...

  2. Get和Load的区别----hibernate

    Get和Load的区别

  3. Hibernate的Session的get()和load()方法区别

    hibernate中Session接口提供的get()和load()方法都是用来获取一个实体对象,在使用方式和查询性能上有一些区别. get Session接口提供了4个重载的get方法,分别通过“持 ...

  4. 【转载】DOMContentLoaded与load的区别

    DOMContentLoaded与load的区别   (1)在chrome浏览器的开发过程中,我们会看到network面板中有这两个数值,分别对应网 络请求上的标志线,这两个时间数值分别代表什么? ( ...

  5. ready与load的区别

    JQuery里有ready和load事件 $(document).ready(function() { // ...代码... }) //document ready 简写 $(function() ...

  6. hibernate延迟加载(get和load的区别)

    概要: 在hibernate中我们知道如果要从数据库中得到一个对象,通常有两种方式,一种是通过session.get()方法,另一种就是通过session.load()方法,然后其实这两种方法在获得一 ...

  7. jQuery document window load ready 区别详解

    用过JavaScript的童鞋,应该知道window对象和document对象,也应该听说过load事件和ready事件,小菜当然也知道,而且自认为很了解,直到最近出了问题,才知道事情并不是那么简单. ...

  8. body里面的onload和window.onload,window.load的区别

    区别:body里面的onload是在“页面加载完成后执行的动作”window里面的onload是在“页面加载时执行的动作” window.load这个应该只是表明事件方法,但并未执行,比如click表 ...

  9. Hibernate中get()和load()方法区别

    get和load方式是根据id取得一个记录下边详细说一下get和load的不同,因为有些时候为了对比也会把find加进来. 1.从返回结果上对比:load方式检索不到的话会抛出org.hibernat ...

随机推荐

  1. 修改 timezone

    1.通过命令修改 1.Set Time, Date Timezone in Linux from Command Line or Gnome | Use ntp 2.Use TZ database 3 ...

  2. Android下各个按键对应的key code

    KEYCODE_UNKNOWN=0; KEYCODE_SOFT_LEFT=1; KEYCODE_SOFT_RIGHT=2; KEYCODE_HOME=3; KEYCODE_BACK=4; KEYCOD ...

  3. bootstrap时间插件 火狐不显示 完美解决方法

    原文链接:http://www.phpbiji.cn/article/index/id/141/cid/4.html bootstrap时间插件火狐 bootstrap-datetimepicker火 ...

  4. VIM小技巧之文件名补全

    恩,这两天在看<简明Python教程>,那里面作者建议写代码的时候前面的注释写上文件名,写上调用的解释器,比如这样: 恩,然后我当然不可能每回新建一个文件,就要在开头写上一大串东西啊,vi ...

  5. OpenSSL 安全漏洞: heartbleed

    Heartbleed 是 2014年4月7日被广泛报道的一个 OpenSSL 安全漏洞,号称是灾难. 利用它能读取服务器上最多64k的内存,只要该服务器可以通过ssl连接.   Heartbleed ...

  6. Silverlight中嵌套html、swf、pdf

    1.MainPage.xaml <UserControl x:Class="SilverlightClient.MainPage" xmlns="http://sc ...

  7. WordPress 主题开发 - (五)WordPress 主题模板及目录结构 待翻译

    While the most minimal of WordPress Themes really only need an index.php template and a style.css fi ...

  8. mysql手工注入

    以下是mynona本人原创的,奉献给大家,不要小看数据库注入 参考: http://www.daydaydata.com/help/sql/advance/limit.html http://www. ...

  9. Oracle 10g RAC 启动与关闭

    一. 检查共享设备 一般情况下,存放OCR和Voting Disk的OCFS2 或者raw 都是自动启动的. 如果他们没有启动,RAC 肯定是启动不了. 1.1 如果使用ocfs2的 检查ocfs2 ...

  10. RDD的转换操作---RDD转换过程

    1) union(otherRDD)RDD-->UnionRDD2) groupByKey(numPartitions)RDD-->ShuffledRDD-->MapPartitio ...