一、官方的文档

  

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. UI1_UIScrollView

    // // AppDelegate.m // UI1_UIScrollView // // Created by zhangxueming on 15/7/10. // Copyright (c) 2 ...

  2. 卸载Linux内置的AMP软件

    卸载Linux内置的AMP软件 在安装Linux软件的LAMP环境时,必须有一个前提:必须要完全卸载掉系统内置的AMP软件. 1.卸载httpd软件(Apache) 如果在卸载软件时出现依赖关系,我们 ...

  3. oracle 数据库导入导出

    要把公司的数据库导入到自己的电脑上(都需要再命令窗口下输入指令) 导出数据库的基本代码: exp zj_user_kf/oracle@tzsw_4 file=d:\test3.dmp full=y 导 ...

  4. 洛谷 P3368 【模板】树状数组 2

    题目描述 如题,已知一个数列,你需要进行下面两种操作: 1.将某区间每一个数数加上x 2.求出某一个数的和 输入输出格式 输入格式: 第一行包含两个整数N.M,分别表示该数列数字的个数和操作的总个数. ...

  5. POJ1056 IMMEDIATE DECODABILITY【数据结构】

    题目地址:http://poj.org/problem?id=1056 Description An encoding of a set of symbols is said to be immedi ...

  6. SNRO:Number Range

    业务对象是在一定的编号范围内分配编号的,编号既可以是内部分配也可以是外部分配.对于外部分配,用户输入编号,系统检查这个编号是否被占用.对于内部分配,系统会自动的把编号分配给业务对象.所以内部分配和外部 ...

  7. Windows Phone 中查找可视化树中的某个类型的元素

    private void StackPanel_Tap(object sender, TappedRoutedEventArgs e) { //获取到的对象是ListBoxItem ListBoxIt ...

  8. Android listview viewpager解决冲突 滑动

    Android listview viewpager滑动 跳动 冲突解决 ListView中嵌套ViewPage有或者滑动手势冲突解决   在listview 上使用 addHeaderView 在第 ...

  9. js实现复制到剪切板

    // <![CDATA[ function copy_clip(copy) { if (window.clipboardData) { window.clipboardData.setData( ...

  10. Oracle RAC Failover

    Oracle  RAC 同时具备HA(High Availiablity) 和LB(LoadBalance). 而其高可用性的基础就是Failover(故障转移). 它指集群中任何一个节点的故障都不会 ...