How to: Scene Loader
Scenes to be loaded, set-up:
Loading a scene
Changing the loading screen
Create your own loading bar
- Use the ScenePrefabHolder prefab to divide your scenes into pieces to load, one after the other:
- Place it in your scene and drag some of your objects or prefabs into it.
- Break the prefab instance and rename (Click on object in hierarchy, then at top of unity editor, GameObject > Break prefab instance).
- Save this as a new prefab
- Follow steps 1,2,3 again, for each object or group of objects that you want to load.
- The more ScenePrefabHolder's you use, the better the feedback from the loading bar. So split your scene into as many holders as possible!
- Place the SceneLoader prefab into your scene:
- Increase the “Size” value of the SceneLoader script, to the number of ScenePrefabHolder's you have in the scene.
- Drag each of the ScenePrefabHolder's from the Project Assets NOT the hierarchy into the the “Element” slots.The scene will be loaded in this order (e.g. “Element 3” will be loaded after “Element 2”).
- Any MonoBehaviour's (scripts) that are attached to these objects, that also rely on other objects in the scene, MUST have their inheritance changed from MonoBehaviour to SceneLoadBehaviour in order to prevent scripts running before the entire scene has been loaded.
- To make this change, open up your script and at the top where it says MonoBehaviour, simply replace it with SceneLoadBehaviour.
- You can just make this change to all scripts that run on the loaded scenes, instead of selected ones if it is easier for you. (ADVISED)
Loading a scene
- Load level with Unity 4.6 new GUI system:
- SceneLoad.LoadLevel("Level1", "SceneLoader/Prefabs/MainMenu/LoadingScreenCanvas");
- Load level with OnGUI:
- SceneLoad.LoadLevel("Level1", "SceneLoader/Prefabs/MainMenu/LoadingScreenOnGUI");
Changing the loading screen
- Unity 4.6 new GUI system:
- Change the prefab called LoadingScreenCanvas in SceneLoader > Resources > Prefabs > MainMenu.
- OnGUI:
- Change the script LoadingScreenOnGUI.
Create your own loading bar
- Inherit from LoadingScreen and write custom code for UpdateLoadingText() & UpdateLoadingBar() (look at LoadingScreenUI & LoadingScreenOnGui for example).