版本 |
作者 |
参与者 |
完成日期 |
备注 |
UnityAPI_ScriptableObject_V01_1.0 |
严立钻 |
|
2020.05.27 |
|
|
|
|
|
|
立钻哥哥: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/
#ScriptableObject脚本化对象 |
#ScriptableObject脚本化对象++A1、Description描述++B2、Variables变量++C3、Public Function共有函数++D4、Message消息 |
#A1、Description描述 |
++++这意味着存储数据资源是最有用的;
#B2、Static Functions静态函数 |
++B2、Static Functions静态函数++++B2.1、CreateInstance++++B2.2、YanlzXREngine.ScriptableObject.StaticFunctions |
++B2.1、CreateInstance |
public static ScriptableObject CreateInstance(string className);public static ScriptableObject CreateInstance(Type type);public static T CreateInstance(); |
++++创建脚本化对象类名为className的一个实例;
++++创建脚本化对象类型为type的一个实例;
++++创建脚本化对象T的一个实例;
//立钻哥哥:示例 //1、Editor代码; //2、创建ScriptableObject脚本; //3、写个MonoBehaviour调用Create方法生成Example格式的数据; //4、在检视面板把Example脚本拖给ExampleInfo;
//----====------------------- //1、Editor代码;using UnityEngine; using System.IO; using System.Collections; using UnityEditor; using YanlzXREngine;
public class MyScriptablity : MonoBehaviour{
public static T Create<T>(string _path, string _name) where T : ScriptableObject{ if(new DirectoryInfo(_path).Exists == false){ Debug.LogError(“立钻哥哥:Can’t create asset, path not found.”); return null; } //立钻哥哥:if(new DirectoryInfo().Exists){}
if(string.IsNullOrEmpty(_name)){ Debug.LogError(“立钻哥哥:Can’t crate asset, the name is empty”); return null; } //立钻哥哥:if(string.IsNullOrEmpty()){}
string assetPath = Path.Combine(_path, _name + “.asset”);
T newT = ScriptableObject.CreateInstance<T>(); AssetDatabase.CreateAsset(newT, assetPath); Selection.activeObject = newT;
return newT; } //立钻哥哥:public static T Create
public static void Create<T>() where T : ScriptableObject{ string assetName = “New” + typeof(T).Name; string assetPath = “Assets”;
if(Selection.activeObject){ assetPath = AssetDatabase.GetAssetPath(Selection.activeObject); if(Path.GetExtension(assetPath) != “”){ assetPath = Path.GetDirectoryName(assetPath); } //立钻哥哥:if(Path.GetExtension()){} } //立钻哥哥:if(Selection.activeObject){}
bool doCreate = true; string path = Path.Combine(assetPath, assetName + “.asset”); FileInfo fileInfo = new FileInfo(path);
if(fileInfo.Exists){ doCreate = EditorUtility.DisplayDialog(assetName + “ already exists.”, “Do you want to overwrite the old one?”, “Yes”, “No”); } //立钻哥哥:if(fileInfo.Exists){}
if(doCreate){ T T_info = Create<T>(assetPath, assetName); Selection.activeObject = T_info; } //立钻哥哥:if(doCreate){}
} //立钻哥哥:public static void Create
public static void Create(){ Debug.LogError(“立钻哥哥:You should call ‘Create’ method like this: Create } //立钻哥哥:public static void Create(){}
} //立钻哥哥:public class MyScriptablity{}
//----====------------------- //2、创建ScriptableObject脚本;public class YanlzExample : ScriptableObject{ public int id; public string name; } //立钻哥哥:public class YanlzExample{}
//----====------------------- //3、写个MonoBehaviour调用Create方法生成Example格式的数据;public class YanlzExampleItem : MonoBehaviour{
[MenuItem(“Example/Create/Example Data”)] static void CreateMyExample(){ Scriptablity.Create<YanlzExample>(); } //立钻哥哥:static void CreateMyExample(){}
} //立钻哥哥:public class YanlzExampleItem{}
//----====------------------- //4、在检视面板把Example脚本拖给ExampleInfo;public class YanlzExampleUsage : MonoBehaviour{ public YanlzExample exampleInfo;
void Start(){ Debug.Log(exampleInfo.name); } //立钻哥哥:void Start(){}
} //立钻哥哥:pubilc class YanlzExampleUsage{}
//立钻哥哥:一个“ScriptableObject”的示例; |
#C3、Message消息 |
++C3、Message消息++++C3.1、OnDestroy++++C3.2、OnDisable++++C3.3、OnEnable++++C3.4、YanlzXREngine.ScriptableObject.Message |
++C3.1、OnDestroy |
ScriptableObject.OnDestroy(); |
++++当脚本化对象将被销毁时,该函数被调用;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzScriptableObject : MonoBehaviour{
void OnDestroy(){ Debug.Log(“立钻哥哥:Script was destroyed.”); } //立钻哥哥:void OnDestroy(){}
} //立钻哥哥:public class YanlzScriptableObject{} |
++C3.2、OnDisable |
ScriptableObject.OnDisable(); |
++++当脚本化对象离开作用域时调用这个函数;
++++当物体被销毁也将被调用并且可以使用任何清除代码;当编译完成以后重新加载脚本时,OnDisable将被调用,随后脚本已经加载之后,OnEnable被调用;
++++注意:OnDisable不能用于协同程序;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzScriptableObject : MonoBehaviour{
void OnDisable(){ Debug.Log(“立钻哥哥:Script was removed.”); } //立钻哥哥:void OnDisable(){}
} //立钻哥哥:public class YanlzScriptableObject{} |
++C3.3、OnEnable |
ScriptableObject.OnEnable(); |
++++当物体被加载的时候调用此函数;
++++注意:OnEnable不能用于协同程序;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzScriptableObject : MonoBehaviour{
void OnEnable(){ Debug.Log(“立钻哥哥:Script was enabled.”); } //立钻哥哥:void OnEnable(){}
} //立钻哥哥:public class YanlzScriptableObject{} |
#D4、ScriptableObject示例 |
++D4.1、非打包方式 |
//1、创建一个ScriptableObject脚本;using UnityEngine; using YanlzXREngine;
public class YanlzXMLContainer : ScriptableObject{ public string yanlzXML; } //立钻哥哥:public class YanlzXMLContains{}
|
//2、然后这样调用;using UnityEngine; using YanlzXREngine;
public class YanlzTieFighter : MonoBehaviour{ public YanlzXMLContainer myXMLSettings;
void Awake(){ } //立钻哥哥:void Awake(){}
} //立钻哥哥:public class YanlzTieFighter{}
|
++D4.2、打包方式 |
//1、先创建一个类using UnityEngine; using System.Collections.Generic; using YanlzXREngine;
public class YanlzSysData : ScriptableObject{ public List<Vector3> myContent; } //立钻哥哥:public class YanlzSysData{} ++++立钻哥哥:该类只有一个属性myContent;当然也可以声明更多属性、事件和方法;在后面,这个类的实例将作为资源被打包;
|
//2、创建一个编辑器脚本;//立钻哥哥:该脚本用于实例化YanlzSysData,设置一些数据,然后打包; using UnityEditor; using System.Collections.Generic; using YanlzXREngine;
public class YanlzExport{
[MenuItem(“Assets/Export”)] public static void Execute(){ //实例化YanlzSysData YanlzSysData mySD = ScriptableObject.CreateInstance<YanlzSysData >();
//随便设置一些数据给myContent mySD.myContent = new List<Vector3>(); mySD.myContent.Add(new Vector3(1, 2, 3)); mySD.myContent.Add(new Vector3(4, 5, 6));
//YanlzSysData将创建为一个对象,这时在Project面板上会看到这个对象; string pStr = “Assets/YanlzSysData.asset”; AssetDatabase.CreateAsset(mySD, pStr); Object myO = AssetDatabase.LoadAssetAtPath(pStr, typeof(YanlzSysData));
//打包为YanlzSysData.assetbundle文件 BuildPipeline.BuildAssetBundle(myO, null, “YanlzSysData.assetbundle”);
//删除面板上的那个临时对象 AssetDatabase.DeleteAsset(pStr);
} //立钻哥哥:public static void Execute(){}
} //立钻哥哥:public class YanlzExport{}
|
//3、运行时加载这个数据资源IEnumerator Start(){ WWW myWww = new WWW(“file://” + Application.dataPath + “/../YanlzSysData.assetbundle”); yield return myWww;
//转换资源为YanlzSysData,这个mySD对象将拥有原来在编辑器中设置的数据 YanlzSysData myD = myWww.assetBundle.mainAsset as YanlzSysData;
//如打印mySD.myContent[0],将得到Vector3(1, 2, 3); Debug.Log(mySD.myContent[0]); } //立钻哥哥:IEnumerator Start(){}
|
//4、这其实是把整个对象实例打包,如果ScriptableObject属性中包括其他的类实例,则这些类需加上[Serializable]序列化;通过这种方法,可以将系统需要的数据(如角色分类、Matrix4x4数据等等)打包,加载后直接转换为预定的类型,具有更高的效率;
|
#E5、立钻哥哥对ScriptableObject类的拓展 |
++++【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--_--