Adventure Creator  1.74.2
An adventure game toolkit for Unity, by Chris Burton, ICEBOX Studios 2013-2019
AC.SceneChanger Class Reference
Inheritance diagram for AC.SceneChanger:

Public Member Functions

void OnInitPersistentEngine ()
 
int NameToIndex (string sceneName)
 
string IndexToName (int sceneIndex)
 
void SetRelativePosition (Marker marker)
 Calculates the player's position relative to the next scene's PlayerStart. More...
 
virtual Vector3 GetStartPosition (Vector3 playerStartPosition)
 Gets the player's starting position by adding the relative position (set in ActionScene) to the PlayerStart's position. More...
 
float GetLoadingProgress ()
 Gets the progress of an asynchronous scene load as a decimal. More...
 
bool IsLoading ()
 Checks if a scene is being loaded More...
 
void PreloadScene (int nextSceneIndex)
 Preloads a scene. Preloaded data will be discarded if the next scene opened is not the same as the one preloaded More...
 
void PreloadScene (string nextSceneName)
 Preloads a scene. Preloaded data will be discarded if the next scene opened is not the same as the one preloaded More...
 
bool ChangeScene (int nextSceneIndex, bool saveRoomData, bool forceReload=false, bool doOverlay=false)
 Loads a new scene. This method should be used instead of Unity's own scene-switching method, because this allows for AC objects to be saved beforehand More...
 
bool ChangeScene (string nextSceneName, bool saveRoomData, bool forceReload=false, bool doOverlay=false)
 Loads a new scene. This method should be used instead of Unity's own scene-switching method, because this allows for AC objects to be saved beforehand More...
 
void SetTransitionTexture (Texture2D _texture)
 Stores a texture used as an overlay during a scene transition. This texture can be retrieved with GetAndResetTransitionTexture(). More...
 
Texture2D GetAndResetTransitionTexture ()
 Gets, and removes from memory, the texture used as an overlay during a scene transition. More...
 
void ScheduleForDeletion (GameObject _gameObject)
 Deletes a GameObject once the current frame has finished renderering. More...
 
void PrepareSceneForExit ()
 
virtual void PopulateBuildSceneData ()
 
void ResetCurrentScene ()
 
void DrawStatus ()
 
void ActivateLoadedScene ()
 
bool SubScenesAreOpen ()
 
bool AddSubScene (int subSceneIndex)
 Adds a new scene as a sub-scene, without affecting any other open scenes. More...
 
bool AddSubScene (string subSceneName)
 Adds a new scene as a sub-scene, without affecting any other open scenes. More...
 
void RegisterSubScene (SubScene subScene)
 Registers a SubScene component with the SceneChanger. More...
 
void UnregisterSubScene (SubScene subScene)
 
bool RemoveScene (int sceneIndex)
 Removes a scene, without affecting any other open scenes, provided multiple scenes are open. If the active scene is removed, the last-added sub-scene will become the new active scene. More...
 
bool RemoveScene (string sceneName)
 Removes a scene, without affecting any other open scenes, provided multiple scenes are open. If the active scene is removed, the last-added sub-scene will become the new active scene. More...
 
PlayerData SavePlayerData (PlayerData playerData)
 Saves data used by this script in a PlayerData class. More...
 
void LoadPlayerData (PlayerData playerData, bool loadSubScenes=true)
 Loads data used by this script from a PlayerData class. More...
 
MainData SaveMainData (MainData mainData)
 Saves data used by this script in a MainData class. More...
 
void LoadMainData (MainData mainData)
 Loads data used by this script from a MainData class. More...
 
int GetPreviousSceneIndex (bool forPlayer=false)
 Gets the previous scene index.

Parameters
forPlayerIf True, the current Player's previous scene will be returned - which may be different from the "global" index if the game makes use of player-switching
Returns
The previous scene index

 
string GetPreviousSceneName (bool forPlayer=false)
 Gets the previous scene name.

Parameters
forPlayerIf True, the current Player's previous scene will be returned - which may be different from the "global" index if the game makes use of player-switching
Returns
The previous scene index

 
SubScene GetSubScene (int sceneIndex)
 Gets a SubScene class associated with a given scene. The scene must be currently opened as a sub-scene More...
 
SubScene GetSubScene (string sceneName)
 Gets a SubScene class associated with a given scene. The scene must be currently opened as a sub-scene More...
 

Protected Member Functions

void OnEnable ()
 
void OnDisable ()
 
SceneInfo GetSceneInfo (int sceneIndex)
 
SceneInfo GetSceneInfo (string sceneName, bool requireInBuildSettings=false)
 
void OnActiveSceneChanged (Scene oldScene, Scene newScene)
 
void OnAfterChangeScene (LoadingGame loadingGame)
 
void OnInitialiseScene ()
 
IEnumerator ScheduleForDeletionCoroutine (GameObject _gameObject)
 
void LoadLevel (int nextSceneIndex, bool useLoadingScreen, bool useAsyncLoading, bool forceReload, bool doOverlay)
 
void LoadLevel (string nextSceneName, bool useLoadingScreen, bool useAsyncLoading, bool forceReload, bool doOverlay)
 
void LoadLoadingScreen (int nextSceneIndex, int loadingSceneIndex, bool loadAsynchronously, bool doOverlay)
 
void LoadLoadingScreen (string nextSceneName, string loadingSceneName, bool loadAsynchronously, bool doOverlay)
 
IEnumerator LoadLoadingScreen (SceneInfo loadingSceneInfo, SceneInfo nextSceneInfo, bool loadAsynchronously, bool doOverlay)
 
void LoadLevelAsync (int nextSceneIndex, bool doOverlay)
 
void LoadLevelAsync (string nextSceneName, bool doOverlay)
 
IEnumerator LoadLevelAsync (bool isPreloadScene, SceneInfo nextSceneInfo, bool doOverlay)
 
void PreloadLevelAsync (int nextSceneIndex)
 
void PreloadLevelAsync (string nextSceneName)
 
IEnumerator PreloadLevelAsync (SceneInfo nextSceneInfo)
 
void LoadLevelCo (int nextSceneIndex, bool forceReload, bool doOverlay)
 
void LoadLevelCo (string nextSceneName, bool forceReload, bool doOverlay)
 
IEnumerator LoadLevelCo (SceneInfo nextSceneInfo, bool forceReload, bool doOverlay)
 
virtual void PrepareSceneForExit (bool isInstant, bool saveRoomData, bool doOverlay)
 
IEnumerator CloseScene (int sceneIndex)
 
IEnumerator CloseScene (string sceneName)
 

Protected Attributes

List< SceneInfobuildScenes = new List<SceneInfo> ()
 
int previousGlobalSceneIndex = -1
 
string previousGlobalSceneName
 
List< SubScenesubScenes = new List<SubScene>()
 
Vector3 relativePosition
 
AsyncOperation preloadAsync
 
int preloadSceneIndex = -1
 
string preloadSceneName
 
Texture2D textureOnTransition = null
 
bool isLoading = false
 
float loadingProgress = 0f
 
Vector2 simulatedCursorPositionOnExit = new Vector2 (-1f, -1f)
 
bool completeSceneActivation
 

Properties

List< SubSceneSubScenes [get]
 
static int CurrentSceneIndex [get]
 
static Scene CurrentScene [get]
 
static string CurrentSceneName [get]
 
int PreviousSceneIndex [get]
 
string PreviousSceneName [get]
 

Detailed Description

Handles the changing of the scene, and keeps track of which scene was previously loaded. It should be placed on the PersistentEngine prefab.

Member Function Documentation

◆ ActivateLoadedScene()

void AC.SceneChanger.ActivateLoadedScene ( )

Activates the loaded scene, if it must be done so manually

◆ AddSubScene() [1/2]

bool AC.SceneChanger.AddSubScene ( int  subSceneIndex)

Adds a new scene as a sub-scene, without affecting any other open scenes.

Parameters
subSceneIndexThe index of the new scene to open
Returns
True if the scene was succesfully added

◆ AddSubScene() [2/2]

bool AC.SceneChanger.AddSubScene ( string  subSceneName)

Adds a new scene as a sub-scene, without affecting any other open scenes.

Parameters
subSceneNameThe name of the new scene to open
Returns
True if the scene was succesfully added

◆ ChangeScene() [1/2]

bool AC.SceneChanger.ChangeScene ( int  nextSceneIndex,
bool  saveRoomData,
bool  forceReload = false,
bool  doOverlay = false 
)

Loads a new scene. This method should be used instead of Unity's own scene-switching method, because this allows for AC objects to be saved beforehand

Parameters
nextSceneIndexThe build index of the scene to load
saveRoomDataIf True, then the states of the current scene's Remember scripts will be recorded in LevelStorage
forceReloadIf True, the scene will be re-loaded if it is already open.
doOverlayIf True, an overlay texture will be displayed fullscreen during the transition
Returns
True if the new scene will be loaded in

◆ ChangeScene() [2/2]

bool AC.SceneChanger.ChangeScene ( string  nextSceneName,
bool  saveRoomData,
bool  forceReload = false,
bool  doOverlay = false 
)

Loads a new scene. This method should be used instead of Unity's own scene-switching method, because this allows for AC objects to be saved beforehand

Parameters
nextSceneNameThe name of the scene to load
saveRoomDataIf True, then the states of the current scene's Remember scripts will be recorded in LevelStorage
forceReloadIf True, the scene will be re-loaded if it is already open.
doOverlayIf True, an overlay texture will be displayed fullscreen during the transition
Returns
True if the new scene will be loaded in

◆ DrawStatus()

void AC.SceneChanger.DrawStatus ( )

Displays scene-related information for the AC Status window

◆ GetAndResetTransitionTexture()

Texture2D AC.SceneChanger.GetAndResetTransitionTexture ( )

Gets, and removes from memory, the texture used as an overlay during a scene transition.

Returns
The texture used as an overlay during a scene transition

◆ GetLoadingProgress()

float AC.SceneChanger.GetLoadingProgress ( )

Gets the progress of an asynchronous scene load as a decimal.

Returns
The progress of an asynchronous scene load as a decimal.

◆ GetStartPosition()

virtual Vector3 AC.SceneChanger.GetStartPosition ( Vector3  playerStartPosition)
virtual

Gets the player's starting position by adding the relative position (set in ActionScene) to the PlayerStart's position.

Parameters
playerStartPositionThe position of the PlayerStart object
Returns
The player's starting position

◆ GetSubScene() [1/2]

SubScene AC.SceneChanger.GetSubScene ( int  sceneIndex)

Gets a SubScene class associated with a given scene. The scene must be currently opened as a sub-scene

Parameters
sceneIndexThe index of the scene to check for
Returns
The scene's associated SubScene class

◆ GetSubScene() [2/2]

SubScene AC.SceneChanger.GetSubScene ( string  sceneName)

Gets a SubScene class associated with a given scene. The scene must be currently opened as a sub-scene

Parameters
sceneNameThe name of the scene to check for
Returns
The scene's associated SubScene class

◆ IsLoading()

bool AC.SceneChanger.IsLoading ( )

Checks if a scene is being loaded

Returns
True if a scene is being loaded

◆ LoadMainData()

void AC.SceneChanger.LoadMainData ( MainData  mainData)

Loads data used by this script from a MainData class.

Parameters
mainDataThe MainData to load from.

◆ LoadPlayerData()

void AC.SceneChanger.LoadPlayerData ( PlayerData  playerData,
bool  loadSubScenes = true 
)

Loads data used by this script from a PlayerData class.

Parameters
playerDataThe PlayerData to load from.
loadSubScenesIf True, then sub-scenes will be loaded

◆ PopulateBuildSceneData()

virtual void AC.SceneChanger.PopulateBuildSceneData ( )
virtual

Creates an internal record of all scenes that are in the game. If scenes are added at runtime, this function may need to be overridden to include them.

◆ PreloadScene() [1/2]

void AC.SceneChanger.PreloadScene ( int  nextSceneIndex)

Preloads a scene. Preloaded data will be discarded if the next scene opened is not the same as the one preloaded

Parameters
nextSceneIndexThe build index to load

◆ PreloadScene() [2/2]

void AC.SceneChanger.PreloadScene ( string  nextSceneName)

Preloads a scene. Preloaded data will be discarded if the next scene opened is not the same as the one preloaded

Parameters
nextSceneIndexThe build index to load

◆ PrepareSceneForExit()

void AC.SceneChanger.PrepareSceneForExit ( )

Saves the current scene objects, kills speech dialog etc. This should if the scene is changed using a custom script, i.e. without using the provided 'Scene: Switch' Action.

◆ RegisterSubScene()

void AC.SceneChanger.RegisterSubScene ( SubScene  subScene)

Registers a SubScene component with the SceneChanger.

Parameters
subSceneThe SubScene component to register

◆ RemoveScene() [1/2]

bool AC.SceneChanger.RemoveScene ( int  sceneIndex)

Removes a scene, without affecting any other open scenes, provided multiple scenes are open. If the active scene is removed, the last-added sub-scene will become the new active scene.

Parameters
sceneIndexThe index of the new scene to remove
Returns
True if the scene was succesfully removed

◆ RemoveScene() [2/2]

bool AC.SceneChanger.RemoveScene ( string  sceneName)

Removes a scene, without affecting any other open scenes, provided multiple scenes are open. If the active scene is removed, the last-added sub-scene will become the new active scene.

Parameters
sceneNameThe name of the new scene to remove
Returns
True if the scene was succesfully removed

◆ ResetCurrentScene()

void AC.SceneChanger.ResetCurrentScene ( )

Resets the current scene, clearing all data related to it

◆ SaveMainData()

MainData AC.SceneChanger.SaveMainData ( MainData  mainData)

Saves data used by this script in a MainData class.

Parameters
mainDataThe MainData to save in.
Returns
The updated MainData

◆ SavePlayerData()

PlayerData AC.SceneChanger.SavePlayerData ( PlayerData  playerData)

Saves data used by this script in a PlayerData class.

Parameters
playerDataThe PlayerData to save in.
Returns
The updated PlayerData

◆ ScheduleForDeletion()

void AC.SceneChanger.ScheduleForDeletion ( GameObject  _gameObject)

Deletes a GameObject once the current frame has finished renderering.

Parameters
_gameObjectThe GameObject to delete

◆ SetRelativePosition()

void AC.SceneChanger.SetRelativePosition ( Marker  marker)

Calculates the player's position relative to the next scene's PlayerStart.

Parameters
markerThe Marker of the GameObject that marks the position that the player should be placed relative to.

◆ SetTransitionTexture()

void AC.SceneChanger.SetTransitionTexture ( Texture2D  _texture)

Stores a texture used as an overlay during a scene transition. This texture can be retrieved with GetAndResetTransitionTexture().

Parameters
_textureThe Texture2D to store

Property Documentation

◆ CurrentScene

Scene AC.SceneChanger.CurrentScene
staticget

The current scene. If multiple scenes are open, this will be the main scene.

◆ CurrentSceneIndex

int AC.SceneChanger.CurrentSceneIndex
staticget

The current scene index. If multiple scenes are open, this will be the main scene.

◆ CurrentSceneName

string AC.SceneChanger.CurrentSceneName
staticget

The current scene name. If multiple scenes are open, this will be the main scene.

◆ PreviousSceneIndex

int AC.SceneChanger.PreviousSceneIndex
get

The index of the previous scene loaded. This is not necessarily the current Player's previous scene - for that, use GetPreviousSceneIndex (true)

◆ PreviousSceneName

string AC.SceneChanger.PreviousSceneName
get

The name of the previous scene loaded. This is not necessarily the current Player's previous scene - for that, use GetPreviousSceneName (true)

◆ SubScenes

List<SubScene> AC.SceneChanger.SubScenes
get

All open SubScenes