Skip to content

Commit 96141d5

Browse files
committed
Update documentation and bump version, restrict API
1 parent 8fb97cf commit 96141d5

File tree

3 files changed

+98
-28
lines changed

3 files changed

+98
-28
lines changed

Documentation~/README.md

Lines changed: 95 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
[Unity Package Manager]: https://docs.unity3d.com/Manual/upm-ui.html
22
[Samples~]: ../Samples%7E
3+
[Defaults Sample]: ../Samples%7E/Defaults
4+
[Changelog]: ../CHANGELOG.md
5+
6+
[Scriptable Scene Window]: ../Editor/ScriptableSceneManagerWindow.cs
37

48
[Scriptable Scene]: ../Runtime/ScriptableScene.cs
59
[Scriptable Scene Collection]: ../Runtime/ScriptableSceneCollection.cs
610
[Scriptable Scene Controller]: ../Runtime/ScriptableSceneController.cs
711

812
[Scriptable Scene Transition]: ../Runtime/Transitions/ScriptableSceneTransition.cs
13+
[Fade Scriptable Scene Transition]: ../Runtime/Transitions/FadeScriptableSceneTransition.cs
914
[Fade Canvas]: ../Runtime/Transitions/FadeCanvas.cs
1015

1116
# Documentation
1217

18+
This package provides as set of utilities, editor windows and scripts to manages scenes in your Unity projects. It works by setting up a set of assets which can then be used as references to load groups of scenes via editor windows (also during runtime) and runtime scripts.
19+
1320
## Getting Started
1421

15-
Open [Unity Package Manager], select _Scriptable Scenes_ package and import _Defaults_ sample:
22+
Open [Unity Package Manager], select _Scriptable Scenes_ package and import [Defaults Sample]:
1623

1724
<p align="center">
1825
<img src="samples.png"/>
@@ -24,24 +31,34 @@ Make sure _SetupScene_ and _PlayScene_ are added to _Build Settings_:
2431
<img src="build-settings.png"/>
2532
</p>
2633

27-
Open _Scriptable Scene_ window by selecting _Window/CHARK/Scriptable Scenes_ menu item:
34+
Open [Scriptable Scene Window] by selecting _Window/CHARK/Scriptable Scenes_ menu item:
2835

2936
<p align="center">
3037
<img src="open-window.png"/>
3138
</p>
3239

33-
Select the action to perform with _Default_ collections imported from the sample:
40+
This will open an Editor window which will allow you to view all [Scriptable Scene Collection] assets present in the project.
41+
42+
The [Defaults Sample] contains a set of [Scriptable Scene] assets and [Scriptable Scene Collection] assets which can be used as a baseline. Additionally, it includes a _SetupScene_ which can be used as a setup/preload scene. It also includes components needed for scene loading logic to work, namely the [Scriptable Scene Controller].
43+
44+
If you create new [Scriptable Scene Collection] assets, they will automatically appear in this window. Additionally, you can move, edit or delete the files created by this sample as per your project requirements:
3445

3546
<p align="center">
3647
<img src="window.png"/>
3748
</p>
3849

50+
You can perform the following actions on each entry:
51+
3952
- **Open** - open selected collection in scene view & hierarchy.
4053
- **Play** - start the game and load selected collection.
4154
- **Load** - load selected collection, only available during play mode. This is handy to quickly switch between the scenes when the game is running.
4255

56+
**Note**, rearranging entries in this list will only affect your local editor and will not show up in version control.
57+
4358
## Creating a new collection
4459

60+
Instead of importing samples, you can start from scratch and create each asset and component manually.
61+
4562
To create a new collection you'll need the following:
4663

4764
- [Scriptable Scene] asset.
@@ -55,68 +72,72 @@ And **optionally**:
5572

5673
### Scriptable Scene
5774

58-
First you'll need to define scenes which go into the collection. Instead of specifying a hard-coded scene path or build index, this package provides a way to safety refer to scenes via Scriptable Objects (_Scriptable Scene_ assets).
75+
First you'll need to define scenes which go into the collection. Instead of specifying a hard-coded scene path or build index, this package provides a way to safety refer to scenes via Scriptable Objects ([Scriptable Scene] assets).
5976

60-
To create a _Scriptable Scene_ asset, right-click in the _Project Window_ and select _Create/CHARK/Scriptable Scenes/Scriptable Scene_:
77+
To create a [Scriptable Scene] asset, right-click anywhere in the _Project Window_ and select _Create/CHARK/Scriptable Scenes/Scriptable Scene_:
6178

6279
<p align="center">
6380
<img hspace="2%" width="30%" src="scriptable-scene-setup.png"/>
6481
<img hspace="2%" width="30%" src="scriptable-scene-play.png"/>
6582
</p>
6683

67-
You can adjust the following properties on this asset:
84+
After creating, select the asset, set the **Pretty Name** and select the correct **Scene Asset**.
85+
86+
Available properties for customization:
6887

69-
- **Scene Asset** - the `.unity` scene this asset is referring to. Drag in the scene file this asset is referring to.
88+
- **Scene Asset** - the `.unity` scene this asset is referring to. Drag in the scene file you want this asset to load.
7089
- **Pretty Name** - user-defined name for the scene. If left blank, a default name will be used.
71-
- **Is Active** - should this scene be activated when it gets loaded by a collection? Set this to `true` for gameplay scenes.
90+
- **Is Active** - should this scene be [activated](https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.SetActiveScene.html) when it gets loaded by a collection? Set this to `true` for gameplay scenes.
7291
- **Is Persist** - should this scene never be unloaded, even when switching collections? Set this to `true` for setup/preload scenes.
73-
- **Scene Events** - events invoked on this scene.
92+
- **Scene Events** - events invoked on this [Scriptable Scene] asset.
7493

7594
### Scriptable Scene Collection
7695

77-
Once you have defined a set of _Scriptable Scene_ assets, you'll need to create a _Scriptable Collection_ asset which will be used to group and load a set of scenes at the same time. Loading will be done additively.
96+
Once you have defined a set of [Scriptable Scene] assets, you'll need to create a [Scriptable Scene Collection] asset which will be used to group and load a set of scenes at the same time. These scenes will be loaded [additively](https://docs.unity3d.com/ScriptReference/SceneManagement.LoadSceneMode.Additive.html).
7897

79-
To create a _Scriptable Scene Collection_ asset, right-click in the _Project Window_ and select _Create/CHARK/Scriptable Scenes/Scriptable Scene Collection_:
98+
To create a [Scriptable Scene Collection] asset, right-click in the _Project Window_ and select _Create/CHARK/Scriptable Scenes/Scriptable Scene Collection_:
8099

81100
<p align="center">
82101
<img src="scriptable-scene-collection.png"/>
83102
</p>
84103

85-
You can adjust the following properties on this asset:
104+
Open the asset, set **Pretty Name** and add your [Scriptable Scene] assets.
105+
106+
Available properties for customization:
86107

87108
- **Pretty Name** - user-defined name for the collection. If left blank, a default name will be used.
88-
- **Transition** - _Scriptable Scene Transition_ asset which can be used to smoothly transition between scenes. If left unset, no transitions will be used.
89-
- **Scriptable Scenes** - scenes to load when this collection is loaded. The order of the scenes in this list defines how they appear in the scene hierarchy.
90-
- **Collection Events** - events invoked on this collection.
91-
- **Scene Events** - events invoked on any of scenes in this collection.
92-
- **Actions** - set of actions that can be performed with this collection. These are the same actions as in _Scriptable Scene_ window.
109+
- **Transition** - [Scriptable Scene Transition] asset which can be used to smoothly transition between scenes. If left unset, no transitions will be used.
110+
- **Scriptable Scenes** - [Scriptable Scene] assets to load when this collection is loaded. The order in this list defines the order of scenes in the scene hierarchy.
111+
- **Collection Events** - events invoked on this [Scriptable Scene Collection].
112+
- **Scene Events** - events invoked on any of [Scriptable Scene] assets in this collection.
113+
- **Actions** - set of actions that can be performed with this collection. These are the same actions as in [Scriptable Scene Window].
93114

94115
### Scriptable Scene Controller
95116

96117
Once you have a set of collections ready, do the following in your primary setup/preload scene:
97118

98119
- Create a new _GameObject_.
99-
- Add _Scriptable Scene Controller_ component.
120+
- Add [Scriptable Scene Controller] component.
100121
- Specify **Initial Collection** to define which collection loads first in build.
101122

102123
<p align="center">
103124
<img src="scriptable-scene-controller.png"/>
104125
</p>
105126

106-
The _Scriptable Scene Controller_ component manages scene loading. You should always an instance of this component in one of your scenes in order to use this package. Keep in mind that only one instance of this component may exist in them game, therefore it is recommended to place this component in your setup/preload scene.
127+
The [Scriptable Scene Controller] component manages scene loading. You should always an instance of this component in one of your scenes in order to use this package. Keep in mind that only one instance of this component may exist in them game, therefore it is recommended to place this component in your setup/preload scene.
107128

108129
You can adjust the following properties on this component:
109130

110-
- **Initial Collection** - collection which will be loaded first in build.
131+
- **Initial Collection** - [Scriptable Scene Collection] which will be loaded first in build. Usually a set of scenes representing the menu or a splash screen.
111132
- **Initial Collection Load Mode** - which Unity Lifecycle method to use when loading the **Initial collection**.
112-
- **Collection Events** - events invoked on any collection in the game.
113-
- **Scene Events** - events invoked on any scene in the game.
133+
- **Collection Events** - events invoked on any [Scriptable Scene Collection].
134+
- **Scene Events** - events invoked on any [Scriptable Scene].
114135

115136
### Fade Transition (optional)
116137

117-
By default, the package includes a simple fade transition which can be used to fade-in/fade-out a loading screen when switching between scenes (custom transitions can also be created by inheriting [ScriptableSceneTransition] class).
138+
By default, the package includes a simple fade transition which can be used to fade-in/fade-out a loading screen when switching between scenes (custom transitions can also be created by inheriting [Scriptable Scene Transition] class).
118139

119-
To create a new _Fade Scriptable Scene Transition_, right-click in the _Project Window_ and select _Create/CHARK/Scriptable Scenes/Fade Scriptable Scene Transition_:
140+
To create a new [Fade Scriptable Scene Transition], right-click in the _Project Window_ and select _Create/CHARK/Scriptable Scenes/Fade Scriptable Scene Transition_:
120141

121142
<p align="center">
122143
<img src="fade-transition-asset.png"/>
@@ -130,8 +151,57 @@ You can adjust the following properties on this asset:
130151
- **Fade In Duration Seconds** - how long should the fade in effect take.
131152
- **Fade Out Duration Seconds** - how long should the fade out effect take.
132153

133-
Finally, after you have created the _Fade Scriptable Scene Transition_ asset, add [Fade Canvas] component onto the loading screen `Canvas` in your setup/preload scene:
154+
Finally, after you have created the [Fade Scriptable Scene Transition] asset, add [Fade Canvas] component onto any `Canvas` which contains loading screen logic in your setup/preload scene:
134155

135156
<p align="center">
136157
<img src="fade-transition-canvas.png"/>
137158
</p>
159+
160+
## Scripting
161+
162+
### Loading Collections via Code
163+
164+
First you must obtain a reference to a [Scriptable Scene Controller]. This can be done via [SerializeField](https://docs.unity3d.com/ScriptReference/SerializeField.html) or any other means, such as using `Object.FindObjectOfType<ScriptableSceneController>()` and so on, depending on your project setup.
165+
166+
Additionally, you'll need to obtain a set of [Scriptable Scene Collection] references. Since these as Scriptable Objects, all you need to do is define a set of [SerializeField](https://docs.unity3d.com/ScriptReference/SerializeField.html) and load them directly. However, you can structure this however you like, e.g., by maintaining lists of scenes, loading them randomly, etc...
167+
168+
```csharp
169+
using CHARK.ScriptableScenes;
170+
using UnityEngine;
171+
172+
internal sealed class GameManager : MonoBehaviour
173+
{
174+
// Obtain a reference to ScriptableSceneController
175+
[SerializeField]
176+
private ScriptableSceneController controller;
177+
178+
// Obtain a set references to ScriptableSceneCollection
179+
[SerializeField]
180+
private ScriptableSceneCollection mainMenuCollection;
181+
182+
[SerializeField]
183+
private ScriptableSceneCollection playCollection;
184+
185+
// Load levels via ScriptableSceneController
186+
internal void LoadMainMenuLevel()
187+
{
188+
controller.LoadSceneCollection(mainMenuCollection);
189+
}
190+
191+
internal void LoadPlayLevel()
192+
{
193+
controller.LoadSceneCollection(playCollection);
194+
}
195+
}
196+
```
197+
198+
### APIs
199+
200+
Explore public APIs defined in the following scripts. Each `public` method and property is documented and should be self-explanatory:
201+
202+
- [Scriptable Scene]
203+
- [Scriptable Scene Collection]
204+
- [Scriptable Scene Controller]
205+
- [Scriptable Scene Transition]
206+
207+
For breaking changes, keep an eye out [Changelog].

Runtime/ScriptableSceneController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private enum CollectionLoadMode
9797
[Sirenix.OdinInspector.ShowInInspector]
9898
[Sirenix.OdinInspector.ReadOnly]
9999
#endif
100-
public ScriptableSceneCollection LoadingCollection { get; private set; }
100+
private ScriptableSceneCollection LoadingCollection { get; set; }
101101

102102
private void Awake()
103103
{
@@ -172,7 +172,7 @@ public void LoadSceneCollection(ScriptableSceneCollection collection)
172172
}
173173

174174
/// <returns>
175-
/// <c>true</c> i`f a collection which is currently being loaded is retrieved or
175+
/// <c>true</c> if a collection which is currently being loaded is retrieved or
176176
/// <c>false</c> otherwise.
177177
/// </returns>
178178
public bool TryGetLoadingSceneCollection(out ScriptableSceneCollection collection)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"name": "CHARK",
66
"url": "https://chark.io"
77
},
8-
"version": "0.0.9",
8+
"version": "0.0.10",
99
"unity": "2022.3",
1010
"description": "Simple scene loading and management system for Unity Engine, implemented via scriptable objects.",
1111
"keywords": [

0 commit comments

Comments
 (0)