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 ...
随机推荐
- Coarse-Grained lock 粗粒度锁
用一个锁Lock一组相关的对象 有时,需要按组来修改多个对象. 这样,在需要锁住其中一个的时候,必须连带地将其他的对象都上锁. 为每一个对象都加上一个锁是很繁琐的. 粗粒度锁是覆盖多个对象的单个锁. ...
- 10款让人惊叹的HTML5/jQuery图片动画特效
1.HTML5相册照片浏览器 可连接Flickr照片服务 以前我们经常会分享一些jQuery相册浏览插件,效果不错,实用性也很强.不过如果能利用HTML5来实现相册浏览器,那么相册浏览效果肯定会更加炫 ...
- 【MediaKit】WPF项目中 调用摄像头拍照的开发包
今天遇到一个 人事的项目,项目中需要调用摄像头给员工照相.如何解决这个问题呢? 介绍一个开发包给你,MediaKit.论坛里头的人都说好,但是黑兔觉得大家好才是真的好.你不妨试试~ 第一步:添加WPF ...
- c++11:function的用法
function是函数.函数对象.函数指针.和成员函数的包装器,可以容纳任何类型的函数对象,函数指针,引用函数,成员函数的指针 普通函数 #include <functional> voi ...
- 实现textarea自适应的方法
1.用div来模拟实现textarea自适应 <!doctype html> <html lang="en"> <head> <meta ...
- ios 控件
反序列化 JSONModel 上拉刷新 下拉加载更多 MJRefresh AFNetworking 2.5 Asynchronous image downloader with cache - SDW ...
- 节点属性(DOM对象)
节点属性 在文档对象模型 (DOM) 中,每个节点都是一个对象.DOM 节点有三个重要的属性 : 1. nodeName : 节点的名称 2. nodeValue :节点的值 3. nodeType ...
- spring中controller
提示:原网站已由百度转码,以便在移动设备上查看. 第七城市 (Portal 开发读书笔记)Spring Portlet MVC 测试Controller 2012-04-28 16:32:44 - - ...
- sql中的系统表sysobjects以及如何查看sql语句的执行时间
使用sysobjects可以快速查看数据库中表.视图.存储过程.触发器.约束等的信息. 大牛文章:http://www.cnblogs.com/atree/p/SQL-Server-sysobject ...
- 《零成本实现Web自动化测试--基于Selenium》 第四章 Selenium 命令
Selenium 命令,通常被称为Selenese,由一系列运行测试案例所需要的命令构成.按顺序排列这些命令就构成了测试脚本. 一. 验证颜面元素 1.Assertion或者Verification ...