LoadAssetAtPath 与 Load 的区别
一、官方的文档
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 的区别的更多相关文章
- Hibernate中session.get()和session.load()的区别
-- 翻译自https://www.mkyong.com/hibernate/different-between-session-get-and-session-load/ 很多时候你会发现,使用Hi ...
- Get和Load的区别----hibernate
Get和Load的区别
- Hibernate的Session的get()和load()方法区别
hibernate中Session接口提供的get()和load()方法都是用来获取一个实体对象,在使用方式和查询性能上有一些区别. get Session接口提供了4个重载的get方法,分别通过“持 ...
- 【转载】DOMContentLoaded与load的区别
DOMContentLoaded与load的区别 (1)在chrome浏览器的开发过程中,我们会看到network面板中有这两个数值,分别对应网 络请求上的标志线,这两个时间数值分别代表什么? ( ...
- ready与load的区别
JQuery里有ready和load事件 $(document).ready(function() { // ...代码... }) //document ready 简写 $(function() ...
- hibernate延迟加载(get和load的区别)
概要: 在hibernate中我们知道如果要从数据库中得到一个对象,通常有两种方式,一种是通过session.get()方法,另一种就是通过session.load()方法,然后其实这两种方法在获得一 ...
- jQuery document window load ready 区别详解
用过JavaScript的童鞋,应该知道window对象和document对象,也应该听说过load事件和ready事件,小菜当然也知道,而且自认为很了解,直到最近出了问题,才知道事情并不是那么简单. ...
- body里面的onload和window.onload,window.load的区别
区别:body里面的onload是在“页面加载完成后执行的动作”window里面的onload是在“页面加载时执行的动作” window.load这个应该只是表明事件方法,但并未执行,比如click表 ...
- Hibernate中get()和load()方法区别
get和load方式是根据id取得一个记录下边详细说一下get和load的不同,因为有些时候为了对比也会把find加进来. 1.从返回结果上对比:load方式检索不到的话会抛出org.hibernat ...
随机推荐
- 直播开始:'云榨汁机'诞生记--聊聊JavaScript中的'业务建模'
闭包是JavaScript中的一个重要特性,在之前的博文中,我们说闭包是一个'看似简单,其实很有内涵'的特性.当我们用JavaScript来实现相对复杂的业务建模时,我们可以如何利用'闭包'这个特性呢 ...
- nyoj_t218(Dinner)
描述 Little A is one member of ACM team. He had just won the gold in World Final. To celebrate, he dec ...
- 网站如何提高PR值
做了站长这些年,积累些经验,记录下来,分享兄弟. 一.商城类型网站 对于商城型的网站站内优化来说,主要是用户咨询和浏览产品时产生的疑问.比如当某用户看到一些自己感兴趣的产品需要咨询的时候,自然就会寻找 ...
- RHEL(RedHat Enterprise Linux)5/6 ISO镜像下载
本文贴出了RHEL(RedHat Enterprise Linux)发行版本中常用的服务器版本的ISO镜像文件,供大家下载学习使用,贴出的版本有RedHat Enterprise Linux(RHEL ...
- WinForm TreeView节点重绘,失去焦点的高亮显示
当用户焦点离开TreeView时,TreeView选中节点仍然高亮,但是颜色符合主题. 设置TreeView.HideSelection = False;可让选中节点保持高亮. 添加重绘事件 Tree ...
- UINavigationController 与 UITabBarController
http://www.cnblogs.com/YouXianMing/p/3756904.html // index start from 1. UITabBarItem *newsItem = [[ ...
- Unable to load DLL 'rasapi32.dll': 动态链接库(DLL)初始化例程失败。
今天做项目传到服务器上碰到下面的问题 但是在本地VS中运行又没问题 后经上网搜索发现只要在web.config文件中加入如下代码即可解决 <system.net> <defa ...
- JavaScript 中的 replace 方法
定义和用法 replace() 方法用于在字符串中用一些字符替换另一些字符,或替换一个与正则表达式匹配的子串. stringObject.replace(regexp/substr,replaceme ...
- JAVA多线程学习1
一.进程与线程 线程是指进程内的一个执行单元(可理解为程序内的一条执行路径),也是进程内的可调度实体. 线程与进程的区别: 1.线程是进程的一个执行单元,一个进程可以拥有多个线程,线程之间共享进程的地 ...
- CentOS 普通用户设置sudo权限
1.先切换到root用户下,输入命令 su 2.添加sudo文件的写权限,命令是: chmod u+w /etc/sudoers 3.编辑sudoers文件 vi /etc/sudoers 找到 ro ...