-
Notifications
You must be signed in to change notification settings - Fork 117
Scene Types
In order to load/unload scene with uFrame, a scene must contain a single root game object that is a parent to all other game objects in the scene.
This root game object needs to have a Scene Type component attached in order to be recognized by uFrame as a root game object.
Scene Type node defines how to load a scene and allows for unloading the scene. You can create a Scene Type node in the MVVMGraph in the designer.
Below is an example of a scene base class that is automatically generated from the designer. It has a DefaultKernelScene
property that defines the [kernel scene](Kernel Scene) that will be loaden with the scene and a Settings
property that will contain all settings passed to the scene from the LoadSceneCommand
.
Example UIScene.designer.cs
// ------------------------------------------------------------------------------
// <autogenerated>
// This code was generated by a tool.
// Mono Runtime Version: 2.0.50727.1433
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </autogenerated>
// ------------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public class UISceneBase : Scene {
public override string DefaultKernelScene {
get {
return "KernelScene";
}
}
public virtual UISceneSettings Settings {
get {
return _SettingsObject as UISceneSettings;
}
set {
_SettingsObject = value;
}
}
}
In the {SceneName}SceneSettings
class you can specify properties that can be passed along to the scene when it's loaded.
// Example settings for the UIScene scene type.
public class UISceneSettings : UISceneSettingsBase {
public int Width { get; set; }
public int Height { get; set; }
}
You can specify those settings when loading a scene with a LoadSceneCommand()
.
Publish(new LoadSceneCommand() {
SceneName = sceneName,
Settings = new UISceneSettings() {
Width = 640,
Height = 480
}
});
When the scene loads, you can make use of those settings from the LoadScene()
method of the scene's loader class.
A scene loader is generated for every scene type that exists in the graph.
Scene loaders live as game objects on the [uFrame Kernel](uFrame Kernel).
When a scene with the corresponding Scene Type is loaded, the scene loader will get a reference to the Scene Type instance and pass it to the LoadScene()
method. There you can use those settings to setup the scene properly. That gives a very fine grained control on how scenes are loaded and unloaded.
Below is an example of a loader class generated automatically for the UISceneType. It has two methods:
-
LoadScene()
that will be called after the scene is loaded additively by the Unity'sLoadSceneAdditively()
method. The process of loading the scene with the Unity's method is called Instantiation. -
UnloadScene()
that is called right before the scene is unloaded (the scene root game object is destroyed).
Example UIScene.designer.cs
// ------------------------------------------------------------------------------
// <autogenerated>
// This code was generated by a tool.
// Mono Runtime Version: 2.0.50727.1433
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </autogenerated>
// ------------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public class UISceneLoaderBase : SceneLoader<UIScene> {
protected override IEnumerator LoadScene(UIScene scene, Action<float, string> progressDelegate) {
yield break;
}
protected override IEnumerator UnloadScene(UIScene scene, Action<float, string> progressDelegate) {
yield break;
}
}
Example of using the defined settings in the LoadScene
method.
// This ViewModel must be added to the subsystem instances in the designer.
// See Subsystems wiki page for details.
[inject] public MenuScreenViewModel MenuScreen;
protected override IEnumerator LoadScene(UIScene scene, Action<float, string> progressDelegate) {
MenuScreen.Width = scene.Settings.Width;
MenuScreen.Height = scene.Settings.Height;
}