Unity Game Scene Loading loading detailed

Source: Internet
Author: User

The loading in the game are now very beautiful, but in the final two types, static loading and dynamic loading.
A static loading may be a background picture. And the dynamic loading is the reading of a thing in the "circle".

1. Static Loading:
Advantages: Read the scene using synchronous method is possible, because it is a synchronous method so the speed of reading is the fastest, do not update the interface, because the synchronous execution of the method when the program is waiting for the end of the read.
Execute Application.loadlevel ("name") and synchronize the method to load your scene.

Cons: Loading if the interface does not move, then the user experience must be poor, because the reading time if too long users will mistakenly think the cell phone card dead. In fact, I personally still feel it is best to use dynamic loading loading, although the read time is not static loading fast, but the user experience is very good.

2. Dynamic Loading:
Advantages: The interface can be animated when reading, even can do some small games. The scene can be loaded asynchronously, so the update on the script executes every frame, so you can do something dynamic.

Disadvantage: No shortcomings, hey, we suggest you must use dynamic loading,
Execute asyncoperation async = Application.loadlevelasync ("Mybiglevel"); method to load the scene asynchronously.

Problems:

A. Can the game only be a scene?

Yes, and I've seen some games that only make one scene, because all of your things can be loaded dynamically, such as scene models, character models, scene baking maps, and so on.
Executes the gameobject.instantiate ("Prefabname") method to read.
But the game only makes one scene with two deadly problems.

1.Loading interface No animation or animation is difficult to see
Because there is a way to have animation, such as the method of reading your scene into 3, with a collaborative task in order to execute the three methods, because the collaborative task does not execute one, will call all the script update, so according to this logic your interface animation can move 3. What if you really want to do this? I advise you to give up early. Because your synchronization method will not be split so evenly, even if the animated animation will be very ugly!!

2. Memory unloading completely requires your own manual maintenance
Unity has the concept of a cache pool for read memory, and if you switch the scene in its standard way, unity will automatically help you unload the unreferenced resource objects from memory when switching scenes. But you are now a scene, then unload the memory of things will be the self-maintenance of the manual.

Two. Asynchronous load scenario Why did you end up with a card?

The culprit is that unity does not support multithreading. The game load is divided into two parts, the first part is the loading scene, you can save the scene of the known models are stored in scenes, when you call the asynchronous loading scene, the progress animation will be very uniform. Load scene you can understand unity itself in multi-threaded loading, it is possible that his background is also synchronous, but we do not see the source from its effect on its loading scene is multithreaded.

But the problem is in the second step, because you need to load the unknown model, for example, when you go into the dungeon loading scene, the scene does not know that you have a few heroes. So after the scene is loaded you still need to load these models. Whether you are working with a collaborative task or in a method, because Unity does not have multi-threaded, generally in order to faster into the game here the load will choose to sync load, so you will find that most of the game progress bar loaded in the end will be stuck.
In order to solve this problem, it is necessary to avoid loading the scene after the load of the synchronous loading of the method, try to let him do less load.

1. As much as possible to include some resources, I think some people to save resources, open the scene after the dynamic loading of some small objects on the ground. I think this situation is more than a few scenes to be able to do, do not have in a synchronous method to contribute too much of the thing.

2. The character model can consider preloading or resident memory. Because your character model may not be used more than in combat.

Iii. number of reductions in loading
Especially in battle scenes, repeat the challenge of the same level, as the scene does not change, try not to read the scene. So you can write a loading interface, depending on the current scene name and the name of the scene you need to load if the scene is the same, do not load, if the scene is different then to load, this can actually save a lot of time.

1     //parameter 1 things to do before loading the scene2     //parameter 2 The newly loaded scene name3     //parameter 3 What to do after loading a scene4      Public voidLoadscene (System.Action before,stringScenename, System.Action end)5     {   6 before ();7         if(Application.loadedlevelname! =scenename)8{//asynchronously loads the scene and calls the end method when it is loaded. 9}Else Ten         {  One end (); A         } -}

Official API Method

1  Public classExampleclass:monobehaviour {2 IEnumerator Start () {3AsyncOperationAsync= Application.loadlevelasync ("Mybiglevel");4         yield return Async;5Debug.Log ("Loading Complete");6     }7}

    • This article fixed link: http://www.xuanyusong.com/archives/2764
    • Reprint Please specify: Rain pine Momo June 14, 2014 Yu Yussong Momo Program Research Institute published

Unity Game Scene Loading loading detailed

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.