Cesium for Unreal 2.13.2
Loading...
Searching...
No Matches
CesiumSubLevelSwitcherComponent.h
Go to the documentation of this file.
1// Copyright 2020-2024 CesiumGS, Inc. and Contributors
2
3#pragma once
4
5#include "Components/ActorComponent.h"
6#include "CesiumSubLevelSwitcherComponent.generated.h"
7
9class ALevelInstance;
10class ULevelStreaming;
11class UWorld;
12
13/**
14 * Manages the asynchronous switching between sub-levels, making sure that a
15 * previous sub-level is hidden before the CesiumGeoreference is switched to a
16 * new location and the next sub-level is loaded.
17 */
18UCLASS(ClassGroup = "Cesium")
19class CESIUMRUNTIME_API UCesiumSubLevelSwitcherComponent
20 : public UActorComponent {
21 GENERATED_BODY()
22
23public:
25
26 /**
27 * Gets the list of sub-levels that are currently registered with this
28 * switcher.
29 */
30 UFUNCTION(BlueprintPure, Category = "Cesium|Sub-levels")
31 TArray<ALevelInstance*> GetRegisteredSubLevels() const noexcept;
32
33 /**
34 * Gets the list of sub-levels that are currently registered with this
35 * switcher. This is slightly more efficient than GetRegisteredSubLevels but
36 * is not accessible from Blueprints.
37 */
38 const TArray<TWeakObjectPtr<ALevelInstance>>&
39 GetRegisteredSubLevelsWeak() const noexcept {
40 return this->_sublevels;
41 }
42
43 /**
44 * Gets the sub-level that is currently active, or nullptr if none are active.
45 */
46 UFUNCTION(BlueprintPure, Category = "Cesium|Sub-levels")
47 ALevelInstance* GetCurrentSubLevel() const noexcept;
48
49 /**
50 * Gets the sub-level that is in the process of becoming active. If nullptr,
51 * the target is a state where no sub-levels are active.
52 */
53 UFUNCTION(BlueprintPure, Category = "Cesium|Sub-levels")
54 ALevelInstance* GetTargetSubLevel() const noexcept;
55
56 /**
57 * Sets the sub-level that should be active. The switcher will asynchronously
58 * load and show this sub-level.
59 */
60 UFUNCTION(BlueprintCallable, Category = "Cesium|Sub-levels")
61 void SetTargetSubLevel(ALevelInstance* LevelInstance) noexcept;
62
63private:
64 // To allow the sub-level to register/unregister itself with the functions
65 // below.
67 friend class CesiumEditorSubLevelMutex;
68
69 /**
70 * Registers a sub-level with this switcher. The switcher will ensure that
71 * no more than one of the registered sub-levels is active at any time.
72 */
73 void RegisterSubLevel(ALevelInstance* pSubLevel) noexcept;
74
75 /**
76 * Unregisters a sub-level from this switcher. This is primarily used if the
77 * sub-level is being destroyed or reparented.
78 */
79 void UnregisterSubLevel(ALevelInstance* pSubLevel) noexcept;
80
81 virtual void TickComponent(
82 float DeltaTime,
83 enum ELevelTick TickType,
84 FActorComponentTickFunction* ThisTickFunction) override;
85
86 void _updateSubLevelStateGame();
87#if WITH_EDITOR
88 void _updateSubLevelStateEditor();
89#endif
90
91 /**
92 * Finds the ULevelStreaming instance, if any, associated with a given
93 * sub-level.
94 */
95 ULevelStreaming*
96 _getLevelStreamingForSubLevel(ALevelInstance* SubLevel) const;
97
98 // Don't save/load or copy this.
99 UPROPERTY(Transient, DuplicateTransient, TextExportTransient)
100 TArray<TWeakObjectPtr<ALevelInstance>> _sublevels;
101
102 // Don't save/load or copy this.
103 UPROPERTY(Transient, DuplicateTransient, TextExportTransient)
104 TWeakObjectPtr<ALevelInstance> _pCurrent = nullptr;
105
106 // Save/load this, but don't copy it.
107 UPROPERTY(DuplicateTransient, TextExportTransient)
108 TWeakObjectPtr<ALevelInstance> _pTarget = nullptr;
109
110 bool _doExtraChecksOnNextTick = false;
111 bool _isTransitioningSubLevels = false;
112};
Controls how global geospatial coordinates are mapped to coordinates in the Unreal Engine level.
A component intended to be attached to a Level Instance Actor that turns that Level Instance into a C...
Manages the asynchronous switching between sub-levels, making sure that a previous sub-level is hidde...