当前位置:网站首页>Create componentized development based on ILRuntime hot update
Create componentized development based on ILRuntime hot update
2022-07-31 04:44:00 【Clank's Game Stack】
Build component development based on ILRuntime
In the previous section, we explained in detail the startup process of the ILRuntime game project framework, as well as the entry into the hot update project, which laid a solid foundation for us to build the framework. The logical hot update project is completed with C#.Therefore, in the logic hot update project, we ensure that the development is not much different from the ordinary Unity C#, so today we will design a componentized development mechanism based on the logic hot update project, we call it ILRBehaviour, similar to MonoBehaviour, try our best toEnsure that all development habits are very similar to MonoBehaviour. Since MonoBehaviour is a data object type in the Unity C# domain, we cannot use it directly in the logic hotfix project, so we have to design a set of class-based mechanisms by ourselves, mainly to accomplish 3 things:
There is a Game Development Communication Team
a> Everyone can go to get the source material to learn and communicate togetherDesign ILRBehaviour interface
The design of the ILRBehaviour interface is mainly consistent with MonoBehaviour. The common development habits of MonoBehaviour are mainly interface + gameObject + transform object. Later, we will do a good job in the collision detection interface of the physics engine.Regarding the timer of MonoBehaviour, we will design a timer module separately to do the timer, instead of simulating the timer mechanism of MonoBehaviour.With this consideration, the data members and interfaces of our ILRBehaviour can be designed,
As follows:
class ILRBehaviour {public GameObject gameObject; // Simulation component instance.gameObject;public Transform transform; // Simulate component instance.transform;virtual public void Awake() {}virtual public void Start() {}virtual public void Update() {}virtual public void LateUpdate() {}virtual public void FixedUpdate() {}virtual public void onDestroy() {}}
What's different from MonoBehaviour here is that the interface of the base class is made a virtual function directly, instead of looking up through reflection to see if the subclass has this method like MonoBehaviour.Therefore, when the subclass overloads the interface function, the override keyword is added.
Add, find, delete ILRBehaviour component instance mechanism
In Unity's development habits, the GameObject class is used to add components. Here GameObject is a natvie c# object, so other methods must be found. Here I added a global singleton of ILRBeahviourMgr to add an instance of the ILRehaviour component.Find, delete.
ILRBehaviour AddILRComponent(GameObject gameObject, Type classType)
public T AddILRComponent
How does this principle work?All MonoBehaviour components in Unity C# GameObject are "hanging" on the GameObject node instance, but for the logic hot change project, GameObject is a nativie C# object, which cannot be directly recorded on it. Our design here is to build here ILRBehaviourMgrA dictionary Dictionary
Figure 1.4-1: AddILRComponent Process Details
Other search and delete interfaces are similar. I won't analyze them one by one here. You can check the source code.
Let the specific interface of ILRBehaviour be called at a specific time
After designing the interface of adding, searching, and deleting the ILRBehaviour component, the next step is to make the specific interface in the ILRBehaviour component mechanism be called at a specific period.The specific period of the current hot update comes from Unity C#, and the entry is in main.cs, so if we want to make the specific interface in the ILRBehaviour component callable, we can start from the specific interface in main.cs, letThey call the specific interface in ILRBehaviourMgr, and then in IlRBehaviourMgr, we traverse each gameObject in the behaviorMap, find the List array list of ILRBehaviour that belongs to it, traverse each ILRBehaviour component instance in it, and call the specific interface.Let's take update as an example to analyze:
The whole process is shown in Figure 1.4-2.
Figure 1.4-2: The whole process of triggering ILRBehaviour.Update call
After implementing these mechanisms, we have designed a complete set of componentized development mechanism based on ILRBehaviour, which combines the previous Mono development habits of Unity c# as much as possible, so that other small partners can seamlesslyDo development in the hot update project.Finally, the last architecture diagram, deepen the impression.
Figure 1.4-3: ILRBehaviour. Mechanism Design Architecture
That's it for today's sharing, you can go to the study group announcement, you can get the source code of our ILRuntime hot update tutorial, and it's more sour to look at the source code.
边栏推荐
- Unity shader forge和自带的shader graph,有哪些优缺点?
- [C language] General method of base conversion
- three.js make 3D photo album
- 微软 AI 量化投资平台 Qlib 体验
- [shell basics] determine whether the directory is empty
- Understanding and Using Unity2D Custom Scriptable Tiles (4) - Start to build a custom tile based on the Tile class (below)
- C# 实现PLC的定时器
- From scratch, a mirror to the end, a pure system builds a grasscutter (Grasscutter)
- [Paper reading] Mastering the game of Go with deep neural networks and tree search
- 产学研用 共建开源人才生态 | 2022开放原子全球开源峰会教育分论坛圆满召开
猜你喜欢
Exsl file preview, word file preview web page method
ERROR 2003 (HY000) Can‘t connect to MySQL server on ‘localhost3306‘ (10061)
产学研用 共建开源人才生态 | 2022开放原子全球开源峰会教育分论坛圆满召开
MATLAB/Simulink&&STM32CubeMX工具链完成基于模型的设计开发(MBD)(三)
WeChat applet uses cloud functions to update and add cloud database nested array elements
Win10 CUDA CUDNN 安装配置(torch paddlepaddle)
专访 | 阿里巴巴首席技术官程立:云+开源共同形成数字世界的可信基础
Lua,ILRuntime, HybridCLR(wolong)/huatuo热更新对比分析
XSS shooting range (3) prompt to win
binom二项分布,
随机推荐
MySQL based operations
unity2d game
Safety 20220709
关于出现大量close_wait状态的理解
马斯克对话“虚拟版”马斯克,脑机交互技术离我们有多远
C# 实现PLC的定时器
(八)Math 类、Arrays 类、System类、Biglnteger 和 BigDecimal 类、日期类
three.js 制作3D相册
【小土堆补充】Pytorch学习笔记_Anaconda虚拟环境使用
Open Source Database Innovation in the Digital Economy Era | 2022 Open Atom Global Open Source Summit Database Sub-Forum Successfully Held
【debug锦集】Expected input batch_size (1) to match target batch_size (0)
three.js make 3D photo album
Two address pools r2 are responsible for managing the address pool r1 is responsible for managing dhcp relays
(5) final, abstract class, interface, inner class
30 Years of Open Source Community | 2022 Open Atom Global Open Source Summit 30 Years of Open Source Community Special Event Held Successfully
Why don't you programmers make a living off your own projects?And have to work for someone else?
visual studio 那些提高效率的快捷键,总结(不时更新)
微软 AI 量化投资平台 Qlib 体验
Can‘t load /home/Iot/.rnd into RNG
idea工程明明有依赖但是文件就是显示没有,Cannot resolve symbol ‘XXX‘