Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Introduction to Unity Development Mediator Model

Shulou Source: shulou.com Published: 2022-06-02 04:03:42 09月11日 Update

This article introduces the relevant knowledge of "introduction to Unity Development intermediary pattern". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

0. Preface

A game may contain many subsystems

Event system

Checkpoint system

Role management system

Achievement system

Game status interface

Role information interface

Pause interface

If the interaction between subsystems is not planned, there will be cross-references.

The intermediary mode can be used to decouple the internal subsystems in game development.

1. An introduction to the intermediary model

The intermediary pattern (Mediator) is stated in GoF as follows:

An interface is defined to encapsulate the interactive behavior of a group of objects. Intermediaries reduce the coupling between objects by removing references between them, and can change the interactive independence between them.

To illustrate the intermediary model in terms of housing transactions, it can be explained as follows:

The intermediary company is an information center (corresponding to the intermediary), and all buyers and sellers (all subsystems) handle the sale of houses through the intermediary company.

two。 The way of implementation in game development

This is how we implement the intermediary model in game development.

First of all, the game will have two major system categories: "game system class" and "interface class".

We define these two abstract classes, define some lifecycle-related methods, and then pass in an instance of the intermediary in the constructor. Each time you create a new system class, you inherit one of the abstract classes. In this way, each system will hold an intermediary. When we do the subsystem function, we do not need to care about which system this function will be associated with, we just need to inform the intermediary what function the current subsystem wants to accomplish through the instance of the intermediary, and leave the rest to the intermediary to deal with the reference logic between subsystems. Of course, the construction of all subsystems is done in the intermediary, who has access to all subsystems.

Advantages

Through this operation, we uncouple the subsystems, and the external dependence of all subsystems is reduced to one class.

Shortcoming

It should be noted that because the intermediary class acts as the information exchange and communication between all game systems and the UI interface, it is easy to have an explosive operation interface, so we also need to cooperate with other design patterns to avoid this situation and to reduce the burden on the intermediary class.

This is the end of the introduction to the Unity Development Mediator Model. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Intermediaries intermediaries subsystems systems patterns between development interfaces situations information functions coupling intermediary companies companies content instances objects houses interfaces ways Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker NVidia Shulou Tech Info OPPO Reno MySQL