With the development of game production technology, in the experience from 2D to 3D, from single-machine to online games, from PC games to mobile game evolution, the player for the game quality requirements more and more high, the difficulty of game production correspondingly increased, the whole game development system began to become large and complex, This results in problems related to the configuration and management of game data. This article will talk about how to manage and configure the game's data in game development from the perspective of the "resurrection" and "pause/Resume" scenarios in the game.
Why to talk about the configuration and management of game data
Do not know whether you will and bloggers have the same idea, is when you come back to think about the game development, you will often find that if you ignore the game's screen, plot, special effects and so on these games in the visual things, then in fact, the game is essentially a large finite state machine (FSM), And what we usually do is to maintain the state of the finite state machine, from the game load to the beginning of the game, from the game to the game to the occurrence of various events to affect the entire finite state machine state, we usually do nothing more than is in the maintenance of various states. This feeling may be more noticeable in RPG games where the player may be walking or running in the scene, may be in a conversation with an NPC in the scene, may be fighting an enemy in front of him, and may be bargaining with the owner of the grocery store ... Can say in the whole game all the time in the game state of the switch, then in different states to switch between, what is the most important? The answer is data. What is data? The player's health, mana, Combat, defense, the purpose of the object, price, quantity, the game's plot, dialogue, music and so on are data. When we switch between states, it's actually the data that really changes. Thus, in the face of complex and huge game system, how to configure and manage the data in the game is a problem worth our thinking.
The configuration and management of game data from the perspective of application scenario
Let's start with two common scenarios in the game: "Resurrection" and "pause/resume" to see the importance of game data configuration and management.
Here is an example of a parkour game for bloggers:
Application Scenario--"Resurrection"
Resurrection is a feature that is particularly common in the game, and the benefit of the resurrection is that it is possible to return to the game without restarting the game, which is, of course, one of our most intuitive feelings, and the deeper reason is that the player skillfully exploits the mental state of the game's failure. Now everyone in life likes to win, this kind of psychology to the game world is also applicable, because the purpose of the game is to let the player have a sense of accomplishment to get happiness. However, when the game mission fails, the player will try their best to defeat the boss to win the game, so in the game has such a setting, can guide the players in the game to form the habit of consumption, so that the game can be profit from the player. Well, let's take a look at the basic "Resurrection" logic!
private void update () {// If the player has a health value greater than 0, the game is normally if (Player.hp>0 ) {//game status is Normal gamemanager.instance.gamestate=gamestateenum.normal; //perform normal game logic Donormalevent (); }else {//game status over Gamemanager.instanc E.gamestate=gamestateenum.over; //show Gameover Showgameover (); //player Resurrection Relive ()}}
There are two things you need to do to revive a player:
1. Adjust the state of the game from over to normal
2. Adjust the player's state from death to normal
Adjusting the state of the game is especially easy because Gamemanager is a typical singleton pattern, so we can change the gamestate from over to noral directly. However, for the player's state adjustment, we have encountered difficulties. Where does the problem go? The problem is that we write a series of attributes, such as the player's health, into the Playercontroller class, and if we set the player's properties all to private, we will not be able to adjust these properties externally. For example, we want the player to be full of blood, but because these properties are private and we can't access them externally, we don't get the player's current health value and maximum health when we restore the player's health value. But if we set all the properties of the player to public, we might have to deal with each property in the editor window, because once we try to balance the power of the game, this is the problem we have to face, and the more deadly player's properties are not always the same, For example, in the RPG game, the player's health and other attributes will increase as the role level increases. So whether we set these properties to public or private, we can't guarantee that the data we access every time is the latest data. In other words, we can't take the player's attributes as a constant value in the script, because the data is changing at any time, but if the numbers are relatively stable like the enemy and boss, we can write them to a fixed value directly in the script, but I don't recommend it. This shows that in-game data configuration and management is an important role in maintaining the normal switching between states. It's rain blood. The Resurrection interface in the Mirage, each resurrection consumes a resurrection Jade:
So how does the blogger do this resurrection in this parkour game? Because bloggers at that time in the design of the game is not considered, directly the player's health is written in 100, so in the resurrection of the player, the same time the game is adjusted to the state, and then the relevant GUI window is hidden, and then the player's health is reset to 100, re-build the player is good. It is because of the feeling that this period of time to do the game lacks a good game architecture, so every time the game to achieve the end of their own cornered, left to their own do not want to maintain the mess, this is obviously not good, so after the formal write code before the planning, Believe this will be able to guarantee the quality of the game! Anything that learns to a certain stage will encounter bottlenecks, although the process of breaking this bottleneck is painful, but if you do not break it, then you can only stay in this position forever.
Application Scenario--"Pause/Resume"
As with the "Resurrection", "Pause/Resume" is also a common feature in the game, which gives the player a choice to leave the game for a while, ensuring that the player does not affect the course of the game while doing other things. For example, in the Paladin, Gujian Tan and other games, the player can press the ESC key to bring up the game settings interface, the player enters the game Settings screen this time, the game world time seems to be still, the enemy in the scene will not because the player in the View system settings interface to take the initiative to attack the player, Because in this case the game is paused. And when the player exits the system Settings screen, the game reverts to normal state. In the era of mobile internet, the "Pause/Resume" situation in the game is more common, which is decided by the nature of people playing games in the mobile internet era to pay more attention to leisure and entertainment. Remember every day cool run just on the line of that period of time, my side a lot of classmates are in class when playing, but because this game a run up will not stop, so often is a game to play down a lesson on the end. Bloggers do not advocate such Ah, play games to play games, but what things have to have a degree ah, otherwise it will become Wanwusangzhi. Well, the purpose of our analysis of this case is simply to tell you that it is necessary to add a "pause/resume" function to the game. OK, now let's analyze what happens when the state transitions in this scenario are involved in the data!
After the game is paused, all objects in the scene will stop moving, and the state of each object in the game is changed, but because the control of the game pause/resume in Unity3d is mainly achieved by adjusting the Time.timescale value. When the Time.timescale value is 0 o'clock, the game pauses; when Time.timescale is 1 o'clock, the game returns to normal. However, it is important to note that Time.timescale will have an impact on all the time in Unity3d such as Fixedupdate (), co-process, Destroy (), animation components, etc., so if there is a special requirement for the state of the game after the pause, Suggestions or other ways to achieve it! Update () and laterupdate () are not mentioned here because these two methods are not affected. Let's take a look at this code:
//游戏是否暂停privatebool isPause=false;//暂停/恢复游戏的方法privatevoidResume(){ if(!isPause){ Time.timeScale=0; isPause=true; }else{ Time.timeScale=1; isPause=false; }}
With this code we are able to implement a basic game "pause/Resume" function. In the game management class Gamemanager we define a player's score. Under normal circumstances, when the player does not die when the player's score is updated in the GUI, and the player's score is directly in the update () to achieve the cumulative way, so the player's score will continue to update after the game is suspended, which is certainly not in line with the actual situation, Therefore, you can solve this problem by taking the previous time.deltatime before this increment. Bo Master This example is just want to tell you to use this method to pause the game there will be such a problem, I hope everyone later attention AH!
Ideas and methods of game data configuration and management
Since we are mainly talking about game data configuration and management in today's article, let's talk about the common ideas and methods of game data configuration and management. Based on the relative size of the data changes in the game, we divide the data in the game into two categories: static data and Dynamic Data.
static data
Static data refers to data that is essentially constant or does not need to be changed in the game. For example, in the game boss level and health is generally determined, so this type of data can be called static data. Similarly, the content of the NPC conversation in the game is a static data, because the NPC dialogue content is designed in the design of the plot, no need to modify it. So for static data, we can consider the following methods:
The benefit of defining static data as constants in a class is that there is no need to modify each script.
The advantage of storing static data in files is that the data can be managed, and the disadvantage is that it requires parsing interfaces for different files, which are commonly used in game development: Json, XML, Excel, CSV, and so on.
Storing static data in a database, such as Sqliite, but the disadvantage of doing so is also obvious, reading the database from the local consumes a lot of resources, and once the database file is lost, the entire game will not run.
Dynamic Data
Dynamic Data refers to data that is constantly changing in the game, such as the player's score, the player's health, the player's experience, and so on. Dynamic Data is handled in addition to being written as a constant in the class, and the rest is the same as the static data, and there is no more talking about it.
Summarize
Maybe today's article is nagging, even from a technical point of view, this article does not talk about any valuable technical points. However, in the blogger's opinion, no matter how great a technology is, if there is no good architecture or structure, then when the size of the project to a certain extent, the project will become problematic. Because according to the broken window theory, when you see the window broken and not to repair it in time, then a long time you break is the whole house. Review Bo Master So long game development, actually did a lot of games to the end did not finish, is because to the final project basically out of control, become a even oneself are unwilling to go to maintain the project, such a situation is terrible. Usually you do the project alone, you may feel that there is nothing, but when you work with others to complete such a project, your problems will become the whole team problem. Bloggers have always wanted to know what it would be like to play games and team games together, because bloggers felt that they were really not well-mastered. Although the architecture of this kind of thing you will have more experience, but you now find the problem, why not get rid of it now? Architecture is really important to those projects that die because of the architecture, the real project should die in practice, because the problem of architecture eventually gets out of hand, this thing itself is shameful. All right, that's all for today.
Welcome to pay attention to bloggers of the independent blog, my blog address is http://www.qinyuanpei.com, timely access to the latest technology blog, look at you, haha!
The daily motto is no doubt that good things will always come. And when it comes late, it's also a surprise. --"Under the Tuscan Sun"
Unity3d game development from "Resurrection" and "Pause/Resume" On game data configuration management