An auxiliary development framework for lightweight RPG games based on Unity3D

With the growing prevalence of virtual reality technology across industries like cinema, video animation, and gaming, game developers must cater to a wider range of players. Game engines serve as middleware, reducing the time spent on coding and improving productivity for creating video games. While mainstream game engines offer a plethora of customization options, certain developers may find themselves limited when it comes to controlling specific aspects of the game. Due to the lack of built‐in functionality in current game engines like Unity and Unreal, the author developed TRPGFramework, a lightweight framework based on Unity3D, to address some of these problems. The game framework consists of two main parts: ZGamework (overall framework) and BGamework (game‐specific framework). To enhance performance, scalability, and code reusability in the game development process, the entity‐component‐system structure is implemented. This approach increases maintainability and makes the code clearer, easier to expand, and debuggable. By creating a simple 2D RPG game for performance testing, we confirmed that the framework significantly improves code reusability and modularity, resulting in faster development time and increased efficiency for interactive applications and games. This framework is particularly useful for creating real‐time combat role‐playing games, which are some of the most complex games available today. Using entity‐component‐system principles, we developed a buff system and unit controller optimized to allow hundreds of intelligent units to fight on the same screen or thousands of non‐intelligent units to fight simultaneously.


F I G U R E 1 MVC, MVP, and MVVM architecture
F I G U R E 2 ECS architecture which reveals that each framework possesses its unique advantages and potential uses. 2,3While developers often use object-oriented methods, this can lead to maintenance and scalability issues as the game's features and versions increase. 4he entity-component-system (ECS) architecture comprises abstract business modules that serve a specific collection of components instead of managing entities.If an entity has this collection, it receives the services offered by the module.As illustrated in Figure 2, the ECS architecture defines each unit in a game, such as a monster or a camera, as an entity composed of one or more components. 5,6Each component only contains the necessary data to perform its function; for instance, skill components hold skill damage and range.The system processes the collection of entities and holds only the logic, not the state, like a tool.For example, the skill system executes skills based on the state of each entity that has access to that state.This structure enables changing the behavior of reality in real-time by adding or removing entity parts. 7he Unity3D implementation layer acts as a bridge between the core layer of the ECS framework and practical game development.It provides a tangible realization of the ECS architecture for the Unity engine. 8,9To allow developers to modify data easily in the editor, the core classes of the Unity implementation layer must be mountable on game objects. 10,11he ECS framework includes an editor that simplifies manipulation of game data for non-developers.This editor can be used directly in the game scene or on a premade body.To achieve this, the three essential classes of the Unity implementation layer-EntityBehavior, ComponentBehavior, and SystemBehavior-all inherit from MonoBehavior.These classes' initialization methods use the inject keyword to leverage dependency injection capabilities. 12,13he ECS architecture and its variations, originating from the gaming industry, follow the composition over inheritance principle, which provides developers with more flexibility in defining simulation objects than conventional approaches. 14o manage logical objects, each object must be assigned an entity behavior by the developer.Although entities are unique throughout the program, each entity must have a corresponding entity behavior in Unity.In rare cases, a collection of in-game entities may represent a single "entity."Therefore, multiple entity behaviors with references to the same entity are possible. 15,16One of these entity behaviors acts as the entity's body, while the proxy property of the other entity behavior maintains a reference to this body.Additionally, the transform component of the game object that contains these entity behaviors is kept in view of this entity.The entity's ViewComponent stores the transform component of the game object on which the entity behavior resides in its transforms property. 17If a view component is not already attached to the game object, the entity behavior generates one.When an entity is destroyed, the disposer property removes any unwanted data streams and unsubscribes from them.The transforms property is a responsive container that stores the transform properties of all the game objects that comprise the entity, allowing access to all of its components. 18,19he current level of production has garnered a large audience, indicating a significant market opportunity. 20,21However, popular game engines like Unreal Engine and Unity3D use the entity-component (EC) architecture, which does not support asynchronous and event-driven systems. 22In contrast, the ECS architecture is specifically designed to meet these requirements by compartmentalizing data and behavior into separate layers.This article presents a comprehensive implementation of all the systems and frameworks necessary for creating a moderately sized game, with a strong emphasis on optimizing speed.Creating a lightweight RPG game requires not only excellent story design but also superb math and performance planning.The TRPGFramework draws inspiration from several existing frameworks, such as GameFramework, QFramework, and EGamePlay, and incorporates various features, such as compiler development, hierarchical property manipulation, object pooling, UI management, timer management, event management, and resource management.This framework is not limited to RPG games and can be applied to any game.The content is simplified to enable developers to quickly grasp and utilize it.Although it may not be as robust as other frameworks, it offers fast and convenient usage. 23,24

RELATED WORKS
The initial Unity game framework focused mainly on fundamental aspects of game development, such as object pooling, resource management, interface management, and event management.While useful, these frameworks did not offer enough support for advanced features and performance optimization in game development.For example, ymh's CatLib was released as an open-source game client based on Unity3D and features a server-side dual-end framework. 25he server-side of the framework is constructed using C.net Core as a distributed game server, and it stands out for its high development efficiency, high performance, shared logic code between the client and server ends, client-side server hot-plugging mechanism, WebSocket protocol support, and various other features.As the game market continues to evolve, Unity-based game frameworks have been adapting to meet the changing needs of the market.For instance, in recent years, with the growing mobile game market, many Unity game frameworks have shifted their focus towards mobile platform optimization and adaptation, offering more features and tools suitable for mobile platforms.In 2020, Ellan Jiang's GameFramework encapsulated commonly used modules in the game development process, largely standardizing the development process, accelerating development, and ensuring product quality.Later, modules such as Config, Data Node, and Data Table were developed for use by game developers.This game framework is more focused on data flow processing, and the structure is more dispersed.Xie'sQFramework is a rapidly evolving collection of frameworks designed to accommodate upgrades and changes in Unity software in 2021.Its goal is to become the first framework for companies without framework experience, independent developers, and Unity3D newcomers.The framework comprises several projects with solutions in various technical directions.The QFramework system design architecture is divided into four layers, each with its set of rules.The performance layer has the ViewController layer, which is responsible for receiving input and changing the state when performance changes, with the IController interface.QFramework is a game development framework that follows the MVC design pattern.In this pattern, developers need to write more code to facilitate the interaction between the controller and view, which increases the complexity of the code and maintenance costs.In certain scenarios, the relationship between the view, model, and controller is tightly coupled, making the code difficult to test and maintain.In Figure 3, we see a simple project based on the MVC architectural pattern.The model, view, and controller are organized in the inner layer.However, this layering can add complexity to the entire project, and the relationships between the models, views, and controllers can become tightly coupled, making it difficult to modify one component without affecting the others.
As the Unity engine evolves and the game market changes, game frameworks are becoming increasingly convenient and supportive for developers.In this article, the author drew inspiration from existing frameworks such as Game-Framework and QFramework to create a simplified TRPGFramework that is easy to understand and use.One of the distinguishing features of this framework is its use of an ECS architecture, which is lightweight and efficient.The authors incorporated the concept of semantic traits into their ECS, enabling compile-time checks, detecting entity class affiliation, and providing run-time functionality changes.To refine hierarchical management, TRPGFramework has been divided into two parts: the generic framework ZGamework, which includes lightweight development aids such as an event system, object pool, time manager, multi-level properties, and resource manager.This level's functionality is similar to the behavior layer of the ECS structure, as it processes entities through systems to provide them with corresponding behaviors.The systems are at the core of this level and perform specific actions on specific components.The specialized event framework BGamework includes a buff system, skill system, backpack system, combat system, AI system, and developer model, among other features.BGamework manages game object entities and their components, presents them to the user, and handles user input.These two frameworks combine to form a mature RPG game framework that improves development efficiency, code speed, code reusability, and modularity for interactive applications and games.

Design ideas
The TRPGFramework, constructed based on ECS, allows for the simulation of different types of games in Unity3D.In this article, the ECS framework's entity layer, behavior layer, and presentation layer are further divided into two parts: ZGamework and BGamework.The underlying game is based on ZGamework, and all repetitive objects are stored in an object pool.The different modules communicate with each other through an event system, and a timer is used to synchronize all time-related events.BGamework is used for game content management, map mapping using TileMap, and backpack management through BagManager.To ensure unified control of multiple types of items, all items inherit from UseBase.This approach can assist developers in having better control over game entities, handling game logic and data more effectively, and managing various events and behaviors within the game.Furthermore, Hierarchical management approach can provide better code organization and scalability, allowing developers to modify and add game features more easily to meet the ever-changing market demands.The ZGamework is responsible for managing the input in each frame, which includes activating systems, registering events, UI windows, and object pools, as shown in Figure 4. Additionally, data in StreamingAssets can be read and initialized into multiple tables.As the interface framework entry of the ECS architecture, ZGamework implements various functions such as activating systems, registering events, UI windows, and object pools.The data in StreamingAssets is also read and initialized into multiple tables.The BGamework includes the initialization of the backpack system, the buff system, the enemy controller, and certain aspects of the game scene.By modeling data using XML-JSON, players have full control over the game data through the open database and StreamingAssets.Players can directly modify the database in StreamingAssets to impact the game content directly. 26

3.2
Data control aspect

Data structure
To achieve full control over game data through an open database and StreamingAssets, traditional game frameworks typically use the XmlDocument or XmlReader class for data parsing.For example, in QFramework, we can utilize the XML utility class to read and parse XML documents.In this article's framework, we use LitJSON, which is a small library class with a low memory footprint that's perfect for use in performance-focused Unity projects.LitJ-SON is optimized for performance and can handle large JSON files quickly and efficiently.Using this approach, players can directly modify the database within StreamingAssets to influence game content.Developers can easily parse JSON format data and convert it into various data types in Unity using LitJSON.As shown in Figure 5, we utilized LitJSON to establish a standardized process for serializing combat, which includes serialized maps and serialized combat units.This is achieved by using the ToObject method of the JsonMapper class to convert the JSON string into a JsonData object, which allows access to the individual fields of the JSON data.As a result, they can design and create many mods that they can plug into the game.Though this method completely foregoes security when compared to using a database like SQLite, it opens up the game's creative possibilities to the player.

Behavior tree
In Unity software, the development time can be reduced by using the basic behavior tree provided by AI Designer and designing only the nodes of the behavior tree.The essence of a behavior tree includes nodes for options, sequences, conditions, events and so on.Code inherits various nodes and merges them into the tree, traverses the nodes from the root node, and performs AI actions based on a complex relationship network and the current reality.As AI behavior tree frameworks, the commonly used lightweight behavior trees in Unity include Behavior Designer, NodeCanvas, and BTFlow, each with its own advantages and applicable scenarios.In this framework, BTFlow is used as the behavior tree editor.In the BTFlow editor, the various nodes and connections of the behavior tree are created, edited, and configured using a drag-and-drop approach.The BTFlow editor uses only three types of nodes: action nodes, condition nodes, and control nodes.Action nodes are responsible for executing specific behaviors, such as movement, attack, and animation Composite nodes have been added to this framework, mainly used to manage a group of child nodes and can achieve complex behavior tree logic, such as selection nodes, sequence nodes, parallel nodes, repeat nodes and so on.These nodes can be combined as needed to achieve more complex behavior tree structures.Composite nodes are widely used in game development and can be used to implement AI behaviors, task systems, plot management and so on.
In addition, the editor in the framework provides a set of predefined nodes that represent common behaviors, such as moving, attacking, or searching for objects.It also allows the creation of custom nodes to achieve specific behaviors.The behavior tree system in this framework is designed to be easy to use and integrate into existing projects.It offers a simple API that allows developers to create and manage behavior trees in their code.Additionally, it supports saving and loading behavior trees from XML files.Overall, the behavior tree system in the framework is a powerful tool that can assist game developers in creating complex and dynamic AI behaviors for their games.

Game flow tool
The Game Flow Tool is a state machine-based tool that assists game developers in quickly creating game flows.The tool manages the flow of the game by utilizing the state machine pattern.This involves defining states and transitions between them to implement the game logic.In the state machine, each state represents a stage or state of the game, and the transitions between them indicate the flow of the game.For example, in this framework, developers can create the game state by inheriting the "State" class and define the specific logic of the game state in this class.The transitions between states are implemented through the "Transition" class, which allows developers to specify the conditions for transitioning between states and the associated behavior.To compute the attack capability in the ESC architecture, developers can break it down into different components such as the base attack power, equipment attack power, percentage provided by equipment, and buff attack power.Attributes are divided into several categories, including the base value, equipment bonus, equipment percentage, buff bonus, and buff percentage.Developers can use these categories to compute the overall attack power of the player.Finally, the framework also includes LitJSON's built-in JsonMapper, which enables developers to serialize .NET objects to JSON strings or deserialize JSON strings to .NET objects.This makes it easier to manage and modify mod tables with complex data structures.These tools and libraries significantly reduce the time and effort required to interact with mod tables, allowing developers to focus more on game development rather than file management (Figure 6).The framework used string extension methods to streamline the conversion process of document content into the properties needed for shaping, coloring, and other purposes: Signed shaping versus unsigned shaping.In Unity, signed Loading loading Above the popup, generally used as a page load.

Max highest
Only for special purposes, with the highest level.
and unsigned shaping are not directly relevant concepts.However, when working with low-level graphics programming in Unity, we may encounter signed and unsigned integer types.Boolean operations: They are used for making decisions based on logical conditions, controlling the flow of code, and implementing behaviors.The basic Boolean operations in Unity are the same as those in other programming languages: AND, OR, and NOT.Types of fractions: However, Unity does provide some support for working with fractions in the form of the Mathf class, which includes methods for manipulating rational numbers.These methods can be useful for performing calculations involving angles, distances, and other geometric quantities.Floating-point numbers: Floating-point numbers are the most commonly used numerical data type in Unity.They are used to represent values with a decimal component, such as positions, velocities, and angles.
Color variations: Unity provides several tools and techniques for working with color variations, including the Color class and the Gradient class.The color class allows you to specify colors using RGB or HSL values, and to manipulate them using various methods.The gradient class allows you to create smooth transitions between colors, which can be used for things like creating color ramps or animating color changes over time.Vectors in two and three dimensions.Unity provides several built-in vector classes, including Vector2, Vector3, and Vector4, which can be used to represent vectors in two, three, and four dimensions, respectively.These classes provide various methods for manipulating vectors, such as adding, subtracting, multiplying, and dividing them, as well as calculating dot products, cross products, and other vector-related quantities.

UIManager
The UIManager in this game framework is set automatically.In such cases, the UIManager may be created and managed automatically based on the game's profile or other settings.For example, some frameworks can create UIManager instances based on specific tags or game objects in a scene and automatically add UI elements to the UI root node at runtime.The main interface has been designed to display the player's life, magic, and shield values, along with a quick props bar and function buttons.When the corresponding button is pressed, the UIManager for the desired interface will open.Furthermore, players can access the backpack and skills pages by using the B or K shortcut keys, respectively.The backpack screen includes a simple attribute viewing area, a backpack section, an equipment bar, and a shortcut bar.Since the shortcut bar is linked to all other shortcut bars, changing one will affect all of them.Players can drag weapons and items to the shortcut bar, and equipment can be dragged to the equipment bar.The window type and its closing behavior are defined first.The actions for closing or destroying a window, as well as opening and activating a window, are defined below.There are four window types, as shown in Table 1.
In addition to the aforementioned structures, the TRPGFramework also includes hierarchical property actions, object pools, timer managers, event managers, and resource managers.The authors have designed the framework to be as lightweight as possible, simplifying its complexity so that developers can quickly understand and start using it.This framework can be applied to any type of game, not just RPGs.Despite having fewer features than other frameworks, it is still fast and easy to use.

TESTS AND CONCLUSIONS
To validate the game framework, a 2D RPG game was used as an example.The main goal was to ensure the game is playable and that the system meets the specified requirements.It is well-known that an official 2D game project resource consists of pages, prefabs, scripts, audio, sprites, and other files.The project utilizes resource packs such as Ads, Analytics Library, Cinemachine, HD Render Pipeline, In-App Purchasing, Lightweight Render-Pipeline (LWRP), Shader Graph, and others.
Certain resource packs such as Lightweight RenderPipeline and Shader Graph are required for this project, as they provide simplified, physics-based lighting and materials for LWRP, allowing the creation and editing of shaders by dragging and dropping in the graphical user interface.The official program structure resembles that of an MVC framework, with a game scene divided into four major components: the time management system, the user interface, player assets, and level assets.Smaller components such as HealthConvas and Footlight are placed below these four components.The design consists of modules such as ZGamework (Event events, UI windows, object pools), which uses UseBase to automatically populate the use method whenever an item in the prop bar, such as consumables, weapons, equipment, and skills, is used.It is very simple to call this method and be done with it.Normally, the UI can be opened and closed, and the data and props in the backpack are displayed, as shown in Figure 7. Effective data access and rendering optimization are utilized for smooth user interaction.
A good game development framework should not only complete the designed function, but also have good performance.In order to find the defects of this framework in time, improve its efficiency and improve its shortcomings, this article will carry out performance testing on the framework.In order to evaluate the performance of the TRPGFramework, we rebuilt the 2D RPG using this framework.We analyzed the event system test and logical code test, respectively.The skill system is composed of various parts, including directed attacks, damage, skill boosts and bonuses, undirected damage, automatic attacks, manual attacks, group attacks, and individual attacks, all of which are included in each skill module.The skill module has three levels, and the system creates a variety of interesting abilities.In the testing section, various types of skills are demonstrated in detail.Target selection is performed according to the skill's target selection method, and the target is fine-tuned and modulated based on specific parameters.The final target is locked, and EffectTo is called on it to add the skill effect.Figure 8 shows the effects of these four skills, which can be switched between using the middle mouse button.Along with the skills system, the TRPGFramework also includes UnitManager and BuffManager modules.Starting with Unity version 2020.3, we ran a benchmark on a 64-bit Windows 10 system with an Intel Core i9-10900k CPU and a 2080TI GPU.

Event system test
Unity's SendMessage method is implemented through reflection.To send a message, the sender needs to get a reference from the subscriber.The difference between using SendMessage and calling methods directly on an object is that SendMessage can call private methods on the object.To test the performance of a game framework using SendMessage, we can follow these steps: First, create a test scenario that contains the game frame and related objects that we want to test.Then, create a TestScript script and write the test code by calling the function in the game frame with the SendMessage function and passing the parameters.After that, we can run the test scenario with Unity Test Runner and record the test results, such as execution time and memory usage.These results can help us evaluate the performance of the game framework and identify any potential areas for optimization.We conducted a test to compare the performance of Unity's event system and its built-in SendMessage method.The code for this test is shown in Figure 9.The test involved sending 200 messages to each of 20 subscribers using the SendMessage method.To measure the CPU and memory usage of the events, we utilized Unity Engine Profiler tool to sample their performance.Unity's SendMessage method uses reflection to send a message.The sender needs to obtain a reference from the subscriber in order to send the message.The advantage of using SendMessage over calling methods directly on an object is that SendMessage can call private methods on the object.
Table 2 shows that the framework has twice the latency and memory consumption compared to Unity's built-in SendMessage method, and it does not perform as well when synchronizing messages.The reason behind this is that event systems based on the ECS framework are designed for asynchronous event flow, and packaging synchronous events as asynchronous events requires more time and memory.Asynchronous processing of the data stream reduces the latency and memory consumption during the send phase to a minimum.Although the latency and cost during the receive phase are higher than Unity's built-in SendMessage method, the excess is still within acceptable limits for the functionality improvement.

Logical code test
By using the Profiler tool provided by the Unity engine, we sampled the CPU usage and memory usage of the sent events.Recording the events for the 100 rounds of the relay, we found that the traditional Unity Framework initialized faster than the TRPGFramework at the start of the game, and that the Unity Framework was faster during the run after initialization.However, the TRPGFramework ultimately won the 100 rounds of the relay.Using a sample of the data from the 100-round race, we plotted a line graph, as shown in Figure 10, to illustrate the performance gap between the two methods.
In the first round, the UnityFrameWork initializes 0.06 seconds faster than the TRPGFramework.The horizontal axis of Figure 10 displays the average time taken in the last 10 rounds, with the exception of the first round, which displays the exact time taken.Despite the fact that the logic developed in the ECS framework required a great deal of time in the first round, by the tenth round, it was taking roughly the same amount of time as the conventional approach.Over the next 80 rounds, both sets of logic take roughly the same amount of time on average, with the TRPGFrameWork taking slightly less time than the conventional development method in most cases, allowing the TRPGFrameWork-controlled runner to complete the 100-round relay first, 0.18 s ahead of the conventional development method.Although the TRPGFrame-Work is slightly slower than the UnityFrameWork during initialization, the logic controlled by the TRPGFrameWork after relatively long runs is significantly more efficient.
The TRPGFramework is a comprehensive evaluation of the TRPGFramework's functionality, usability, reliability, performance, and supportability.
The practical application enables us to identify the framework's flaws and address them.We rewrote the official Unity demo to ensure comparability and practicality when implementing the TRPGFrameWork in practice.The TRPGFramework methods have significant functional advantages over traditional development methods, according to a performance comparison of the two development approaches.In previous performance tests, we evaluated the performance of the TRPGFrameWork using test cases.Now, we will compare the two in the context of an RPG game application.For this analysis, we will continue to use the Unity engine's profiler to obtain valid data.We have chosen the point in the game when the player has killed 1000 enemies for comparison to figure out how well the game works when played normally.

DISCUSSION
The TRPGFramework in Unity is comprised of a lightweight gaming framework and several RPGs featuring in-game development and digital planning functionalities.However, it was specifically designed to address particular issues in certain RPGs and may not be suitable for all game types.Therefore, developers should be aware of its limitations before using it and ensure it is appropriately customized for optimal results.The TRPGFramework offers essential lightweight functionalities, including an event system, a timer manager, object pools, multi-level properties, and string expansion.
The proposed architecture provides various benefits, such as flexibility, extensibility, and a clear separation of state and behavior.When combined with Odin and addressable tools, it results in a streamlined and widely applicable game framework.This RPG framework can even be used to create real-time combat RPGs, which are among the most complex game types available today.The buff system in this framework utilizes the most effective elements of the current high-quality combat framework, EGamePlay, making it easy to control and modify.This framework is a combination of ideas from Kingdom Come 3, The Greatest Showman, and The Original Stone Project, which is a recent trend.It would be challenging for the average developer to create their own set of standalone mod designers or a complete set of fully open parameters, as Kingdom Come 3's development team did or the authors of The Original Stone Project did.Therefore, we chose the simplest and most effective way to use it by storing data directly in JSON and XML, enabling developers to decide for themselves whether to allow player customization.In future game development projects, the game framework will continue to be updated to provide more useful features while meeting the project's specific requirements.

F I G U R E 5
LitJSON serializes the battlefield playback.Condition nodes are used to determine whether certain conditions are met, such as whether the character is within attack range or has been damaged.Control nodes are used to control the execution flow of the behavior tree.

F
, placed at the bottom.PopPop-up window Above the window, generally used as a popover.

F I G U R E 7
UI display (ability to open and close menu, with data and items in the backpack displayed properly) Framework EventSystem test result Four kinds of skills display image F I G U R E 9 CPU usage in the framework TA B L E 2 F I G U R E 10 Test result line chart