Unity3d Engine principle Detailed introduction, Unity3d engine architecture design-Zhibolife

Source: Internet
Author: User

time 2014-03-24 11:18:00 Blog Park-All essays Area original http://www.cnblogs.com/zhibolife/p/3620440.html

System structure

In order to better understand the game's software architecture and object model, it is very useful to get a better look at only one Unity3d game engine and editor, and it's the main principle.

Unity3d engine

Unity3d is an award-winning tool for creating interactive 3D applications in multiple platforms.unity3d by game engine and editor. The engine contains the software components, the most common and recurring tasks in game research and development. Topics covered by the engine include sound, graphics, physical and network functions. The engine supports C#,boo, and JavaScript script programming.
The other part is unity editing, which acts as a script and other component that contains the game scene settings and the game's preview window (see Figure 4) For the Layered Object Check Project panel's integrated development environment. It is also equipped with several multilingual script editors and a unique prefabricated assembly system that will be explained later.

Figure 4:unity3d Editor

There are several unity licenses. Unity Basic features a limited free PC for Mac and web development. Other platforms or full feature set [15] need to purchase additional licenses.
While there are many free software and proprietary alternative game engines, such as Unreal Engine ™ or the C4™ engine chose unity for the following reasons:
* It can be deployed in Windows,mac OSX, Web browser, wii console, Iphone,ipad, Android, Microsoft Xbox 360 and PlayStation 3. It even plans to increase flash and Linux deployments in the future. The deployment of Possbilities offers a lot of possibilities to use the game engine or game engine monetization or further research.

* The Unity community is very supportive and the engine, and the editor is well documented.

* The engine is relatively easy to learn and work with, and supports the idea of rapid software development by providing all the tools, rapid prototyping and iteration as well as fast script compilation.

* The iOS base license for Iphone,ipad and ipod touch may be deployed at a relatively low price compared to other vendors. Create machine armor and tanks using Unity3.0,c # scripts and MonoDevelop IDE for development. You can find an addendum to the Unity tutorial.

A Brief History of Unity3d

The following dates illustrate the evolution of the Unity engine between 2001 and 2011 [16].
? 2001 Unity Technology began developing its own game engine in 2001. The main inducement at the time was to create the game, the foundation of these games, and create a good tool [1].
? 2003 in 2003 the company, the resulting engine will be a great product of its own.
In 2005, Unity1 launched Apple's WWDC stage in 2005.
The 2007unity2.0 was launched in 2007 and added a terrain engine, real-time dynamic shading and video playback, and more.
In 2008, the launch of Unity's iphone and Cartoon Network launched FusionFall in 2008, with more than 8 million games already playing.
? 2010 in 2010 Unity3.0 released dozens of new features, such as asset management and animal illumination mapping.
? 2011 unites more than 5 million developers and 600,000 network player installations.

Game architecture

The architecture of the machine armor and the tank is composed of modules and unity's scene architecture.

Main modules

This section describes the most important modules and subsystems at the level of their relationships. The architectural style of the game is an object with data capsules. The following UML component diagram illustrates the subsystem and its relational network.

Game logic

This module manages current player and AI configuration Countdown timerand current game status (pause, wait for network reply).

ai (AI (Artificial Intelligence), English abbreviation for AI)

The AI module contains the logic units behind, groups and players ai.the units of AI pathfinding or obstacles to avoid using different steering behavior Control unit states. Group AI manages the behavior and activities of the group, such as group Pathfinding. A higher level of management of all the players in the player group is by the player module.
Ai Machine learns to save and load its data using the interface of the persistent data module.

Persistant Data Persistence

This module is responsible for the different game sessions between the data. Among other should be available for saving and loading, storing lookup tables and graph pathfinding modules and managing Accumulateddata machines for learning AI.

Game Actors Players

game participants in the game in the terrain, units or buildings. Their 3D model gets visualized through Unity3d's rendering pipeline. Each player in the game has an AI module that controls its behavior.

Steering behaviours guiding behavior

The computational power of guiding behavior, how and how fast autonomous game agents can be active, should be used to avoid obstacles, people or simply looking for tasks.

Pathfinding Road Search

This module is responsible for creating a pathgrid, obstacle information collection and providing various pathfinding requests aninterface. To get better performance, some information is saved to load from disk.

Input inputs

This module tracks the user's input, processes it, and generates feedback.

Network Networks

The network module is responsible for all game actors ' state management is to keep the game state, consistent on both machines, to avoid dithering Network Unit motion network game. Another responsibility.

Gui

Graphical user Interface (GUI) displays all buttons, menus, and countdown timers in small maps. It is also responsible for the functionality and interaction of these elements with the logic modules of the game used for this purpose.

3D rendering

The module mainly manages the Unity3d.  The scene's main camera determines which objects need to be rendered and sends them through the render pipeline. The Unity3d encapsulates the most rendered detail, and also provides access through the pixel and vertex shaders.

Unity Scene Settings

Each figure in the game is represented by a unity3d scene. Below is a typical scenario set at Unity level (i) and (ii) in the live window looks like:

Unity-Level Maps

Map of the scene view

Now all the game objects are described from the bottom of the top panel.

Cwalls

This object contains custom paint wall nodes and wall edges. Another way is to use custom drawing walls to Calculatethem depending on the geometry of the map.

Directional Light (directional)

This lamp is only used to calculate terrain illumination maps. After the shutdown, due to performance reasons.

Game Music (gaming)

hold the game's main music and play the live launcher.

Gamecontroller (game controller)

Gamecontroller Game objects hold and manage all the game objects and manage the logic of the game. It includes the following objects:

Cursorcontroller (Cursor Controller):

manages the appearance of the cursor and the logic behind it.

Gameinstantiator (game instantiation):

This important game object is responsible for instantiating other objects that need to create a nonspecific order.

Gameinstantiator in the Inspector

Gamecontroller in the Hierarchy

Gameinstantiator holds maps, Pathcreator path creation and management barriers, manages player configuration and settings, is used to handle user input of Inputcontrol game objects, The referenes of a game object and a reference to a building on a player's game object define a map of the playable area.

It also contains references to spawn points and custom paths and walls of the player.

Gui

all GUI objects that own the map.

Machine learning Controller

This game object controls all the functions that machine learning requires.

SPAWN1, SPAWN2

The spawn point of the actual player. The sign of the spawn point is the green cube scene view.

Hpaths

Customize the path node at the edge of the map. The custom node is tagged in the scene editor and outlines the Red line.

Main Camera (primary)

On-site master camera and audio monitoring. All 3D sounds are viewed from the camera's perspective.

Playarea (playing field)

Defines the area of the map that is actually playable.

Base prefabs (site prefabrication)

A building scattered on a map.

Terrain (Terrain)

Unity Terrain object.

Testrunner

An object that is used to run unit tests with Unity3d's unit testingframework sharpunit.

MVC pattern (MVC mode)

The Unity engine Design encourages MVC (model-View-controller) for engineering. In my case, the structure looks like this:

Figure 5:MVC Architecture representation of a pattern

The model contains all the game objects, components and data files. Access to the game object's renderer and camera objects.

The view rendering model and the engine rendering of the primary management Unity3d. It requires accessthe to hold models of 3D models, textures, materials and effects. It also has the effect of what input options are.

The controller receives the user input and invokes the method response on the model object. This is the input subsystem represented in my game. The user can influence the view with his input.

multiplatform development (Multi-platform development)

Unity allows deployment projects to vary slightly on different platforms. The presentation and functionality are largely maintained depending on the platform's capabilities. However, there are significant differences in some areas, such as the input mechanism on different devices.

Abstract Factory design patterns are applied to the design of these components.

The abstract Factory Pattern Abstraction Factory mode

Figure 6: Abstract Factory mode

Abstract Factory mode (see Figure 6) protects customers from different platforms to implement the same concept on different APC and platform is a set of abstractproduct classes. These classes represent a concept that supports all abstract factory platforms. An class declaration creates a single product operation, and the Concretefactory class represents a specific platform.

Clients use only abstract factory and abstract product methods, thus protecting from the specific implementation of a platform.

Input and persistant data (inputs and persistence)

There are two main aspects of the game, the different implementation requirements are the input mechanism and usageof persistent file data. Cross-plattform databases are not supported in Unity3d. That's why machine armor and tanks use persistent data on disk binaries. All platforms get their own capabilities and their implementation, supported by the file format.

In order to maintain readability and flexibility, the following abstract Factory mode adapts to cross-platform input processing:

Figure 7: Input subsystem structure excerpt from

This is just a small one involving all the platforms and commands that are selected for the demo excerpt.

InputManager is attached to the Inputcontrol of the game object in the scene. It calls the update function inside each frame of the Execute method of Commandimplementor. The commandimplementor of the execution method iterates through all the added commands, checks their execution status to express satisfaction, and invokes the Execute method, if so.

The abstract factory pattern in the diagram of the component of the input subsystem:

Ios+unity

The machine armor and tank were created by iterative development of the process, which is why the game has been played before any adjustments for ipad™.
This chapter describes and analyzes the challenges and solutions that are facing the transplant machine armor and tank ipad™.

Maximum Polygon count (highest polygon count)

One of the most obvious limitations that apply to the ipad™ game of the polygon number of graphics chips is the ability to present each frame.it's turned-out, more than 300,000 polygons, each frame starting to drop below the FPS frame rate on the ipad™. In 3D modeling software, by manually eliminating edges and applying pre-defined algorithms to reduce polygons, from the beginning, some models even rebuiilding reduce the polygon count, the number of polygons currently on all platforms is:

The average polygon number is approximately 300 per unit. If all 24 enemies and player units are taken by the camera, the number of polygons produced in one frame will be 7200, averaging about 8500, in the worst case of runners. Adding the polygon of the maximum 4000 terrain (the terrain of the rest of the flat-head body is culled), the heaviest frame will render about 12500 GPU polygons.
Draw Call Reduction and Lights (draw reduce calls and lights)
Even on mobile devices, the number of draw calls per frame is more important. A draw calls the GPU to draw one model at a time. If the model has n sub-grid will cause at least n battle flat calls.every GUI texture, select the airplane and health bar to add a call to the scene.
Additional draw call another source is per pixel illumination, resulting in additional draw calls per light pass. That's why all subnets and models merged into a model do not use dynamic illumination. All the model and terrain textures of the lights bake in inches of light and shade to calculate each texture gets a static light source to illuminate the brightness of the texture that lays the light map. It looked as if their lights were affected, though there was no computational model. Figure 8 shows several models without lighting maps or lighting effects.

Figure 8: Off-texture material shader and no light baking mode

Figure 9: The game expands the view in the upper right corner of the statistics window

This is to say that you can combine several objects of unity to share the same material made, at run time, in a single draw call to draw together. This method is called dynamic batching [18]. Figure 9 shows a scenario caused by a 66-level call to the following sources:
Graphical user interface (GUI)
8 Draw call to zoom Out button, Countdown countdown text + 24 Map spots + 8th building maps spots +1 camera map spot. Summarizes the GUI resulting in draw calls.
Terrain (Terrain)

4 Draw the call. Each of these textures.
Visible Models (visual model)
14 draw calls. Each model results in a call to itself than a 3-level battle. One for the cell grid, one for the Healthbar grid, and one for the planar mesh selection. The low numbers can explain the dynamic batching with unity.
terrains (terrain)
Unity3d has no supported terrain for iOS until Unity3.4 was released in July 2011 [19]. In order to find the best solution for armor and tanks, two alternative ways of terrain implementation have been tested: simulating terrain in 3D programs: a 3D modeling program and terrain are divided into different sections (see Figure 10). The effect of partitioning, most of the segment cones unity culling. That meansthat only at least partially visible segments are rendered.

                                                                                 Figure 10: Follow the terrain highlighting section

This technique is discarded to create new terrain, because this process will be very complicatedcompared Unity's terrain system, the texture size is very large or the quality is affected. * Terrain: Terrain Mobile System Mobile system is a solution that can be used for mobile devices through the Unity Asset store t4m terrain, and can be converted into Unity's terrain. Originally, the performance of this solution was not enough for the game.
The ultimate terrain solution is to use the unity terrain engine with very low quality settings. This is the only possible post-Unity3.4 release in July 2011 to join Unity terrain support for mobile communications systems.
gui-optimization (GUI optimization)
The Unity engine provides two ways to implement the GUI. One way is to use Unity's GUI system Unitygui, which requires its functionality, is a special feature calledinside called Ongui (), which executes two times per frame and onceevery events. This system is only used for the main menu, and the Pause menu, in allvalues need to calculate the external Ongui function.
GUI textures are used for all other GUI elements like GUI buttons and small maps to maintain performance. The GUI textures are displayed in a flat image in 2D and rendered once per frame.
script-optimizations (script optimization)
In order to grant the script a high performance, the cheapest way to track with the profiler. It turned out to be known as the most expensive way to go through the pathfinding or steering behavior subsystem. Pathfinding has been optimized, as described below in the AI section. It has also been suggested to ensure that expensive features such as steering behavior and other AI programs do not invoke every frame.

Reprinted from: http://blog.csdn.net/jbjwpzyl3611421/article/details/10441681

==================unity3d Engine Architecture Design ======================

The concept of components (Component) was first approached in the 2005 Game programming Gems 5 "Component Based Object Management", which was felt to be very practical in design. Later, it was found that an important improvement of Unreal Engine 3 was the abandonment of the previous object model based on pure derivation, instead of the component-based object model . For this design idea, unity is more thorough than unreal-everything is component.

So what exactly is the "component-based" object model ? What problems can it solve?

In traditional designs, we typically use "derivation" to describe the relationship between objects. Subclasses derive the function of the parent class by deriving the parent class. When designing the game object, it will add various functions for the game object according to the needs of the game itself, such as rendering, collision, rigid body, particle system and so on. These common functions must be implemented into the base class in order to provide services for various derived classes. This led to the game object base class become very large bloated, that is difficult to use, and difficult to maintain.

The "component-based" object model is to separate all the basic functions that need to be provided to the game object into separate "component modules" (Component), and a specific game object can be used to combine the functional modules it needs. All functionality is no longer an interface in the parent class, and becomes a child object instance, serving the game object. This will not only ensure the reusability of the function code, but also increase the modularity and flexibility of the whole object system.

In unity, Gameobject has essentially no other function except as a container for component. All required functions are implemented by combining component. The script itself is also a component, used to implement custom functions on gameobject by controlling other component. Although these component are physically tied together, there is a certain level of relationship between them. When designing a specific function of a game object, the component is generally divided into three levels.

Basic components of the engine

Unity itself provides a variety of internal functional components. such as rendering components, physical components, sound components, and so on. These components implement the basic functionality provided by all engines and are used by scripts to combine advanced functionality.

Module Function Script Component

A component that implements some relatively independent generic module functionality through scripting. The design of such components is the key to the reusability of scripts, which requires careful analysis of what functions in the game object can be independently made into a reusable functional module component, and the implementation should minimize coupling with other components. For example, when designing a character game object, you need to design a dress up function for him. Dress up function is actually to display sub-object group management, toggle display status. This function is relatively independent, instead of implementing him into the role, it is better to stand alone as a functional module component. The role game object and all other game objects that need to be dressed up can be implemented by including this module component.

There may also be dependencies between module functional components, which means that a functional module component may be dependent on another functional module component to form more sub-hierarchies at this component level.

High-level Glue code script

These scripts are used to really combine the engine infrastructure components and module functional components to implement the final game object logic. Using "Glue code" to describe these scripts is very pertinent, which is to "stick" all these sub-functions together. For example, a player script is designed to combine all the required component functions to implement a player's specific game logic. Because this level represents the highest level of game behavior control objects, is the specific game logic of the "glue" code, no longer for the higher layer of service, so its reusability is not high. However, these objects are differentiated by type and tend to overlap in functionality, so you can continue to use derived relationships to implement functionality reuse. For example, by implementing all the basic functions in character (which are implemented by combining the underlying components), both player and NPC derive from character to inherit all character functions and continue to implement their own special features. Whether a feature should be implemented with components or derived implementations without very clear boundaries should be applied flexibly as needed.

In the process of using unity, if you want to implement a small project of the demo level, there is no need to consider a lot, directly with the script to implement the function. However, it is important to effectively organize complex projects, improve the reusability of code, fully understand and rationally utilize "component-based" object model design ideas.

Unity3d Engine principle Detailed introduction, Unity3d engine architecture design-Zhibolife

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.