MultiSceneRef.cs
Assembly: CarterGames.MultiScene.Runtime
Namespace: CarterGames.Experimental.MultiScene
The main way to reference between scenes in the multi scene asset. This class gives you a load of methods to help with getting references between scenes. It is important to note that the scene with the element you are trying to reference has to be loaded to make a valid reference. It is advised to only reference in scenes loaded before the one the reference is being made in or to wait until all the scenes have loaded which can be listened for with the IMultiSceneAwake/Enable/Start
Interfaces & the PostScenesLoaded
event.
Methods
Root Objects
GetRootObjects
Method
string
→ The scenes name to get the objects from.
Returns
GameObject[]
→ An array of all the root gameObjects in the scene requested.
Gets all the root games objects in a particular scene.
var objs = MultiSceneRef.GetRootObjects("MyScene");
Move Objects
MoveObjectToScene
Method
GameObject
→ The object to move.
string
→ The scenes name to move the object to.
Tries to move the object entered in the scene string entered.
GameObject obj;
var result = MultiSceneRef.MoveObjectToScene(obj, "MyScene");
MoveObjectsToScene
Method
List<GameObject>
→ The objects to move.
string
→ The scenes name to move the object to.
Tries to move the object entered in the scene string entered.
List<GameObject> objs;
var result = MultiSceneRef.MoveObjectsToScene(objs, "MyScene");
Find Objects
FindObject
Method
string
→ The name of the object to find.
Returns
GameObject
→ Whether it was successful or not.
Finds the first gameObject of the name entered in all the scenes currently loaded.
var obj = MultiSceneRef.FindObject("MyGameObject");
Method
string
→ The scenes name to move the object to.
string
→ The name of the object to find.
Returns
GameObject
→ Whether it was successful or not.
Finds the first gameObject of the name entered in the scene string entered.
var obj = MultiSceneRef.FindObject("MyScene", "MyGameObject");
FindObjects
Method
string
→ The name of the object to find.
Returns
List<GameObject>
→ Whether it was successful or not.
Finds all the gameObjects of the name entered in all the scenes currently loaded.
var objs = MultiSceneRef.FindObjects("MyGameObject");
Get Components
GetComponentFromActiveScene
Method
Returns
T
→ The type requested.
The first component of the type requested found in the active scene only.
var conponent = MultiSceneRef.GetComponentFromActiveScene<MyComponent>();
GetComponentFromScene
Method
string
→ The name of the scene to get from.
Returns
T
→ The type requested.
The first component of the type requested found in the scene name entered.
var conponent = MultiSceneRef.GetComponentFromScene<MyComponent>("MyScene");
GetComponentFromScenes
Method
List<
string
>
→ The name of the scenes to get from.
Returns
T
→ The type requested.
The first component of the type requested found in the scene names entered.
var scenes = new List<string>(){ "MyScene", "AnotherScene" };
var conponent = MultiSceneRef.GetComponentFromScenes<MyComponent>(scenes);
GetComponentFromAllScenes
Method
string
→ The name of the scene to get from.
Returns
T
→ The type requested.
The first component of the type requested found in all currently loaded scenes.
var conponent = MultiSceneRef.GetComponentFromAllScenes<MyComponent>();
GetComponentsFromActiveScene
Method
Returns
List<T>
→ A list of the type requested.
The all components of the type requested found in the active scene only.
var conponents = MultiSceneRef.GetComponentsFromActiveScene<MyComponent>();
GetComponentsFromScene
Method
string
→ The name of the scene to get from.
Returns
List<T>
→ A list of the type requested.
All the components of the type requested found in the scene name entered.
var conponents = MultiSceneRef.GetComponentsFromScene<MyComponent>("MyScene");
GetComponentsFromScenes
Method
List<
string
>
→ The name of the scenes to get from.
Returns
List<T>
→ A list of the type requested.
All the components of the type requested found in the scene name entered.
var scenes = new List<string>(){ "MyScene", "AnotherScene" };
var conponents = MultiSceneRef.GetComponentsFromScenes<MyComponent>(scenes);
GetComponentsFromAllScenes
Method
string
→ The name of the scene to get from.
Returns
List<T>
→ A list of the type requested.
All the components of the type requested found in all currently loaded scenes.
var conponents = MultiSceneRef.GetComponentsFromAllScenes<MyComponent>();