Img

Maps Portals And Transitions

Description

This is ready to use Brick to move between connected scenes
It supports single and additive loading with persistence logic through DontDestroyOnLoad scene

If you dont really need to have few scenes loaded simultanously, you dont have to!
Use additive loading and all consequences tied to it only if you really need it!

There 3 pieces that make it work:

CallBinder_TriggerEnter - binder that will call specified method on TriggerEnter
MapPortal - defines enter transform and CrossSceneLink to Portal on other scene
Service_MapTransitions - defines overridable transition logic to other scene with Store and Restore persistent Objects

All three is more template and starting point for project and expected to be copied customized for project needs

CallBinder_TriggerEnter : MonoBehaviour

Simple script
Reacts to Unity OnTriggerEnter and call specified method on target like MapPortal.GoToMapSingle_AtPoint

Fields

FieldsDescription
ColliderTagReact only on colliders with this tag (e.g. Player)
TargetTarget object and method to call

MapPortal

Logical portal between scenes
Do nothing by itself
Call its methods from code or by using CallBinder_TriggerEnter

Fields

FieldsDescription
Pointother portal this one linked to (on other scene/map). Load both scenes to link
EnterPlaceTransform that define position and orientation upon entering this scene/map though this portal

Methods

MethodDescription
GoToMapDefault_AtPointLaunch transition to another scene with default scene loading (Setted up on Service_MapTransitions)
GoToMapSingle_AtPointLaunch transition to another scene with Single scene loading
GoToMapAdditive_AtPointLaunch transition to another scene with Additive scene loading

Service_MapTransitions

Serializable Struct to use as filed on your MonboBehaviours to reference objects in other scenes

Fields

FieldDescription
BackOverlayCanvas to activate while transitioning
PlayerMobTagTag to find object for Persistence (Move to DontDestroyOnLoad and than back to loaded scene at Portal.EnterPlace)
DefaultLoadModeDefault load Mode to use (Single, Additive, or AdditiveNoUnload)

Methods

all methods virtual and async allow custom implementation for project

MethodsDescription
GoToMap_AtPointGet T Component from referenced object or throw
FadeOutFade Out (Show back overlay)
StorePersistentObjectsMove object that must survive to DontDestroyOnLoad (obj marked with _playerMobTag )
LoadMapUnload old map and load new one
RestorePersistentObjectsMove object back to new loaded scene
FadeInFade In (Hide back overlay)
PreloadMapConvenient method to preload specified map/scene
UnloadMapConvenient method to preload specified map/scene