BomberUnits
...a Unity learning project
SceneReference Class Reference

A wrapper that provides the means to safely serialize Scene Asset References. More...

+ Inheritance diagram for SceneReference:
+ Collaboration diagram for SceneReference:

Public Member Functions

bool IsCurrentScene ()
 
void OnBeforeSerialize ()
 
void OnAfterDeserialize ()
 

Static Public Member Functions

static implicit operator string (SceneReference sceneReference)
 

Properties

string ScenePath [get, set]
 

Private Attributes

string scenePath = string.Empty
 

Detailed Description

A wrapper that provides the means to safely serialize Scene Asset References.

Internally we serialize an Object to the SceneAsset which only exists at editor time. Any time the object is serialized, we store the path provided by this Asset (assuming it was valid).

This means that, come build time, the string path of the scene asset is always already stored, which if the scene was added to the build settings means it can be loaded.

It is up to the user to ensure the scene exists in the build settings so it is loadable at runtime. To help with this, a custom PropertyDrawer displays the scene build settings state.

Known issues:

  • When reverting back to a prefab which has the asset stored as null, Unity will show the property as modified despite having just reverted. This only happens the fist time, and reverting again fixes it. Under the hood the state is still always valid, and serialized correctly regardless.

Definition at line 29 of file SceneReference.cs.


The documentation for this class was generated from the following file: