Unity3d: dynamically add and create scenarios, and unity3d scenarios
In Unity3d, most scenarios (scene) are implemented by clicking add current IN build settings or dragging the scenario to the Panel. If this is not done, Your scenarios will not be loaded, even if you have an absolute path.
That is to say, the number of scenarios to be loaded in a game is mostly fixed. Dog planing Learning Network]
This method may cause a lot of inconvenience and is not easy to dynamically load scenarios. So what we want to talk about today is a method for dynamic loading scenarios.
First, you need an editor file in the editor folder. Note: This file cannot be inherited from monobehaviour
- Public class BuildSceneEditor {[@ MenuItem ("build/BuildWebplayerStreamed")] static void Build () {string [] levels = new string [] {"Assets/Level1.unity ", "Assets/Level2.unity"}; BuildPipeline. buildStreamedSceneAssetBundle (levels, "streamed. unity3d ", BuildTarget. webPlayer );}}
Copy code
In this way, a button appears in your unity editor. If you execute this button, the created streamed will appear in the directory of your Assets at the same level. unity3d file, you put this file on the server, the next step is to download this file and build it.
- WWW download = WWW. LoadFromCacheOrDownload ("http: // xxx/streamed. unity3d", 0); yield return download; Application. LoadLevel ("Level1 ");
Copy code
Have you noticed this. After downloading, you can directly loadlevel without manually performing the add current operation.