Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/gilzoide/unity-scene-reference

Autogenerated ScriptableObjects that are stable references to the scenes configured in Build Settings, even if they are moved/renamed
https://github.com/gilzoide/unity-scene-reference

package reference scene unity unity3d upm upm-package

Last synced: 1 day ago
JSON representation

Autogenerated ScriptableObjects that are stable references to the scenes configured in Build Settings, even if they are moved/renamed

Awesome Lists containing this project

README

        

# Stable Scene Reference
[![openupm](https://img.shields.io/npm/v/com.gilzoide.stable-scene-reference?label=openupm&registry_uri=https://package.openupm.com)](https://openupm.com/packages/com.gilzoide.stable-scene-reference/)

Autogenerated `ScriptableObject`s that are stable references to the scenes configured in Unity Build Settings.

## Features
- Scene references are automatically generated/refreshed whenever the scenes in Build Settings change or any scene is renamed/moved, no code or manual setup required
- Scene references are stable and based on their GUID: if a scene is renamed/moved, all existing references to the corresponding `SceneReference` are maintained
- No extra files are created in your project: everything lives in the asset imported from an empty file that lives in the package's own folder
- Utility methods `SceneReference.Load`, `SceneReference.LoadAsync` and `SceneReference.UnloadAsync` to load/unload scenes directly from references

## Caveats
- Only Scenes enabled in Build Settings are generated
+ Referencing scenes that are not in Build Settings is not supported at all
+ If you have multiple build configurations that involve changing which Scenes are enabled, previous references to disabled ones will be missing from the build and will be `null` at runtime

## How to install
Either:
- Use the [openupm registry](https://openupm.com/) and install this package using the [openupm-cli](https://github.com/openupm/openupm-cli):
```
openupm add com.gilzoide.stable-scene-reference
```
- Install via [Unity Package Manager](https://docs.unity3d.com/Manual/upm-ui-giturl.html) using the following URL:
```
https://github.com/gilzoide/unity-scene-reference.git#1.0.0
```
- Clone this repository or download a snapshot of it directly inside your project's `Assets` or `Packages` folder.

## How to use
1. Declare [SceneReference](Runtime/SceneReference.cs) fields in your scripts
2. Use the Inspector to assign any of the `SceneReference`s automatically generated from your project's Build Settings
3. Use `SceneReference.Load`, `SceneReference.LoadAsync` and `SceneReference.UnloadAsync` to load/unload scenes.
Alternatively, use `SceneReference.BuildIndex` or `SceneReference.Path` as argument to [SceneManager](https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.html) load/unload methods.
4. Enjoy 🍾

## Related projects
- https://github.com/NibbleByte/UnitySceneReference
- https://github.com/starikcetin/Eflatun.SceneReference