Unity3D game development path-my one-week work summary, unity3d Game Development
Hello, everyone. Welcome to my blog. I am Qin Yuanpei. My blog address is http://blog.csdn.net/qinyuanpei.
It has been a week since I went to work in the company. Taking the weekend off, I want to write down my recent feelings and thoughts in my work and life, because life is a constant accumulation and accumulation, the process of achieving self-transcendence. As my first job, although I was not as good as I thought, I was still working very hard. The first project claimed after work was a real estate roaming demonstration project, because the company was previously engaged in film and television later, so after deciding to do this project, the company's leadership does not have a clear understanding of the specific effects of this project, therefore, no specific feasible solution is available in the early stage of project development, no matter the familiarity with the technology used by the project or the overall planning of the project. Since the company's leadership was from an artistic background, since I joined the company, the company has been immersed in a depressing atmosphere of working overtime to create a model.
On the first day I entered the company, the person in charge of the company demonstrated a video to me, telling me that the project was just like this, then let me start to write the so-called "Framework", because he is not familiar with the Unity3D technology, so basically from my work, all work related to Unity3D is done by me alone. I am flattered by the pressure of a new employee to take on the "Main Journey, however, since he and I were not very old and always respected my ideas, the Unity3D project was handed over to me with confidence, the result is that it took me about a week to write the overall framework [sneer :)]. However, in the process of designing the entire project, because the art is busy with modeling, the UI design is basically blank. As a newcomer who has just entered the company and has no right to speak, in this case, I can only make a DEMO by myself, and then listen to the opinions of the leaders for repeated modifications. However, in this case, if the project requirements change at the end of the project, maybe the UI design needs to be re-created. I personally hate to do the UI, because sometimes the UI may cause debugging errors due to unreasonable parameter settings and other reasons, in this way, you have been searching for various possible errors for a long time, but you finally find that the reason is that the setting of a parameter is unreasonable, which is so painful! I prefer Cocos Studio to create a UI, that is, let art directly prepare the UI in the UI editor and export it as a data type that can be parsed by the program, in this way, the program only needs to resolve the data and bind the relevant UI events to them. However, the reality is cruel. In this project, because of the uncontrollability of real estate, house type, home decoration and other factors, all of them are handled in the form of Dynamic Loading During UI design, because you are not sure how many elements are displayed in these UIS, I will consider this when designing this framework, it means to manually adjust and control all the parts that require manpower (such as model placement and Scenario Design, therefore, all parts related to the UI (such as dynamic loading of UI elements, loading of models, and local configuration files) are implemented through dynamic loading, because the third part of the project involves a large number of models, this part is to package the model file into an AssetBundle file and load it from the server.
I don't know how company leaders decided to use Unity3D for this project at the beginning, because considering the needs of virtual presentation, this project is finally presented to users on a webpage, in this way, we need to consider the issue of resource organization. In this way, during the first week of work, I thought of the technical solutions that I had never "made up" when I was playing games at school, the basic idea is that the local game file will eventually retain only one main scenario file (MainMenu. cs), the main scenario is responsible for maintaining all the logic from the real estate to the house type to the home decoration, the dynamic part of each scenario is through the Resource. load () and AssetBundle are implemented to put these scenarios on the server. The main scenario determines which scenario to Load. Because the entire project is mainly divided into three parts: Real Estate, house type, and home decoration, the logic except the model is the same, so the logic of this part is written as a public script, when creating these scenarios, you only need to drag the script to some objects. Because you need to obtain information about the real estate that meets the screening requirements from the server, you also need to write the server-side logic. Currently, there are no server-side programs in the project team. I cannot help you with this Part, haha. If you want to make the final web page more beautiful, you may need to add front-end engineers. Currently, this is also Blank! Well, it's my dream to become a full-stack engineer even when programmers are not doing anything in their projects. But I can't do it now! I don't know what the relationship between the program and the art is like in game development. Anyway, in my current project team, the existence of this program is too weak, it may be because the program proportion in the project team is too low. Maybe I am not familiar with it, but yesterday I ran an art project and asked if I could teach him Unity3D, because he thinks that the model that has been well done is dead after all. Haha, I feel a sense of mutual sorrow. Well, let's talk about these things first. Today I want to share with you some of the pitfalls I encountered during the development process, because I am a programmer, in the final analysis, I want to talk to you about programs!
I. "cross-domain" problems encountered when downloading AssetBundle
This problem is mainly caused by the absence of a crossdomain on the server. xml files. This is a policy proposed by Adobe to ensure that Flash can access files across domains, when this error occurs, you can download the AssetBundle file from the server through a browser. However, an error is reported when you attempt to access the file using WWW in Unity, I do not remember the specific error message, but the error message clearly states that it is due to the lack of crossdomain. xml file, so the solution is to add such a file in the root directory of the server, the content of the file is as follows:
<?xml version="1.0" encoding="UTF-8"?><cross-domain-policy> <site-control permitted-cross-domain-policies="master-only" /> <allow-access-from domain="*" to-ports="*"/></cross-domain-policy>
Specifically, you need to replace "*" with the addresses and ports that allow cross-origin access. Because I am a local server built with the WAMP software, the default value is used here, you still need to explore how to set the content here. However, it is important to consider this issue if you want to use Unity3D for web games or download files from servers!
Ii. Question of dynamically generated UI Prefab being stretched
This problem occurs in the process of dynamically generating UI elements, that is, after an object is generated, the object size and position will change. This problem has been read in Xuan Yusong's blog, however, he didn't clarify the cause of the problem at the time, so when the same problem happened to me, I decided to be the same as him, haha, the solution is to set the localScale of the object to (, 1) and localPosition to (, 0). Of course, based on my traditions, please tell me why!
Iii. AssetBundle mainAsset
This problem occurs when the initial determination of AssetBundle packaging is to package a single object or to Package Multiple objects together, and later found that mainAsset depends on
bool BuildAssetBundle (Object mainAsset,Object[] assets,string pathName, BuildAssetBundleOptions optionsBuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets,BuildTarget targetPlatform= BuildTarget.WebPlayer)
The first parameter in this method means that if a parameter is specified, you can use mainAsset to obtain the main object in AssetBundle. Otherwise, you can only pass in a name through the Load method to obtain the specified object. Here is a strange thing. For example, we select two objects and package them, but the number of objects obtained through LoadAll is not two, during packaging, GamObject and Transform are packaged separately, and child objects under the parent object are also packaged separately. Therefore, this method is not so satisfactory, I hope you will pay attention to this!
Iv. Scenario packaging as AssetBundle
We know that in Unity, we can use the BuildStreamedSceneAssetBundle method to package the scenario as an AssetBundle file and load it into the game as follows. The following describes how to package a scenario:
static function MyBuild(){var levels : String[] = ["Assets/Level1.unity"];BuildPipeline.BuildStreamedSceneAssetBundle( levels, "Streamed-Level1.unity3d", BuildTarget.WebPlayer); }
Next we can load it into the game through the WWW Method
function Start () {// Download compressed scene. If version 5 of the file named "Streamed-Level1.unity3d" was previously downloaded and cached.// Then Unity will completely skip the download and load the decompressed scene directly from disk.var download = WWW.LoadFromCacheOrDownload ("http://myWebSite.com/Streamed-Level1.unity3d", 5);yield download;// Handle errorif (download.error != null){Debug.LogError(download.error);return;}// In order to make the scene available from LoadLevel, we have to load the asset bundle.// The AssetBundle class also lets you force unload all assets and file storage once it is no longer needed.var bundle = download.assetBundle;// Load the level we have just downloadedApplication.LoadLevel ("Level1");}
Note that the last line uses the LoadLevel method to load a scenario. This method requires a parameter, which is the level we registered in Unity3D, that is, you need to add the game to the level list when compiling the game. Now, the question is: whether this Level11 is a local scenario or a download scenario. Since we have chosen to load a scenario from the server, there should be no local scenario, this level does not exist in the game level list. Therefore, if the last code is called, the system will prompt that this level cannot be found. I 've struggled for a long time here, and finally found that, now the local level is ready and then added to the level list. When the local level is packaged as AssetBundle, you can still load this scenario from the server by deleting the current level locally. This is the result of my own experiments. I don't know if it is true or not. I hope a friend who knows this can tell me if it is true or not, because this method is a bit cool, haha.
Well, today's content is like this, because the current project has found these problems for the time being, so more Unity3D content needs to be found when the project is slowly advancing, hope everyone will like it!