博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LoadAssetAtPath 与 Load 的区别
阅读量:6909 次
发布时间:2019-06-27

本文共 3736 字,大约阅读时间需要 12 分钟。

一、官方的文档 

  

Resources.LoadAssetAtPathReturns 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 onlyResources.LoadLoads 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

 上面已经解释的很清楚了,接下来我做个实验来验证一下。

 

二、试验代码

1 public enum UpDecorationEnum 2 { 3     Flower_Category1, 4     Olive_Category2, 5     Man_Category3, 6     Woman_Category4 7 } 8  9 void UnitTest()10 {11     Random_Sprite_SpecificEnum(UpDecorationEnum.Flower_Category1);12 }13 14 public static void Random_Sprite_SpecificEnum(UpDecorationEnum specific)15 {16     string DataPath = Application.dataPath17     + "/Resources/Environment/Line_Up/Up/" + specific.ToString();18 19     DirectoryInfo directoryinfo = new DirectoryInfo(DataPath);20 21     FileInfo[] fileinfo = directoryinfo.GetFiles("*.png");22 23     List
list = new List
();24 foreach (var item in fileinfo)25 {26 //Window Editor27 // Flower@sprite.png28 //Debug.Log(item.Name);29 30 // E:\Unity3D Project\MenSa_Academy_2\Client\MenSa_Academy31 // \Assets\Resources\Environment\Line_Up\Up\Flower_Category1\Flower@sprite.png32 //Debug.Log(item.FullName);33 34 // Assets\Resources\Environment\Line_Up\Up\Flower_Category1\Flower@sprite.png35 //Debug.Log(DataPathToAssetPath(item.FullName));36 37 38 // Environment/Line_Up/Up/Flower_Category1/Flower@sprite39 // Debug.Log(DataPathToResourcesPath(item.FullName));40 41 42 /// 这个在android 下 是 不行的 使用 DataPathToAssetPath 下面两种都是可以的43 // Assets\Resources\Environment\Line_Up\Up\Flower_Category1\Flower@sprite.png44 // Assets/Resources/Environment/Line_Up/Up/Flower_Category1/Flower@sprite.png45 //Sprite tmp = Resources.LoadAssetAtPath
(DataPathToAssetPath(item.FullName));46 47 /// 全平台适用 只能使用 DataPathToResourcesPath1路径48 Sprite tmp = Resources.Load
(DataPathToResourcesPath(item.FullName)); 49 50 if (tmp == null) Debug.Log("Null");51 else list.Add(tmp);52 }53 Debug.Log("Random_Sprite_SpecificEnum" + list.Count);54 }55 56 public static string DataPathToAssetPath(string path)57 {58 if (Application.platform == RuntimePlatform.WindowsEditor)59 return path.Substring(path.IndexOf("Assets\\"));60 else61 return path.Substring(path.IndexOf("Assets/"));62 }63 64 public static string DataPathToResourcesPath(string path)65 {66 // E:\Unity3D Project\MenSa_Academy_2\Client\MenSa_Academy67 // \Assets\Resources\Environment\Line_Up\Up\Flower_Category1\Flower@sprite.png68 if (Application.platform == RuntimePlatform.WindowsEditor){69 // Environment\Line_Up\Up\Flower_Category1\Flower@sprite.png70 string result = path.Substring(path.IndexOf("Environment\\"));71 72 // Environment/Line_Up/Up/Flower_Category1/Flower@sprite.png73 string result1 = result.Replace("\\","/");74 75 // Environment/Line_Up/Up/Flower_Category1/Flower@sprite76 int index = result1.LastIndexOf('.');77 string result2 = result1.Substring(0, index);78 79 return result2;80 81 }82 83 else84 return path.Substring(path.IndexOf("Environment/"));85 }

 

转载于:https://www.cnblogs.com/chongxin/p/4098055.html

你可能感兴趣的文章
openstack学习笔记二 网络设置基础
查看>>
RabbitMQ基础
查看>>
有了安全边界,人工智能才能有序发展
查看>>
Qt在mainwindow下代码添加控件不能显示的问题
查看>>
【cocos2dx】使用VS插件在VS2012/2013上编辑和调试Quick-Cocos2d-x的Lua代码
查看>>
Centos6.0之pptpd+mysql+freeradius实现***帐号统一认证管理
查看>>
Excel导出数据
查看>>
解释Windows7“上帝模式”的原理
查看>>
httpClient4.* 使用教程
查看>>
相对和绝对路径、cd命令、创建和删除目录mkdir/rmdir 、rm命令
查看>>
yum安装配置nagios
查看>>
linux下Bash局部变量及信号捕捉等概念解释
查看>>
HTML5 input placeholder 颜色修改示例css
查看>>
cacti-0.8.8c 下安装realtime插件
查看>>
我的友情链接
查看>>
从0开始学大数据-Java基础开篇(1)
查看>>
github常用命令总结(一)
查看>>
Intent(意图)
查看>>
Exchange Server 2007迁移Exchange Server 2010 (2) ---前期准备之二
查看>>
翻译:Fast dynamic extracted honeypots in cloud computing --5.CONCLUSION
查看>>