版本 |
作者 |
参与者 |
完成日期 |
备注 |
UnityAPI_Resources_V01_1.0 |
严立钻 |
|
2020.06.17 |
|
|
|
|
|
|
立钻哥哥:Unity是一个入门快、提高难的游戏引擎,想要提升能力,至少需要越过3道坎:API+Shader+综合能力;++1、API的积累:对API的合理利用不仅可以减轻自己的编码负担,而且往往可以提高程序的运行效率;这也是钻哥开始“Unity API”独立打造分类的初衷; ++2、Shader编程:想要做出一款精品游戏往往需要有高效的Shader的支持;Unity提供了一套改良的“Shader Lab”系统,优化了繁杂的“Open GL”编程; ++3、综合能力(技术+业务+管理):一款产品的制作除了功能编程外,往往会涉及很多其他领域,例如产品架构、UI交互设计、模型制作等,作为主要的编程人员,对其他相关领域的了解程序往往会影响到产品制作直至最后的产品体验; ++++立钻哥哥一直在推动【VR云游戏=Unity+SteamVR+云技术+5G+AI】,这个只是一个引子,抛砖引玉让大家对整个知识体系有一个明确的落地方向,宝宝们可以根据自己的兴趣方向进行拓展:比如Unity这里是指一种“3D游戏引擎”,也可拓展至“UE4、Cocos2dx”等游戏引擎;SteamVR是一种跨硬件解决方案,也可拓展至“VRTK”等第三方插件;“云技术+5G”是一种跨平台解决方案的核心技术,同样可拓展至其他平台解决方案;AI也是一种先进技术的举例,也可以拓展至任何一种前沿技术; |
++++【Unity API】分类:https://blog.csdn.net/vrunsoftyanlz/category_7637520.html
++++【Unity开发基础】分类:https://blog.csdn.net/vrunsoftyanlz/category_7309057.html
++++【Linux系统编程】分类:https://blog.csdn.net/vrunsoftyanlz/category_9694767.html
++++【C++C铸就生存利器】分类:https://blog.csdn.net/vrunsoftyanlz/category_9325802.html
++++【人工智能AI2026】分类:https://blog.csdn.net/vrunsoftyanlz/category_9212024.html
++++【立钻哥哥CSDN空间】:https://blog.csdn.net/VRunSoftYanlz/
#Resources资源 |
#Resources资源++A1、Description描述++B2、Variables变量++C3、Public Function共有函数++D4、Message消息 |
#A1、Description描述 |
++++在编辑器,Resources.FindObjectsOfTypeAll能用来定位资源和场景对象;
++++所有资源必须在项目Assets文件内的任意Resources文件夹中,可以通过Resources.Load访问;允许有多个Resources文件夹,每次加载对象是会自动检查;
++++在Unity中通常不需要使用路径名来访问资源,相反可以通过声明一个成员变量来暴露一个资源的引用,然后在检视面板中指定它;使用这个技巧的时候Unity可以在构建的时候自动计算哪个资源被使用;这从根本上最大限度地减少了实际用于游戏的资源的尺寸;当资源在“Resources”文件夹中时,所有在“Resources”文件夹中的资源都将被打包编译包含在游戏中;
++++另一个使用路径名的缺点是,缺乏可重用性,因为脚本对于使用的资源具有硬编码要求;另一方面使用暴露在检视面板中的资源引用,是自文档化的,对于使用脚本的用户来说也是立竿见影的;
++++然而,有些情况下按照名称比在检视面板中取回一个资源更方便,尤其是当在检视面板中指定引用是不方便的时候;例如或许想从脚本创建一个游戏物体,为程序生成的网格赋值一个纹理;
++++有些已加载的资源,最明显的是纹理,即使在场景没有实例,也最占内存;当资源不再需要时,可以使用Resources.UnloadUnusedAssets回收内存;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzResources : MonoBehaviour{
void Start(){ var go = GameObject.CreatePrimitive(PrimitiveType.Plane); var rend = go.GetComponent<Renderer>(); rend.material.mainTexture = Resources.Load(“YanlzTestGlass”) as Texture; } //立钻哥哥:void Start(){}
} //立钻哥哥:public class YanlzResources{} |
#B2、Static Functions静态函数 |
++B2、Static Functions静态函数++++B2.1、FindObjectsOfTypeAll++++B2.2、Load++++B2.3、LoadAll++++B2.4、LoadAsync++++B2.5、UnloadAsset++++B2.6、UnloadUnusedAssets++++B2.7、YanlzXREngine.Resources.StaticFunctions |
++B2.1、FindObjectsOfTypeAll |
public static Object[] FindObjectsOfTypeAll(Type type);public static T[] FindObjectsOfTypeAll(); |
++++[type]:匹配搜索时类的类型;
++++返回一个对象的类型或从type派生的数组;
++++返回所有type类型对象的一个列表;
++++返回所有类型T的对象列表;
++++这个函数可以返回加载的Unity物体的任意类型,包含游戏对象、预制体、材质、网格、纹理等;它也会列出内部的东西,因此,请格外小心处理返回的对象的方式;相反Object.FindObjectsOfType这个函数也会列出禁用的对象;
++++请注意:这个函数非常慢,不推荐在每帧中使用;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzResources : MonoBehaviour{
List<GameObject> GetMyAllObjectsInScene(){ List<GameObject> objectsInScene = new List<GameObject>();
foreach(GameObject go in Resources.FindObjectsOfTypeAll(typeof(GameObject)) as GameObject[]){ if(go.hideFlags == HideFlags.NotEditable || go.hideFlags == HideFlags.HideAndDontSave){ continue; } //立钻哥哥:if(){}
if(!EditorUtility.IsPersistent(go.transform.root.gameObject)){ continue; } //立钻哥哥:if(){}
objectsInScene.Add(go); } //立钻哥哥:foreach(){}
return objectsInScene; } //立钻哥哥:List
} //立钻哥哥:public class YanlzResources{} |
++B2.2、Load |
public static Object Load(string path);public static Object Load(string path, Type systemTypeInstance);public static T Load(string path); |
++++[path]:路径名;
++++[systemTypeInstance]:要返回的对象类型过滤器;
++++加载储存在Resources文件夹中path处的资源;
++++如果发现,返回所在path处的资源,否则返回null;如果有type参数,只有type类型的物体将被返回;Path相对于Resources文件夹,忽略扩展名;Resources文件夹可以在Assets文件夹中的任意位置;
++++注意:路径名使用正斜杠“/”,如果使用反斜杠“\”会不正常运行;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzResources : MonoBehaviour{
void Start(){ GameObject go = GameObject.CreatePrimitive(PrimitiveType.Plane); Renderer rend = go.GetComponent<Renderer>(); rend.material.mainTexture = Resources.Load(“MyTestGlass”) as Texture; } //立钻哥哥:void Start(){}
} //立钻哥哥:public class YanlzResources{}
|
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzResources : MonoBehaviour{
void Start(){ //Instantiates a prefab named “enemy” located in any Resources folder in your project’s Assets folder. GameObject instance = Instantiate(Resources.Load(“MyTestEnemy”, typeof(GameObject))) as GameObject; } //立钻哥哥:void Start(){}
} //立钻哥哥:public class YanlzResources{} |
++B2.3、LoadAll |
public static Object[] LoadAll(string path);public static Object[] LoadAll(string path, Type systemTypeInstance);public static T[] LoadAll(string path); |
++++[path]:路径名;
++++[systemTypeInstance]:返回对象的类型过滤器;
++++加载Resources文件夹中的path文件夹或者文件中的所有资源;
++++如果path是一个文件夹,文件中的所有资源都将被返回;如果path为一个文件,只有这个资源将被返回;Path相对于任意Resources文件夹;Resources文件夹可以在Assets文件夹中的任意位置;
++++注意:路径名使用正斜杠“/”,如果使用反斜杠“\”会不正常运行;
//Loads all assets in the “Resources/Textures” folder then picks a random one from the list. //Note: Random.Range in this case returns [low, high) range, i.e. the high value is not included in the range. using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzResources : MonoBehaviour{
void Start(){ GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube); Texture2D[] textures = (Texture2D[])Resources.LoadAll(“Textures”); Texture2D texture = textures[Random.Range(0, textures.Length)]; go.GetComponent<Renderer>().material.mainTexture = texture; } //立钻哥哥:void Start(){}
} //立钻哥哥:public class YanlzResources{} |
++B2.4、LoadAsync |
public static ResourcesRequest LoadAsync(string path);public static ResourcesRequest LoadAsync(string path, Type type); |
++++[path]:路径名;
++++[systemTypeInstance]:返回对象的类型过滤器;
++++异步加载Resources文件夹中的资源;
++++返回ResourceRequest,从该资源可以检索一次已经加载完成的操作;如果有type参数,只有type类型的物体将被返回;Path相对于Resources文件夹,忽略扩展名;Resources文件夹可以在Assets文件夹中的任何位置;
++++注意:路径名使用正斜杠“/”,如果使用反斜杠“\”会不正常运行;
++B2.5、UnloadAsset |
public static void UnloadAsset(Object assetToUnload); |
++++从内存卸载指定的资源;
++++这个函数仅用于储存在硬盘上的资源;
++++如果场景有任何对象引用该资源,该资源被使用时,Unity会从硬盘重新加载该资源;
++B2.6、UnloadUnusedAssets |
public static AsyncOperation UnloadUnusedAssets(); |
++++返回AsyncOperation对象,可以yield等待直到操作完成;
++++卸载未使用的资源;
++++如果对象没有进入到游戏场景,资源被认为没有使用,包括脚本组件,静态变量也被检查;
++++这个脚本执行堆栈,然而并不检查,所以只从脚本栈中卸载引用的资源;如果需要的话下次再重新加载,这需要注意资源已经在内存中被修改;在资源垃圾回收被触发之前,确保调用EditorUtility.SetDirty;
#C3、立钻哥哥对Resources类的拓展 |
++++【Unity API】分类:https://blog.csdn.net/vrunsoftyanlz/category_7637520.html
++++【Unity开发基础】分类:https://blog.csdn.net/vrunsoftyanlz/category_7309057.html
++++【Linux系统编程】分类:https://blog.csdn.net/vrunsoftyanlz/category_9694767.html
++++【C++C铸就生存利器】分类:https://blog.csdn.net/vrunsoftyanlz/category_9325802.html
++++【人工智能AI2026】分类:https://blog.csdn.net/vrunsoftyanlz/category_9212024.html
++++【立钻哥哥CSDN空间】:https://blog.csdn.net/VRunSoftYanlz/
立钻哥哥推荐的拓展学习链接(Link_Url) |
++++立钻哥哥Unity 学习空间: http://blog.csdn.net/VRunSoftYanlz/
++++虚拟现实VR资讯: https://blog.csdn.net/VRunSoftYanlz/article/details/89165846
++++HTC_VIVE开发基础:https://blog.csdn.net/VRunSoftYanlz/article/details/81989970
++++Oculus杂谈:https://blog.csdn.net/VRunSoftYanlz/article/details/82469850
++++Oculus安装使用:https://blog.csdn.net/VRunSoftYanlz/article/details/82718982
++++Unity+SteamVR=>VR:https://blog.csdn.net/VRunSoftYanlz/article/details/88809370
++++Unity减少VR晕眩症:https://blog.csdn.net/VRunSoftYanlz/article/details/89115518
++++SteamVR简介:https://blog.csdn.net/VRunSoftYanlz/article/details/86484254
++++SteamVR脚本功能分析:https://blog.csdn.net/VRunSoftYanlz/article/details/86531480
++++SteamVR2.0开发指南:https://blog.csdn.net/VRunSoftYanlz/article/details/86618187
++++SteamVR2.2.0开发指南:https://blog.csdn.net/VRunSoftYanlz/article/details/88784527
++++SteamVR2.2.0快速入门:https://blog.csdn.net/VRunSoftYanlz/article/details/88833579
++++SteamVR2.2.0交互系统:https://blog.csdn.net/VRunSoftYanlz/article/details/89199778
++++SteamVR2.2.0传送机制:https://blog.csdn.net/VRunSoftYanlz/article/details/89390866
++++SteamVR2.2.0教程(一):https://blog.csdn.net/VRunSoftYanlz/article/details/89324067
++++SteamVR2.2.0教程(二):https://blog.csdn.net/VRunSoftYanlz/article/details/89894097
++++SteamVR_Skeleton_Poser:https://blog.csdn.net/VRunSoftYanlz/article/details/89931725
++++SteamVR实战之PMCore:https://blog.csdn.net/VRunSoftYanlz/article/details/89463658
++++SteamVR/Extras:https://blog.csdn.net/VRunSoftYanlz/article/details/86584108
++++SteamVR/Input:https://blog.csdn.net/VRunSoftYanlz/article/details/86601950
++++OpenXR简介:https://blog.csdn.net/VRunSoftYanlz/article/details/85726365
++++VRTK杂谈:https://blog.csdn.net/VRunSoftYanlz/article/details/82562993
++++VRTK快速入门(杂谈):https://blog.csdn.net/VRunSoftYanlz/article/details/82955267
++++VRTK官方示例(目录):https://blog.csdn.net/VRunSoftYanlz/article/details/82955410
++++VRTK代码结构(目录):https://blog.csdn.net/VRunSoftYanlz/article/details/82780085
++++VRTK(SceneResources):https://blog.csdn.net/VRunSoftYanlz/article/details/82795400
++++VRTK_ControllerEvents:https://blog.csdn.net/VRunSoftYanlz/article/details/83099512
++++VRTK_InteractTouch:https://blog.csdn.net/VRunSoftYanlz/article/details/83120220
++++虚拟现实行业应用:https://blog.csdn.net/VRunSoftYanlz/article/details/88360157
++++Steam平台上的VR:https://blog.csdn.net/VRunSoftYanlz/article/details/88960085
++++Steam平台热销VR:https://blog.csdn.net/VRunSoftYanlz/article/details/89007741
++++VR实验:以太网帧的构成:https://blog.csdn.net/VRunSoftYanlz/article/details/82598140
++++实验四:存储器扩展实验:https://blog.csdn.net/VRunSoftYanlz/article/details/87834434
++++FrameVR示例V0913:https://blog.csdn.net/VRunSoftYanlz/article/details/82808498
++++FrameVR示例V1003:https://blog.csdn.net/VRunSoftYanlz/article/details/83066516
++++SwitchMachineV1022:https://blog.csdn.net/VRunSoftYanlz/article/details/83280886
++++PlaySceneManagerV1022:https://blog.csdn.net/VRunSoftYanlz/article/details/83280886
++++Unity5.x用户手册:https://blog.csdn.net/VRunSoftYanlz/article/details/81712741
++++Unity面试题ABC:https://blog.csdn.net/vrunsoftyanlz/article/details/78630687
++++Unity面试题D:https://blog.csdn.net/VRunSoftYanlz/article/details/78630838
++++Unity面试题E:https://blog.csdn.net/vrunsoftyanlz/article/details/78630913
++++Unity面试题F:https://blog.csdn.net/VRunSoftYanlz/article/details/78630945
++++Cocos2dx面试题:https://blog.csdn.net/VRunSoftYanlz/article/details/78630967
++++禅道[zentao]:https://blog.csdn.net/VRunSoftYanlz/article/details/83964057
++++Lua快速入门篇(Xlua拓展):https://blog.csdn.net/VRunSoftYanlz/article/details/81173818
++++Lua快速入门篇(XLua教程):https://blog.csdn.net/VRunSoftYanlz/article/details/81141502
++++Lua快速入门篇(基础概述):https://blog.csdn.net/VRunSoftYanlz/article/details/81041359
++++框架知识点:https://blog.csdn.net/VRunSoftYanlz/article/details/80862879
++++游戏框架(UI框架夯实篇):https://blog.csdn.net/vrunsoftyanlz/article/details/80781140
++++游戏框架(初探篇):https://blog.csdn.net/VRunSoftYanlz/article/details/80630325
++++.Net框架设计:https://blog.csdn.net/VRunSoftYanlz/article/details/87401225
++++从零开始学架构:https://blog.csdn.net/VRunSoftYanlz/article/details/88095895
++++设计模式简单整理:https://blog.csdn.net/vrunsoftyanlz/article/details/79839641
++++专题:设计模式(精华篇):https://blog.csdn.net/VRunSoftYanlz/article/details/81322678
++++U3D小项目参考:https://blog.csdn.net/vrunsoftyanlz/article/details/80141811
++++Unity小游戏算法分析:https://blog.csdn.net/VRunSoftYanlz/article/details/87908365
++++Unity案例(Vehicle):https://blog.csdn.net/VRunSoftYanlz/article/details/82355876
++++UML类图:https://blog.csdn.net/vrunsoftyanlz/article/details/80289461
++++PowerDesigner简介:https://blog.csdn.net/VRunSoftYanlz/article/details/86500084
++++Unity知识点0001:https://blog.csdn.net/vrunsoftyanlz/article/details/80302012
++++Unity知识点0008:https://blog.csdn.net/VRunSoftYanlz/article/details/81153606
++++U3D_Shader编程(第一篇:快速入门篇):https://blog.csdn.net/vrunsoftyanlz/article/details/80372071
++++U3D_Shader编程(第二篇:基础夯实篇):https://blog.csdn.net/vrunsoftyanlz/article/details/80372628
++++Unity引擎基础:https://blog.csdn.net/vrunsoftyanlz/article/details/78881685
++++Unity面向组件开发:https://blog.csdn.net/vrunsoftyanlz/article/details/78881752
++++Unity物理系统:https://blog.csdn.net/vrunsoftyanlz/article/details/78881879
++++Unity2D平台开发:https://blog.csdn.net/vrunsoftyanlz/article/details/78882034
++++UGUI基础:https://blog.csdn.net/vrunsoftyanlz/article/details/78884693
++++UGUI进阶:https://blog.csdn.net/vrunsoftyanlz/article/details/78884882
++++UGUI综合:https://blog.csdn.net/vrunsoftyanlz/article/details/78885013
++++Unity动画系统基础:https://blog.csdn.net/vrunsoftyanlz/article/details/78886068
++++Unity动画系统进阶:https://blog.csdn.net/vrunsoftyanlz/article/details/78886198
++++Navigation导航系统:https://blog.csdn.net/vrunsoftyanlz/article/details/78886281
++++Unity特效渲染:https://blog.csdn.net/vrunsoftyanlz/article/details/78886403
++++Unity数据存储:https://blog.csdn.net/vrunsoftyanlz/article/details/79251273
++++Unity中Sqlite数据库:https://blog.csdn.net/vrunsoftyanlz/article/details/79254162
++++WWW类和协程:https://blog.csdn.net/vrunsoftyanlz/article/details/79254559
++++Unity网络:https://blog.csdn.net/vrunsoftyanlz/article/details/79254902
++++Unity资源加密:https://blog.csdn.net/VRunSoftYanlz/article/details/87644514
++++PhotonServer简介:https://blog.csdn.net/VRunSoftYanlz/article/details/86652770
++++编写Photon游戏服务器:https://blog.csdn.net/VRunSoftYanlz/article/details/86682935
++++C#事件:https://blog.csdn.net/vrunsoftyanlz/article/details/78631267
++++C#委托:https://blog.csdn.net/vrunsoftyanlz/article/details/78631183
++++C#集合:https://blog.csdn.net/vrunsoftyanlz/article/details/78631175
++++C#泛型:https://blog.csdn.net/vrunsoftyanlz/article/details/78631141
++++C#接口:https://blog.csdn.net/vrunsoftyanlz/article/details/78631122
++++C#静态类:https://blog.csdn.net/vrunsoftyanlz/article/details/78630979
++++C#中System.String类:https://blog.csdn.net/vrunsoftyanlz/article/details/78630945
++++C#数据类型:https://blog.csdn.net/vrunsoftyanlz/article/details/78630913
++++Unity3D默认的快捷键:https://blog.csdn.net/vrunsoftyanlz/article/details/78630838
++++游戏相关缩写:https://blog.csdn.net/vrunsoftyanlz/article/details/78630687
++++UnityAPI.Rigidbody刚体:https://blog.csdn.net/VRunSoftYanlz/article/details/81784053
++++UnityAPI.Material材质:https://blog.csdn.net/VRunSoftYanlz/article/details/81814303
++++UnityAPI.Android安卓:https://blog.csdn.net/VRunSoftYanlz/article/details/81843193
++++UnityAPI.AndroidJNI安卓JNI:https://blog.csdn.net/VRunSoftYanlz/article/details/81879345
++++UnityAPI.Transform变换:https://blog.csdn.net/VRunSoftYanlz/article/details/81916293
++++UnityAPI.WheelCollider轮碰撞器:https://blog.csdn.net/VRunSoftYanlz/article/details/82356217
++++UnityAPI.Resources资源:https://blog.csdn.net/VRunSoftYanlz/article/details/83155518
++++JSON数据结构:https://blog.csdn.net/VRunSoftYanlz/article/details/82026644
++++CocosStudio快速入门:https://blog.csdn.net/VRunSoftYanlz/article/details/82356839
++++Unity企业内训(目录):https://blog.csdn.net/VRunSoftYanlz/article/details/82634668
++++Unity企业内训(第1讲):https://blog.csdn.net/VRunSoftYanlz/article/details/82634733
++++Unity企业内训(第2讲):https://blog.csdn.net/VRunSoftYanlz/article/details/82861180
++++Unity企业内训(第3讲):https://blog.csdn.net/VRunSoftYanlz/article/details/82927699
++++Unity企业内训(第4讲):https://blog.csdn.net/VRunSoftYanlz/article/details/83479776
++++Unity企业内训(第5讲):https://blog.csdn.net/VRunSoftYanlz/article/details/83963811
++++Unity企业内训(第6讲):https://blog.csdn.net/VRunSoftYanlz/article/details/84207696
++++钻哥带您了解产品原型:https://blog.csdn.net/VRunSoftYanlz/article/details/87303828
++++插件
++++计算机组成原理(教材篇):https://blog.csdn.net/VRunSoftYanlz/article/details/82719129
++++5G接入:云计算和雾计算:https://blog.csdn.net/VRunSoftYanlz/article/details/88372718
++++云计算通俗讲义:https://blog.csdn.net/VRunSoftYanlz/article/details/88652803
++++立钻哥哥Unity 学习空间: http://blog.csdn.net/VRunSoftYanlz
--_--VRunSoft:lovezuanzuan--_--