Resource management in a unity project

Source: Internet
Author: User

This is part of what I share in the 2017 Kingsoft technology open day. Starting from the introduction of mapping resource format configuration, the Resource Configuration tool is introduced, and finally, a whole set of project resource management schemes is discussed. The code for the Resource Configuration tool can be obtained on GitHub and is a simple implementation based on the following concepts.

The resources in a 3D game project are mainly composed of stickers, models, actions, sounds, and so on. Model Designer Design model, the scene is composed of models, the role is not only a refined model also with a variety of actions, including walking, running, standby, attack and so on. A variety of basic resources constitute the most elements of the game.

In my swordsman World Hand Tour Project There are tens of thousands of materials, the main city is a 7000+ model. Each character can have a different outfit, hairstyle, weapons, pendants, mounts, and so on. Hosting so many resources has very high requirements for memory and performance. An excellent resource management solution can carry more content and meet more needs.

Map Resource Configuration

Unity provides very generous support for this resource management. With the map as an example, unity supports directly putting the original map directly into the project without any additional processing required. Unity automatically generates the final map data based on the map configuration. Different platforms (IOS, Android, PC) support a different map format, in the form of a configuration file, the final convenient to generate a variety of maps. This is a very good practice, and you can visually see the different formats of the map representation in the development environment.

Configuration Interface for maps

As you can see, there are many configuration properties for the map. Different textures will have different configurations, and some properties will have a significant impact on memory and performance. You can see that now this is an RGB map of X 512 with a memory size of 1M. If you limit the use of 50M of mapped memory, it can only load 50 posters, which is obviously not enough.

Map Initial Size

A commonly used technique in three-dimensional computer graphics rendering is called mipmap. To speed up rendering and reduce graphics aliasing, the map is processed into a series of pre-computed and optimized images. For 2D maps used by the UI, we need to turn off mipmap to avoid loss of precision. At the same time in the test we also found that the opening of Mipmap did not bring much performance improvement, in the hands of the scene, we are very close to the sight, and there is no excessive demand in this regard. Close mipmap at the same time we can save 33% of memory, this is a relatively good upgrade. When we turn off mipmap, we see that the decal becomes 0.8M, and this should be 768KB.

Map off Mipmap

A small upgrade, but it is important to note that this is a decision made after the test, different circumstances of the decision is not the same.

Next we discuss the mapping compression, etc is the format accepted by all Android, the compression quality of this format is poor. But in most cases, it is difficult to see the difference on the screen of the mobile phone so small, the rendering itself is a visual deception, if you feel satisfied that there is no problem. ETC 2 on the picture quality has a bigger increase, but need OPGL ES 3.0 or more to support, this should be based on the supported models to make the decision. There is no too much discussion about the compression format, see the official Unity document.

Setting the compression format to etc after the map size of 128KB, reduced by 6 times times, this is a very large increase.

After the map is compressed

In other words max size This property, really need to 512x512 such a large map, 256x256 is not enough. Make such a decision, then look at the effect on the real machine, the map size is limited to 256, and the last map size is 32KB. The total was reduced by 32 times times, and now we can load 1600 stickers, believing that this number will meet the needs of most projects.

After setting the maximum size of the decal

Finally, read/write enable this property, if you open this property, the runtime map size will be doubled, memory will be stored in an extra copy of the map data. In most cases this is not necessary, so by default this property is turned off and opened when needed.

In this optimal configuration we reduced the size of the map by 64 times times, from the beginning of 25 to the last 1600, amazing optimization. Resource format configuration is the most basic module in overall resource management, but it is also the most important module, and he determines how many resources you can display.

Resource Configuration Tool

Under normal circumstances, mapping resources to be submitted by the art, different kinds of stickers have the same configuration file, iOS configuration format and Android will be different. It's hard to ask the art to have a deep understanding of the resource allocation, and it's very cumbersome to configure some properties each time. This is where the program is needed to help do some work.

First, based on the previous understanding, we extracted some of the property settings.

      PublicClasstextureimportdata:importdata {public TextureAlphaMode Alphamode = texturealphamode.formtexture; public textureimportertype textype = Textureimportertype.default; public textureimportershape shapetype = textureimportershape.texture2d; public textureimporterformat androidformat = textureimporterformat.etc2_rgb4; public textureimporterformat iosformat = textureimporterformat.pvrtc_rgb4; public bool readwriteenable = FALSE; public bool mipmapenable = false; public int MaxSize = -1;}     

You can then apply this configuration to a map

PublicStaticvoidFormattexture(String path, Textureimportdata data) {Textureimporter Timporter = Assetimporter.getatpath (path) as Textureimporter;if (Timporter = = null)Returnif (timporter.texturetype! = data. Textype) {timporter.texturetype = data. Textype; } timporter.isreadable = data. readwriteenable; timporter.mipmapenabled = data. mipmapenable;if (data. MaxSize > 0) {timporter.maxtexturesize = data. MaxSize; } textureimporterplatformsettings settingandroid = Timporter.getplatformtexturesettings ( Editorconst.platformandroid); Settingandroid.overridden = true; settingandroid.format = data. Getformatbyalphamode (data. Androidformat, Timporter); Settingandroid.maxtexturesize = timporter.maxtexturesize; Timporter.setplatformtexturesettings (settingandroid); Textureimporterplatformsettings Settingios = timporter.getplatformtexturesettings (EditorConst.PlatformIos); Settingios.overridden = true; settingios.format = data. Getformatbyalphamode (data. Iosformat, Timporter); Settingios.maxtexturesize = timporter.maxtexturesize; Timporter.setplatformtexturesettings (Settingios); Timporter.saveandreimport ();}   

Finally, with the art of making a convention or specification, you can set the map format in bulk by directory and a regular.

Generally speaking, more than 10 rules can cover all situations, and if there are omissions, add a rule. One more detail to consider here is what to do if a file is overwritten by multiple rules. It is assumed that some general rules are added at the outset, and some special rules are added later. and follow the rules to set the properties, the following rules will also overwrite the previous rules. So this is only used to introduce the order attribute of a rule configuration, the order can be modified, the order of the following rules prevail. Then, for easy viewing, you can also record the number and size of the map under the current rule, so there is a more intuitive understanding.

PublicClassImportData {PublicString RootPath =public string filenamematch =  "*. *"; public int Index = -1; public int totalcount = 0; public int totalmemuse = 0; public bool prebuild = true; public bool forceset = false; public bool alwaysmatch = false;}    

After the data is designed, the end is to implement a window interface to configure these properties, and to display the required information on the window. Windows are implemented directly with Unity's API and are very handy.

Map Formatting Tool

Finally, I put the resource allocation tool to technical art (tech Artist) to use, the art side has the need to adjust, direct configuration can, do not need to continue to participate.

Resource management in a project

Then consider whether there is a resource mismatch, resource allocation is reasonable, at present, our resources in a what kind of situation? A scenario is needed to get more information. The tool above has seen the ability to statistically map resources, implementing a function that can export statistics on resource usage, and a list of resources sorted by size. Each statistic is then saved, and a resource growth is observed in the project in comparison to the daily statistical results.

Map Statistics List

I chose a list of problematic stickers to see if there was a problem with the configuration and it was easy to expose it in the list.

There are also some ideas that are not practiced, such as displaying not only the map size, but also the compressed format of the map. Know the size of this map is 2M, but do not know whether it is compressed before 2M or after compression. At the same time the project is inevitably there is duplicate mapping, you can consider the program to achieve a function to do duplicate map contrast and so on.

However, to consider the cost and benefits of input, the focus on TOP10 and the daily changes in resources have been to a certain degree of control of the project. Can focus on more critical product development, where the actual product quality assurance.

Summarize

From the focus on the configuration of the resource itself, to how to set the resource configuration to the last floor of the overall preview data. Everything is very simple, and the main thing to share is the process and way of thinking. While this is just about working on a unity project, a lot of ideas and methods are shared. But this is only a summary of my current project experience, different projects have different backgrounds and problems. It is still necessary to think deeply about the problem itself and propose practical solutions.

At the same time, much of the work here is to show more information that is observable throughout the project. The more people learn about a thing, the easier it will be to modify it. For example, art can also observe the explosion of our project resources, and then subconsciously control the growth of the amount of resources.

Report

Resource Configuration Tool



Carber
Links: https://www.jianshu.com/p/4646d34223b1
Source: Pinterest
The copyright of the book is owned by the author, and any form of reprint should be contacted by the author for authorization and attribution.

Resource management in a unity project

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.