| | 1 | | using DCL.Controllers; |
| | 2 | | using DCL.Helpers; |
| | 3 | | using DCL.Interface; |
| | 4 | | using DCL.Models; |
| | 5 | | using DCL.Configuration; |
| | 6 | | using System; |
| | 7 | | using System.Collections; |
| | 8 | | using System.Collections.Concurrent; |
| | 9 | | using System.Linq; |
| | 10 | | using System.Threading; |
| | 11 | | using Cysharp.Threading.Tasks; |
| | 12 | | using DCL.Components; |
| | 13 | | using DCL.Tasks; |
| | 14 | | using DCL.World.PortableExperiences; |
| | 15 | | using DCLServices.PlacesAPIService; |
| | 16 | | using DCLServices.PortableExperiences.Analytics; |
| | 17 | | using DCLServices.WorldsAPIService; |
| | 18 | | using MainScripts.DCL.Controllers.HotScenes; |
| | 19 | | using Newtonsoft.Json; |
| | 20 | | using System.Collections.Generic; |
| | 21 | | using System.Threading.Tasks; |
| | 22 | | using UnityEngine; |
| | 23 | | using Debug = UnityEngine.Debug; |
| | 24 | |
|
| | 25 | | namespace DCL |
| | 26 | | { |
| | 27 | | public class SceneController : ISceneController |
| | 28 | | { |
| | 29 | | private const bool VERBOSE = false; |
| | 30 | | private const int SCENE_MESSAGES_PREWARM_COUNT = 100000; |
| | 31 | | private const int REQUEST_PLACE_TIME_OUT = 10; |
| | 32 | | private const string EMPTY_PARCEL_NAME = "Empty parcel"; |
| | 33 | |
|
| | 34 | | private readonly IConfirmedExperiencesRepository confirmedExperiencesRepository; |
| | 35 | |
|
| 2 | 36 | | private BaseVariable<Transform> isPexViewerInitialized => DataStore.i.experiencesViewer.isInitialized; |
| | 37 | |
|
| | 38 | | //TODO(Brian): Move to WorldRuntimePlugin later |
| | 39 | | private Coroutine deferredDecodingCoroutine; |
| | 40 | | private CancellationTokenSource tokenSource; |
| | 41 | | private CancellationTokenSource requestPlaceCts; |
| | 42 | | private CancellationTokenSource reloadAdultScenesCts; |
| 583 | 43 | | private IMessagingControllersManager messagingControllersManager => Environment.i.messaging.manager; |
| 4 | 44 | | private BaseDictionary<string, (string name, string description, string icon)> disabledPortableExperiences => Da |
| 6 | 45 | | private BaseHashSet<string> portableExperienceIds => DataStore.i.world.portableExperienceIds; |
| 0 | 46 | | private BaseVariable<ExperiencesConfirmationData> pendingPortableExperienceToBeConfirmed => DataStore.i.world.po |
| 2 | 47 | | private IPortableExperiencesAnalyticsService portableExperiencesAnalytics => Environment.i.serviceLocator.Get<IP |
| 0 | 48 | | private IPlacesAPIService placesAPIService => Environment.i.serviceLocator.Get<IPlacesAPIService>(); |
| 0 | 49 | | private IWorldsAPIService worldsAPIService => Environment.i.serviceLocator.Get<IWorldsAPIService>(); |
| 36 | 50 | | private bool isContentModerationFeatureEnabled => DataStore.i.featureFlags.flags.Get().IsFeatureEnabled("content |
| | 51 | |
|
| 440 | 52 | | public EntityIdHelper entityIdHelper { get; } = new EntityIdHelper(); |
| 24677 | 53 | | public bool enabled { get; set; } = true; |
| | 54 | |
|
| 440 | 55 | | public SceneController(IConfirmedExperiencesRepository confirmedExperiencesRepository) |
| | 56 | | { |
| 440 | 57 | | this.confirmedExperiencesRepository = confirmedExperiencesRepository; |
| 440 | 58 | | } |
| | 59 | |
|
| | 60 | | public void Initialize() |
| | 61 | | { |
| 440 | 62 | | tokenSource = new CancellationTokenSource(); |
| 440 | 63 | | requestPlaceCts = requestPlaceCts.SafeRestart(); |
| 440 | 64 | | sceneSortDirty = true; |
| 440 | 65 | | positionDirty = true; |
| 440 | 66 | | lastSortFrame = 0; |
| 440 | 67 | | enabled = true; |
| | 68 | |
|
| 440 | 69 | | DataStore.i.debugConfig.isDebugMode.OnChange += OnDebugModeSet; |
| 440 | 70 | | DataStore.i.player.playerGridPosition.OnChange += SetPositionDirty; |
| 440 | 71 | | CommonScriptableObjects.sceneNumber.OnChange += OnCurrentSceneNumberChange; |
| 440 | 72 | | DataStore.i.contentModeration.adultContentSettingEnabled.OnChange += OnAdultContentSettingChange; |
| | 73 | |
|
| 440 | 74 | | Environment.i.platform.updateEventHandler.AddListener(IUpdateEventHandler.EventType.Update, Update); |
| 440 | 75 | | Environment.i.platform.updateEventHandler.AddListener(IUpdateEventHandler.EventType.LateUpdate, LateUpdate); |
| 440 | 76 | | } |
| | 77 | |
|
| | 78 | | private void OnDebugModeSet(bool current, bool previous) |
| | 79 | | { |
| 30 | 80 | | if (current == previous) |
| 0 | 81 | | return; |
| | 82 | |
|
| 60 | 83 | | if (current) { Environment.i.world.sceneBoundsChecker.SetFeedbackStyle(new SceneBoundsFeedbackStyle_RedBox() |
| 0 | 84 | | else { Environment.i.world.sceneBoundsChecker.SetFeedbackStyle(new SceneBoundsFeedbackStyle_Simple()); } |
| 0 | 85 | | } |
| | 86 | |
|
| | 87 | | public void Dispose() |
| | 88 | | { |
| 440 | 89 | | tokenSource?.Cancel(); |
| 440 | 90 | | tokenSource?.Dispose(); |
| 440 | 91 | | requestPlaceCts.SafeCancelAndDispose(); |
| 440 | 92 | | reloadAdultScenesCts.SafeCancelAndDispose(); |
| | 93 | |
|
| 440 | 94 | | Environment.i.platform.updateEventHandler.RemoveListener(IUpdateEventHandler.EventType.Update, Update); |
| 440 | 95 | | Environment.i.platform.updateEventHandler.RemoveListener(IUpdateEventHandler.EventType.LateUpdate, LateUpdat |
| | 96 | |
|
| 440 | 97 | | PoolManager.i.OnGet -= Environment.i.platform.physicsSyncController.MarkDirty; |
| 440 | 98 | | PoolManager.i.OnGet -= Environment.i.platform.cullingController.objectsTracker.MarkDirty; |
| | 99 | |
|
| 440 | 100 | | DataStore.i.player.playerGridPosition.OnChange -= SetPositionDirty; |
| 440 | 101 | | DataStore.i.debugConfig.isDebugMode.OnChange -= OnDebugModeSet; |
| 440 | 102 | | DataStore.i.contentModeration.adultContentSettingEnabled.OnChange -= OnAdultContentSettingChange; |
| | 103 | |
|
| 440 | 104 | | CommonScriptableObjects.sceneNumber.OnChange -= OnCurrentSceneNumberChange; |
| | 105 | |
|
| 440 | 106 | | UnloadAllScenes(includePersistent: true); |
| | 107 | |
|
| 440 | 108 | | if (deferredDecodingCoroutine != null) |
| 0 | 109 | | CoroutineStarter.Stop(deferredDecodingCoroutine); |
| 440 | 110 | | } |
| | 111 | |
|
| | 112 | | public void Update() |
| | 113 | | { |
| 11886 | 114 | | if (!enabled) |
| 1303 | 115 | | return; |
| | 116 | |
|
| 10583 | 117 | | if (lastSortFrame != Time.frameCount && sceneSortDirty) |
| | 118 | | { |
| 444 | 119 | | lastSortFrame = Time.frameCount; |
| 444 | 120 | | sceneSortDirty = false; |
| 444 | 121 | | SortScenesByDistance(); |
| | 122 | | } |
| 10583 | 123 | | } |
| | 124 | |
|
| | 125 | | public void LateUpdate() |
| | 126 | | { |
| 11886 | 127 | | if (!enabled) |
| 1303 | 128 | | return; |
| | 129 | |
|
| 10583 | 130 | | Environment.i.platform.physicsSyncController.Sync(); |
| 10583 | 131 | | } |
| | 132 | |
|
| | 133 | | //====================================================================== |
| | 134 | |
|
| | 135 | | #region MESSAGES_HANDLING |
| | 136 | | //====================================================================== |
| | 137 | |
|
| | 138 | | #if UNITY_EDITOR |
| | 139 | | public delegate void ProcessDelegate(int sceneNumber, string method); |
| | 140 | |
|
| | 141 | | public event ProcessDelegate OnMessageProcessInfoStart; |
| | 142 | | public event ProcessDelegate OnMessageProcessInfoEnds; |
| | 143 | | #endif |
| 0 | 144 | | public bool deferredMessagesDecoding { get; set; } = false; |
| | 145 | |
|
| 440 | 146 | | readonly ConcurrentQueue<string> chunksToDecode = new ConcurrentQueue<string>(); |
| 440 | 147 | | private readonly ConcurrentQueue<QueuedSceneMessage_Scene> messagesToProcess = new ConcurrentQueue<QueuedSceneMe |
| | 148 | |
|
| | 149 | | const float MAX_TIME_FOR_DECODE = 0.005f; |
| | 150 | |
|
| | 151 | | public bool ProcessMessage(QueuedSceneMessage_Scene msgObject, out CustomYieldInstruction yieldInstruction) |
| | 152 | | { |
| 1 | 153 | | int sceneNumber = msgObject.sceneNumber; |
| 1 | 154 | | string method = msgObject.method; |
| | 155 | |
|
| 1 | 156 | | yieldInstruction = null; |
| | 157 | |
|
| | 158 | | IParcelScene scene; |
| 1 | 159 | | DebugConfig debugConfig = DataStore.i.debugConfig; |
| | 160 | |
|
| 1 | 161 | | if (Environment.i.world.state.TryGetScene(sceneNumber, out scene)) |
| | 162 | | { |
| | 163 | | #if UNITY_EDITOR |
| 1 | 164 | | if (debugConfig.soloScene && scene is GlobalScene && debugConfig.ignoreGlobalScenes) { return false; } |
| | 165 | | #endif |
| 1 | 166 | | if (!scene.GetSceneTransform().gameObject.activeInHierarchy) { return true; } |
| | 167 | |
|
| | 168 | | #if UNITY_EDITOR |
| 1 | 169 | | OnMessageProcessInfoStart?.Invoke(sceneNumber, method); |
| | 170 | | #endif |
| 1 | 171 | | ProfilingEvents.OnMessageProcessStart?.Invoke(method); |
| | 172 | |
|
| 1 | 173 | | ProcessMessage(scene as ParcelScene, method, msgObject.payload, out yieldInstruction); |
| | 174 | |
|
| 1 | 175 | | ProfilingEvents.OnMessageProcessEnds?.Invoke(method); |
| | 176 | |
|
| | 177 | | #if UNITY_EDITOR |
| 1 | 178 | | OnMessageProcessInfoEnds?.Invoke(sceneNumber, method); |
| | 179 | | #endif |
| | 180 | |
|
| 1 | 181 | | return true; |
| | 182 | | } |
| | 183 | |
|
| 0 | 184 | | return false; |
| | 185 | | } |
| | 186 | |
|
| | 187 | | private void ProcessMessage(ParcelScene scene, string method, object msgPayload, out CustomYieldInstruction yiel |
| | 188 | | { |
| 1 | 189 | | yieldInstruction = null; |
| 1 | 190 | | IDelayedComponent delayedComponent = null; |
| | 191 | |
|
| | 192 | | try |
| | 193 | | { |
| 1 | 194 | | if (isContentModerationFeatureEnabled && method != MessagingTypes.INIT_DONE) |
| | 195 | | { |
| 0 | 196 | | if (scene.contentCategory == SceneContentCategory.RESTRICTED || |
| | 197 | | (scene.contentCategory == SceneContentCategory.ADULT && !DataStore.i.contentModeration.adultCont |
| 0 | 198 | | return; |
| | 199 | | } |
| | 200 | |
|
| | 201 | | switch (method) |
| | 202 | | { |
| | 203 | | case MessagingTypes.ENTITY_CREATE: |
| | 204 | | { |
| 0 | 205 | | if (msgPayload is Protocol.CreateEntity payload) |
| 0 | 206 | | scene.CreateEntity(entityIdHelper.EntityFromLegacyEntityString(payload.entityId)); |
| | 207 | |
|
| 0 | 208 | | break; |
| | 209 | | } |
| | 210 | | case MessagingTypes.ENTITY_REPARENT: |
| | 211 | | { |
| 0 | 212 | | if (msgPayload is Protocol.SetEntityParent payload) |
| 0 | 213 | | scene.SetEntityParent(entityIdHelper.EntityFromLegacyEntityString(payload.entityId), entityI |
| | 214 | |
|
| 0 | 215 | | break; |
| | 216 | | } |
| | 217 | | case MessagingTypes.PB_SHARED_COMPONENT_UPDATE: |
| | 218 | | { |
| 0 | 219 | | if (msgPayload is Decentraland.Sdk.Ecs6.ComponentUpdatedBody payload) |
| | 220 | | { |
| 0 | 221 | | if (payload.ComponentData != null) { delayedComponent = scene.componentsManagerLegacy.SceneS |
| | 222 | | } |
| | 223 | |
|
| 0 | 224 | | break; |
| | 225 | | } |
| | 226 | | case MessagingTypes.PB_ENTITY_COMPONENT_CREATE_OR_UPDATE: |
| | 227 | | { |
| 0 | 228 | | if (msgPayload is Decentraland.Sdk.Ecs6.UpdateEntityComponentBody payload) |
| | 229 | | { |
| 0 | 230 | | if (payload.ComponentData != null) |
| | 231 | | { |
| 0 | 232 | | delayedComponent = scene.componentsManagerLegacy.EntityComponentCreateOrUpdate(entityIdH |
| | 233 | | (CLASS_ID_COMPONENT)payload.ClassId, payload.ComponentData) as IDelayedComponent; |
| | 234 | | } |
| | 235 | | } |
| | 236 | |
|
| 0 | 237 | | break; |
| | 238 | | } |
| | 239 | | case MessagingTypes.ENTITY_COMPONENT_DESTROY: |
| | 240 | | { |
| 0 | 241 | | if (msgPayload is Protocol.EntityComponentDestroy payload) |
| 0 | 242 | | scene.componentsManagerLegacy.EntityComponentRemove(entityIdHelper.EntityFromLegacyEntityStr |
| | 243 | |
|
| 0 | 244 | | break; |
| | 245 | | } |
| | 246 | | case MessagingTypes.SHARED_COMPONENT_ATTACH: |
| | 247 | | { |
| 0 | 248 | | if (msgPayload is Protocol.SharedComponentAttach payload) |
| 0 | 249 | | scene.componentsManagerLegacy.SceneSharedComponentAttach(entityIdHelper.EntityFromLegacyEnti |
| | 250 | |
|
| 0 | 251 | | break; |
| | 252 | | } |
| | 253 | | case MessagingTypes.SHARED_COMPONENT_CREATE: |
| | 254 | | { |
| 0 | 255 | | if (msgPayload is Protocol.SharedComponentCreate payload) |
| 0 | 256 | | scene.componentsManagerLegacy.SceneSharedComponentCreate(payload.id, payload.classId); |
| | 257 | |
|
| 0 | 258 | | break; |
| | 259 | | } |
| | 260 | | case MessagingTypes.SHARED_COMPONENT_DISPOSE: |
| | 261 | | { |
| 0 | 262 | | if (msgPayload is Protocol.SharedComponentDispose payload) |
| 0 | 263 | | scene.componentsManagerLegacy.SceneSharedComponentDispose(payload.id); |
| | 264 | |
|
| 0 | 265 | | break; |
| | 266 | | } |
| | 267 | | case MessagingTypes.ENTITY_DESTROY: |
| | 268 | | { |
| 0 | 269 | | if (msgPayload is Protocol.RemoveEntity payload) |
| 0 | 270 | | scene.RemoveEntity(entityIdHelper.EntityFromLegacyEntityString(payload.entityId)); |
| | 271 | |
|
| 0 | 272 | | break; |
| | 273 | | } |
| | 274 | | case MessagingTypes.INIT_DONE: |
| | 275 | | { |
| 1 | 276 | | if (!scene.IsInitMessageDone()) |
| 1 | 277 | | scene.sceneLifecycleHandler.SetInitMessagesDone(); |
| | 278 | |
|
| 1 | 279 | | break; |
| | 280 | | } |
| | 281 | | case MessagingTypes.QUERY: |
| | 282 | | { |
| 0 | 283 | | if (msgPayload is QueryMessage queryMessage) |
| 0 | 284 | | ParseQuery(queryMessage.payload, scene.sceneData.sceneNumber); |
| | 285 | |
|
| 0 | 286 | | break; |
| | 287 | | } |
| | 288 | | case MessagingTypes.OPEN_EXTERNAL_URL: |
| | 289 | | { |
| 0 | 290 | | if (msgPayload is Protocol.OpenExternalUrl payload) |
| | 291 | | { |
| | 292 | | // SDK6 permission check for PX |
| 0 | 293 | | if (scene.isPortableExperience && !scene.sceneData.requiredPermissions.Contains(ScenePermiss |
| | 294 | | { |
| 0 | 295 | | Debug.LogError($"PX requires permission {ScenePermissionNames.OPEN_EXTERNAL_LINK}"); |
| 0 | 296 | | return; |
| | 297 | | } |
| | 298 | |
|
| 0 | 299 | | OnOpenExternalUrlRequest?.Invoke(scene, payload.url); |
| | 300 | | } |
| | 301 | |
|
| 0 | 302 | | break; |
| | 303 | | } |
| | 304 | | case MessagingTypes.OPEN_NFT_DIALOG: |
| | 305 | | { |
| | 306 | | // TODO: update protocol |
| 0 | 307 | | if (msgPayload is Protocol.OpenNftDialog payload) |
| 0 | 308 | | DataStore.i.common.onOpenNFTPrompt.Set(new NFTPromptModel("ethereum", payload.contactAddress |
| | 309 | |
|
| 0 | 310 | | break; |
| | 311 | | } |
| | 312 | |
|
| | 313 | | default: |
| 0 | 314 | | Debug.LogError($"Unknown method {method}"); |
| | 315 | | break; |
| | 316 | | } |
| 1 | 317 | | } |
| | 318 | | catch (Exception e) |
| | 319 | | { |
| 0 | 320 | | Debug.LogException(e); |
| 0 | 321 | | Debug.LogError($"Scene message error. scene: {scene.sceneData.sceneNumber} method: {method} payload: {Js |
| 0 | 322 | | } |
| | 323 | |
|
| 1 | 324 | | if (delayedComponent != null) |
| | 325 | | { |
| 0 | 326 | | if (delayedComponent.isRoutineRunning) { yieldInstruction = delayedComponent.yieldInstruction; } |
| | 327 | | } |
| 1 | 328 | | } |
| | 329 | |
|
| | 330 | | public void ParseQuery(object payload, int sceneNumber) |
| | 331 | | { |
| 0 | 332 | | if (!Environment.i.world.state.TryGetScene(sceneNumber, out var scene)) return; |
| | 333 | |
|
| 0 | 334 | | if (!(payload is RaycastQuery raycastQuery)) |
| 0 | 335 | | return; |
| | 336 | |
|
| 0 | 337 | | Vector3 worldOrigin = raycastQuery.ray.origin + Utils.GridToWorldPosition(scene.sceneData.basePosition.x, sc |
| | 338 | |
|
| 0 | 339 | | raycastQuery.ray.unityOrigin = PositionUtils.WorldToUnityPosition(worldOrigin); |
| 0 | 340 | | raycastQuery.sceneNumber = sceneNumber; |
| 0 | 341 | | PhysicsCast.i.Query(raycastQuery, entityIdHelper); |
| 0 | 342 | | } |
| | 343 | |
|
| | 344 | | public void SendSceneMessage(string chunk) |
| | 345 | | { |
| 0 | 346 | | var renderer = CommonScriptableObjects.rendererState.Get(); |
| | 347 | |
|
| 0 | 348 | | if (!renderer) { EnqueueChunk(chunk); } |
| 0 | 349 | | else { chunksToDecode.Enqueue(chunk); } |
| 0 | 350 | | } |
| | 351 | |
|
| | 352 | | private QueuedSceneMessage_Scene Decode(string payload, QueuedSceneMessage_Scene queuedMessage) |
| | 353 | | { |
| 0 | 354 | | ProfilingEvents.OnMessageDecodeStart?.Invoke("Misc"); |
| | 355 | |
|
| 0 | 356 | | if (!MessageDecoder.DecodePayloadChunk(payload, |
| | 357 | | out int sceneNumber, |
| | 358 | | out string message, |
| | 359 | | out string messageTag, |
| 0 | 360 | | out PB_SendSceneMessage sendSceneMessage)) { return null; } |
| | 361 | |
|
| 0 | 362 | | MessageDecoder.DecodeSceneMessage(sceneNumber, message, messageTag, sendSceneMessage, ref queuedMessage); |
| | 363 | |
|
| 0 | 364 | | ProfilingEvents.OnMessageDecodeEnds?.Invoke("Misc"); |
| | 365 | |
|
| 0 | 366 | | return queuedMessage; |
| | 367 | | } |
| | 368 | |
|
| | 369 | | private void EnqueueChunk(string chunk) |
| | 370 | | { |
| 0 | 371 | | string[] payloads = chunk.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); |
| 0 | 372 | | var count = payloads.Length; |
| | 373 | |
|
| 0 | 374 | | for (int i = 0; i < count; i++) |
| | 375 | | { |
| 0 | 376 | | EnqueueSceneMessage(Decode(payloads[i], new QueuedSceneMessage_Scene())); |
| | 377 | | } |
| 0 | 378 | | } |
| | 379 | |
|
| | 380 | | public void EnqueueSceneMessage(QueuedSceneMessage_Scene message) |
| | 381 | | { |
| 1 | 382 | | bool isGlobalScene = WorldStateUtils.IsGlobalScene(message.sceneNumber); |
| 1 | 383 | | messagingControllersManager.AddControllerIfNotExists(this, message.sceneNumber); |
| 1 | 384 | | messagingControllersManager.Enqueue(isGlobalScene, message); |
| 1 | 385 | | } |
| | 386 | |
|
| | 387 | | //====================================================================== |
| | 388 | | #endregion |
| | 389 | |
|
| | 390 | | //====================================================================== |
| | 391 | |
|
| | 392 | | //====================================================================== |
| | 393 | |
|
| | 394 | | #region SCENES_MANAGEMENT |
| | 395 | | //====================================================================== |
| | 396 | | public event Action<int> OnReadyScene; |
| | 397 | |
|
| | 398 | | public void SendSceneReady(int sceneNumber) |
| | 399 | | { |
| 241 | 400 | | messagingControllersManager.SetSceneReady(sceneNumber); |
| | 401 | |
|
| 241 | 402 | | WebInterface.ReportControlEvent(new WebInterface.SceneReady(sceneNumber)); |
| 241 | 403 | | WebInterface.ReportCameraChanged(CommonScriptableObjects.cameraMode.Get(), sceneNumber); |
| | 404 | |
|
| 241 | 405 | | Environment.i.world.blockersController.SetupWorldBlockers(); |
| | 406 | |
|
| 241 | 407 | | OnReadyScene?.Invoke(sceneNumber); |
| 0 | 408 | | } |
| | 409 | |
|
| | 410 | | private void SetPositionDirty(Vector2Int gridPosition, Vector2Int previous) |
| | 411 | | { |
| 11 | 412 | | positionDirty = gridPosition.x != currentGridSceneCoordinate.x || gridPosition.y != currentGridSceneCoordina |
| | 413 | |
|
| 11 | 414 | | if (positionDirty) |
| | 415 | | { |
| 11 | 416 | | sceneSortDirty = true; |
| 11 | 417 | | currentGridSceneCoordinate = gridPosition; |
| | 418 | |
|
| | 419 | | // Since the first position for the character is not sent from Kernel until just-before calling |
| | 420 | | // the rendering activation from Kernel, we need to sort the scenes to get the current scene id |
| | 421 | | // to lock the rendering accordingly... |
| 11 | 422 | | if (!CommonScriptableObjects.rendererState.Get()) { SortScenesByDistance(); } |
| | 423 | | } |
| 11 | 424 | | } |
| | 425 | |
|
| | 426 | | public void SortScenesByDistance() |
| | 427 | | { |
| 444 | 428 | | IWorldState worldState = Environment.i.world.state; |
| | 429 | |
|
| 444 | 430 | | worldState.SortScenesByDistance(currentGridSceneCoordinate); |
| | 431 | |
|
| 444 | 432 | | int currentSceneNumber = worldState.GetCurrentSceneNumber(); |
| | 433 | |
|
| 444 | 434 | | if (!DataStore.i.debugConfig.isDebugMode.Get() && currentSceneNumber <= 0) |
| | 435 | | { |
| | 436 | | // When we don't know the current scene yet, we must lock the rendering from enabling until it is set |
| 431 | 437 | | CommonScriptableObjects.rendererState.AddLock(this); |
| | 438 | | } |
| | 439 | | else |
| | 440 | | { |
| | 441 | | // 1. Set current scene id |
| 13 | 442 | | CommonScriptableObjects.sceneNumber.Set(currentSceneNumber); |
| | 443 | |
|
| | 444 | | // 2. Attempt to remove SceneController's lock on rendering |
| 13 | 445 | | CommonScriptableObjects.rendererState.RemoveLock(this); |
| | 446 | | } |
| | 447 | |
|
| 444 | 448 | | OnSortScenes?.Invoke(); |
| 444 | 449 | | } |
| | 450 | |
|
| | 451 | | private void OnCurrentSceneNumberChange(int newSceneNumber, int previousSceneNumber) |
| | 452 | | { |
| 72 | 453 | | if (Environment.i.world.state.TryGetScene(newSceneNumber, out IParcelScene newCurrentScene) |
| | 454 | | && !(newCurrentScene as ParcelScene).sceneLifecycleHandler.isReady) |
| | 455 | | { |
| 6 | 456 | | CommonScriptableObjects.rendererState.AddLock(newCurrentScene); |
| | 457 | |
|
| 6 | 458 | | (newCurrentScene as ParcelScene).sceneLifecycleHandler.OnSceneReady += (readyScene) => { CommonScriptabl |
| | 459 | | } |
| 72 | 460 | | } |
| | 461 | |
|
| | 462 | | public void LoadParcelScenesExecute(string scenePayload) |
| | 463 | | { |
| | 464 | | LoadParcelScenesMessage.UnityParcelScene sceneToLoad; |
| | 465 | |
|
| 28 | 466 | | ProfilingEvents.OnMessageDecodeStart?.Invoke(MessagingTypes.SCENE_LOAD); |
| 28 | 467 | | sceneToLoad = Utils.SafeFromJson<LoadParcelScenesMessage.UnityParcelScene>(scenePayload); |
| 28 | 468 | | ProfilingEvents.OnMessageDecodeEnds?.Invoke(MessagingTypes.SCENE_LOAD); |
| | 469 | |
|
| 28 | 470 | | LoadUnityParcelScene(sceneToLoad).Forget(); |
| 28 | 471 | | } |
| | 472 | |
|
| | 473 | | public async UniTaskVoid LoadUnityParcelScene(LoadParcelScenesMessage.UnityParcelScene sceneToLoad) |
| | 474 | | { |
| 34 | 475 | | if (sceneToLoad == null || sceneToLoad.sceneNumber <= 0) |
| 0 | 476 | | return; |
| | 477 | |
|
| | 478 | | if (VERBOSE) |
| | 479 | | Debug.Log($"{Time.frameCount}: Trying to load scene: id: {sceneToLoad.id}; number: {sceneToLoad.sceneNum |
| | 480 | |
|
| 34 | 481 | | DebugConfig debugConfig = DataStore.i.debugConfig; |
| | 482 | | #if UNITY_EDITOR |
| 34 | 483 | | if (debugConfig.soloScene && sceneToLoad.basePosition.ToString() != debugConfig.soloSceneCoords.ToString()) |
| | 484 | | { |
| 0 | 485 | | SendSceneReady(sceneToLoad.sceneNumber); |
| | 486 | |
|
| 0 | 487 | | return; |
| | 488 | | } |
| | 489 | | #endif |
| | 490 | |
|
| 34 | 491 | | ProfilingEvents.OnMessageProcessStart?.Invoke(MessagingTypes.SCENE_LOAD); |
| | 492 | |
|
| 34 | 493 | | IWorldState worldState = Environment.i.world.state; |
| | 494 | |
|
| 34 | 495 | | if (!worldState.ContainsScene(sceneToLoad.sceneNumber)) |
| | 496 | | { |
| 34 | 497 | | var newGameObject = new GameObject("New Scene"); |
| | 498 | |
|
| 34 | 499 | | var newScene = newGameObject.AddComponent<ParcelScene>(); |
| 34 | 500 | | await newScene.SetData(sceneToLoad); |
| 34 | 501 | | await RequestSceneContentCategory(newScene); |
| | 502 | |
|
| 62 | 503 | | if (debugConfig.isDebugMode.Get()) { newScene.InitializeDebugPlane(); } |
| | 504 | |
|
| 34 | 505 | | worldState.AddScene(newScene); |
| | 506 | |
|
| 34 | 507 | | sceneSortDirty = true; |
| | 508 | |
|
| 34 | 509 | | if (newScene.contentCategory != SceneContentCategory.RESTRICTED && |
| | 510 | | (newScene.contentCategory != SceneContentCategory.ADULT || (newScene.contentCategory == SceneContent |
| 34 | 511 | | OnNewSceneAdded?.Invoke(newScene); |
| | 512 | |
|
| 34 | 513 | | messagingControllersManager.AddControllerIfNotExists(this, newScene.sceneData.sceneNumber); |
| | 514 | |
|
| | 515 | | if (VERBOSE) |
| | 516 | | Debug.Log($"{Time.frameCount}: Load parcel scene (id: {newScene.sceneData.sceneNumber})"); |
| 34 | 517 | | } |
| | 518 | |
|
| 34 | 519 | | ProfilingEvents.OnMessageProcessEnds?.Invoke(MessagingTypes.SCENE_LOAD); |
| 34 | 520 | | } |
| | 521 | |
|
| | 522 | | private async Task RequestSceneContentCategory(ParcelScene parcelScene) |
| | 523 | | { |
| 34 | 524 | | if (!isContentModerationFeatureEnabled) |
| 34 | 525 | | return; |
| | 526 | |
|
| 0 | 527 | | var sceneInfo = MinimapMetadata.GetMetadata().GetSceneInfo(parcelScene.sceneData.basePosition.x, parcelScene |
| 0 | 528 | | if (sceneInfo is { name: EMPTY_PARCEL_NAME }) |
| 0 | 529 | | return; |
| | 530 | |
|
| | 531 | | try |
| | 532 | | { |
| | 533 | | string placeId; |
| | 534 | | string placeContentRating; |
| | 535 | |
|
| 0 | 536 | | await UniTask |
| 0 | 537 | | .WaitUntil(() => DataStore.i.realm.realmWasSetByFirstTime.Get(), cancellationToken: requestPlaceCts |
| | 538 | | .Timeout(TimeSpan.FromSeconds(REQUEST_PLACE_TIME_OUT)); |
| | 539 | |
|
| 0 | 540 | | if (!DataStore.i.common.isWorld.Get()) |
| | 541 | | { |
| 0 | 542 | | var associatedPlace = await placesAPIService |
| | 543 | | .GetPlace(parcelScene.sceneData.basePosition, requestPlaceCts.Token) |
| | 544 | | .Timeout(TimeSpan.FromSeconds(REQUEST_PLACE_TIME_OUT)); |
| | 545 | |
|
| 0 | 546 | | placeId = associatedPlace.id; |
| 0 | 547 | | placeContentRating = associatedPlace.content_rating; |
| | 548 | | } |
| | 549 | | else |
| | 550 | | { |
| 0 | 551 | | var associatedWorld = await worldsAPIService |
| | 552 | | .GetWorld(DataStore.i.realm.realmName.Get(), requestPlaceCts.Token) |
| | 553 | | .Timeout(TimeSpan.FromSeconds(REQUEST_PLACE_TIME_OUT)); |
| 0 | 554 | | placeId = associatedWorld.id; |
| 0 | 555 | | placeContentRating = associatedWorld.content_rating; |
| | 556 | | } |
| | 557 | |
|
| 0 | 558 | | parcelScene.SetAssociatedPlace(placeId); |
| | 559 | |
|
| | 560 | | switch (placeContentRating) |
| | 561 | | { |
| | 562 | | case "A" or "M": |
| 0 | 563 | | parcelScene.SetContentCategory(SceneContentCategory.ADULT); |
| 0 | 564 | | break; |
| | 565 | | case "R": |
| 0 | 566 | | parcelScene.SetContentCategory(SceneContentCategory.RESTRICTED); |
| 0 | 567 | | break; |
| | 568 | | default: |
| 0 | 569 | | parcelScene.SetContentCategory(SceneContentCategory.TEEN); |
| | 570 | | break; |
| | 571 | | } |
| 0 | 572 | | } |
| 0 | 573 | | catch (Exception ex) |
| | 574 | | { |
| 0 | 575 | | parcelScene.SetContentCategory(SceneContentCategory.TEEN); |
| | 576 | |
|
| 0 | 577 | | if (ex is not NotAPlaceException) |
| 0 | 578 | | Debug.LogError($"An error occurred while requesting the content category for ({parcelScene.sceneData |
| 0 | 579 | | } |
| 34 | 580 | | } |
| | 581 | |
|
| | 582 | | public void UpdateParcelScenesExecute(string scenePayload) |
| | 583 | | { |
| | 584 | | LoadParcelScenesMessage.UnityParcelScene sceneData; |
| | 585 | |
|
| 0 | 586 | | ProfilingEvents.OnMessageDecodeStart?.Invoke(MessagingTypes.SCENE_UPDATE); |
| 0 | 587 | | sceneData = Utils.SafeFromJson<LoadParcelScenesMessage.UnityParcelScene>(scenePayload); |
| 0 | 588 | | ProfilingEvents.OnMessageDecodeEnds?.Invoke(MessagingTypes.SCENE_UPDATE); |
| | 589 | |
|
| 0 | 590 | | IWorldState worldState = Environment.i.world.state; |
| | 591 | |
|
| 0 | 592 | | if (worldState.TryGetScene(sceneData.sceneNumber, out IParcelScene sceneInterface)) |
| | 593 | | { |
| 0 | 594 | | ParcelScene scene = sceneInterface as ParcelScene; |
| 0 | 595 | | scene.SetUpdateData(sceneData); |
| | 596 | | } |
| 0 | 597 | | else { LoadParcelScenesExecute(scenePayload); } |
| 0 | 598 | | } |
| | 599 | |
|
| | 600 | | public void UpdateParcelScenesExecute(LoadParcelScenesMessage.UnityParcelScene scene) |
| | 601 | | { |
| 0 | 602 | | if (scene == null || scene.sceneNumber <= 0) |
| 0 | 603 | | return; |
| | 604 | |
|
| 0 | 605 | | var sceneToLoad = scene; |
| | 606 | |
|
| 0 | 607 | | ProfilingEvents.OnMessageProcessStart?.Invoke(MessagingTypes.SCENE_UPDATE); |
| | 608 | |
|
| 0 | 609 | | ParcelScene parcelScene = Environment.i.world.state.GetScene(sceneToLoad.sceneNumber) as ParcelScene; |
| | 610 | |
|
| 0 | 611 | | if (parcelScene != null) |
| 0 | 612 | | parcelScene.SetUpdateData(sceneToLoad); |
| | 613 | |
|
| 0 | 614 | | ProfilingEvents.OnMessageProcessEnds?.Invoke(MessagingTypes.SCENE_UPDATE); |
| 0 | 615 | | } |
| | 616 | |
|
| | 617 | | public void UnloadScene(int sceneNumber) |
| | 618 | | { |
| 2 | 619 | | var queuedMessage = new QueuedSceneMessage() |
| | 620 | | { type = QueuedSceneMessage.Type.UNLOAD_PARCEL, sceneNumber = sceneNumber }; |
| | 621 | |
|
| 2 | 622 | | ProfilingEvents.OnMessageWillQueue?.Invoke(MessagingTypes.SCENE_DESTROY); |
| | 623 | |
|
| 2 | 624 | | messagingControllersManager.ForceEnqueueToGlobal(MessagingBusType.INIT, queuedMessage); |
| 2 | 625 | | messagingControllersManager.RemoveController(sceneNumber); |
| 2 | 626 | | } |
| | 627 | |
|
| | 628 | | public void UnloadParcelSceneExecute(int sceneNumber) |
| | 629 | | { |
| 267 | 630 | | ProfilingEvents.OnMessageProcessStart?.Invoke(MessagingTypes.SCENE_DESTROY); |
| | 631 | |
|
| 267 | 632 | | IWorldState worldState = Environment.i.world.state; |
| | 633 | |
|
| 267 | 634 | | if (!worldState.TryGetScene(sceneNumber, out ParcelScene scene)) |
| 0 | 635 | | return; |
| | 636 | |
|
| 267 | 637 | | CommonScriptableObjects.rendererState.RemoveLock(scene); |
| 267 | 638 | | worldState.RemoveScene(sceneNumber); |
| | 639 | |
|
| 267 | 640 | | if (scene.isPortableExperience) |
| | 641 | | { |
| 2 | 642 | | portableExperienceIds.Remove(scene.sceneData.id); |
| | 643 | |
|
| 2 | 644 | | string iconUrl = null; |
| | 645 | |
|
| 2 | 646 | | if (!string.IsNullOrEmpty(scene.sceneData.iconUrl)) |
| 0 | 647 | | iconUrl = scene.contentProvider.GetContentsUrl(scene.sceneData.iconUrl); |
| | 648 | |
|
| 2 | 649 | | disabledPortableExperiences.AddOrSet(scene.sceneData.id, |
| | 650 | | (name: scene.sceneName, description: scene.sceneData.description, icon: iconUrl)); |
| | 651 | | } |
| | 652 | |
|
| | 653 | | // Remove messaging controller for unloaded scene |
| 267 | 654 | | messagingControllersManager.RemoveController(sceneNumber); |
| | 655 | |
|
| 267 | 656 | | scene.Cleanup(!CommonScriptableObjects.rendererState.Get()); |
| | 657 | |
|
| | 658 | | if (VERBOSE) { Debug.Log($"{Time.frameCount} : Destroying scene {scene.sceneData.basePosition}"); } |
| | 659 | |
|
| 267 | 660 | | Environment.i.world.blockersController.SetupWorldBlockers(); |
| | 661 | |
|
| 267 | 662 | | ProfilingEvents.OnMessageProcessEnds?.Invoke(MessagingTypes.SCENE_DESTROY); |
| 267 | 663 | | OnSceneRemoved?.Invoke(scene); |
| 2 | 664 | | } |
| | 665 | |
|
| | 666 | | public void UnloadAllScenes(bool includePersistent = false) |
| | 667 | | { |
| 442 | 668 | | var worldState = Environment.i.world.state; |
| | 669 | |
|
| | 670 | | // since the list was changing by this foreach, we make a copy |
| 442 | 671 | | var list = worldState.GetLoadedScenes().ToArray(); |
| | 672 | |
|
| 1392 | 673 | | foreach (var kvp in list) |
| | 674 | | { |
| 254 | 675 | | if (kvp.Value.isPersistent && !includePersistent) |
| | 676 | | continue; |
| | 677 | |
|
| 254 | 678 | | UnloadParcelSceneExecute(kvp.Key); |
| | 679 | | } |
| 442 | 680 | | } |
| | 681 | |
|
| | 682 | | public void LoadParcelScenes(string decentralandSceneJSON) |
| | 683 | | { |
| 28 | 684 | | var queuedMessage = new QueuedSceneMessage() |
| | 685 | | { |
| | 686 | | type = QueuedSceneMessage.Type.LOAD_PARCEL, |
| | 687 | | message = decentralandSceneJSON |
| | 688 | | }; |
| | 689 | |
|
| 28 | 690 | | ProfilingEvents.OnMessageWillQueue?.Invoke(MessagingTypes.SCENE_LOAD); |
| | 691 | |
|
| 28 | 692 | | messagingControllersManager.ForceEnqueueToGlobal(MessagingBusType.INIT, queuedMessage); |
| | 693 | |
|
| | 694 | | if (VERBOSE) |
| | 695 | | Debug.Log($"{Time.frameCount} : Load parcel scene queue {decentralandSceneJSON}"); |
| 28 | 696 | | } |
| | 697 | |
|
| | 698 | | public void UpdateParcelScenes(string decentralandSceneJSON) |
| | 699 | | { |
| 0 | 700 | | var queuedMessage = new QueuedSceneMessage() |
| | 701 | | { type = QueuedSceneMessage.Type.UPDATE_PARCEL, message = decentralandSceneJSON }; |
| | 702 | |
|
| 0 | 703 | | ProfilingEvents.OnMessageWillQueue?.Invoke(MessagingTypes.SCENE_UPDATE); |
| | 704 | |
|
| 0 | 705 | | messagingControllersManager.ForceEnqueueToGlobal(MessagingBusType.INIT, queuedMessage); |
| 0 | 706 | | } |
| | 707 | |
|
| | 708 | | public void UnloadAllScenesQueued() |
| | 709 | | { |
| 0 | 710 | | var queuedMessage = new QueuedSceneMessage() { type = QueuedSceneMessage.Type.UNLOAD_SCENES }; |
| | 711 | |
|
| 0 | 712 | | ProfilingEvents.OnMessageWillQueue?.Invoke(MessagingTypes.SCENE_DESTROY); |
| | 713 | |
|
| 0 | 714 | | Environment.i.messaging.manager.ForceEnqueueToGlobal(MessagingBusType.INIT, queuedMessage); |
| 0 | 715 | | } |
| | 716 | |
|
| | 717 | | public void CreateGlobalScene(CreateGlobalSceneMessage globalScene) |
| | 718 | | { |
| | 719 | | void CreateGlobalSceneInternal(CreateGlobalSceneMessage globalScene) |
| | 720 | | { |
| | 721 | | #if UNITY_EDITOR |
| 7 | 722 | | DebugConfig debugConfig = DataStore.i.debugConfig; |
| | 723 | |
|
| 7 | 724 | | if (debugConfig.soloScene && debugConfig.ignoreGlobalScenes) |
| 0 | 725 | | return; |
| | 726 | | #endif |
| | 727 | |
|
| | 728 | | // NOTE(Brian): We should remove this line. SceneController is a runtime core class. |
| | 729 | | // It should never have references to UI systems or higher level systems. |
| 7 | 730 | | if (globalScene.isPortableExperience && !isPexViewerInitialized.Get()) |
| | 731 | | { |
| 0 | 732 | | Debug.LogError( |
| | 733 | | "Portable experiences are trying to be added before the system is initialized!. scene number: " |
| | 734 | | globalScene.sceneNumber); |
| | 735 | |
|
| 0 | 736 | | return; |
| | 737 | | } |
| | 738 | |
|
| 7 | 739 | | int newGlobalSceneNumber = globalScene.sceneNumber; |
| 7 | 740 | | IWorldState worldState = Environment.i.world.state; |
| | 741 | |
|
| 7 | 742 | | if (worldState.ContainsScene(newGlobalSceneNumber)) |
| 0 | 743 | | return; |
| | 744 | |
|
| 7 | 745 | | var newGameObject = new GameObject("Global Scene - " + newGlobalSceneNumber); |
| | 746 | |
|
| 7 | 747 | | var newScene = newGameObject.AddComponent<GlobalScene>(); |
| 7 | 748 | | newScene.unloadWithDistance = false; |
| 7 | 749 | | newScene.isPersistent = true; |
| 7 | 750 | | newScene.sceneName = globalScene.name; |
| 7 | 751 | | newScene.isPortableExperience = globalScene.isPortableExperience; |
| | 752 | |
|
| 7 | 753 | | LoadParcelScenesMessage.UnityParcelScene sceneData = new LoadParcelScenesMessage.UnityParcelScene |
| | 754 | | { |
| | 755 | | id = globalScene.id, |
| | 756 | | sceneNumber = newGlobalSceneNumber, |
| | 757 | | basePosition = new Vector2Int(0, 0), |
| | 758 | | baseUrl = globalScene.baseUrl, |
| | 759 | | contents = globalScene.contents, |
| | 760 | | sdk7 = globalScene.sdk7, |
| | 761 | | requiredPermissions = globalScene.requiredPermissions, |
| | 762 | | allowedMediaHostnames = globalScene.allowedMediaHostnames, |
| | 763 | | description = globalScene.description, |
| | 764 | | iconUrl = globalScene.icon, |
| | 765 | | }; |
| | 766 | |
|
| 7 | 767 | | newScene.SetData(sceneData).Forget(); |
| | 768 | |
|
| 7 | 769 | | if (!string.IsNullOrEmpty(globalScene.icon)) |
| 0 | 770 | | newScene.iconUrl = newScene.contentProvider.GetContentsUrl(globalScene.icon); |
| | 771 | |
|
| 7 | 772 | | worldState.AddScene(newScene); |
| 7 | 773 | | OnNewSceneAdded?.Invoke(newScene); |
| | 774 | |
|
| 7 | 775 | | if (globalScene.isPortableExperience) |
| | 776 | | { |
| 2 | 777 | | disabledPortableExperiences.Remove(sceneData.id); |
| | 778 | |
|
| 2 | 779 | | if (!portableExperienceIds.Contains(sceneData.id)) |
| 2 | 780 | | portableExperienceIds.Add(sceneData.id); |
| | 781 | |
|
| 2 | 782 | | portableExperiencesAnalytics.Spawn(sceneData.id); |
| | 783 | | } |
| | 784 | |
|
| 7 | 785 | | messagingControllersManager.AddControllerIfNotExists(this, newGlobalSceneNumber, isGlobal: true); |
| | 786 | |
|
| | 787 | | if (VERBOSE) |
| | 788 | | Debug.Log($"Creating Global scene {newGlobalSceneNumber}"); |
| 7 | 789 | | } |
| | 790 | |
|
| | 791 | | (string name, string description, string icon) CreateDisabledPortableExperience(CreateGlobalSceneMessage glo |
| | 792 | | { |
| 0 | 793 | | string iconUrl = null; |
| | 794 | |
|
| 0 | 795 | | if (!string.IsNullOrEmpty(globalScene.icon)) |
| | 796 | | { |
| 0 | 797 | | ContentProvider contentProvider = new ContentProvider |
| | 798 | | { |
| | 799 | | baseUrl = globalScene.baseUrl, |
| | 800 | | contents = globalScene.contents, |
| | 801 | | sceneCid = globalScene.id, |
| | 802 | | }; |
| | 803 | |
|
| 0 | 804 | | contentProvider.BakeHashes(); |
| | 805 | |
|
| 0 | 806 | | iconUrl = contentProvider.GetContentsUrl(globalScene.icon); |
| | 807 | | } |
| | 808 | |
|
| 0 | 809 | | return (name: globalScene.name, description: globalScene.description, icon: iconUrl); |
| | 810 | | } |
| | 811 | |
|
| | 812 | | void DisablePortableExperience(string pxId, |
| | 813 | | (string name, string description, string icon) disabledPx) |
| | 814 | | { |
| 0 | 815 | | disabledPortableExperiences.AddOrSet(pxId, disabledPx); |
| | 816 | |
|
| 0 | 817 | | WebInterface.SetDisabledPortableExperiences( |
| | 818 | | disabledPortableExperiences.GetKeys().ToArray()); |
| 0 | 819 | | } |
| | 820 | |
|
| | 821 | | void ConfirmPortableExperience(CreateGlobalSceneMessage globalScene) |
| | 822 | | { |
| 0 | 823 | | (string name, string description, string icon) disabledPx = CreateDisabledPortableExperience(globalScene |
| | 824 | |
|
| 0 | 825 | | disabledPortableExperiences.AddOrSet(globalScene.id, disabledPx); |
| | 826 | |
|
| 0 | 827 | | pendingPortableExperienceToBeConfirmed.Set(new ExperiencesConfirmationData |
| | 828 | | { |
| | 829 | | Experience = new ExperiencesConfirmationData.ExperienceMetadata |
| | 830 | | { |
| | 831 | | Permissions = globalScene.requiredPermissions, |
| | 832 | | ExperienceId = globalScene.id, |
| | 833 | | ExperienceName = globalScene.name, |
| | 834 | | IconUrl = disabledPx.icon, |
| | 835 | | Description = globalScene.description, |
| | 836 | | }, |
| 0 | 837 | | OnAcceptCallback = () => CreateGlobalSceneInternal(globalScene), |
| 0 | 838 | | OnRejectCallback = () => DisablePortableExperience(globalScene.id, disabledPx), |
| | 839 | | }); |
| 0 | 840 | | } |
| | 841 | |
|
| 7 | 842 | | if (globalScene.isPortableExperience) |
| | 843 | | { |
| 2 | 844 | | string pxId = globalScene.id; |
| 2 | 845 | | bool confirmPx = false; |
| 2 | 846 | | bool disablePx = false; |
| | 847 | |
|
| 2 | 848 | | if (DataStore.i.featureFlags.flags.Get().IsFeatureEnabled("px_confirm_enabled")) |
| | 849 | | { |
| 0 | 850 | | if (!IsPortableExperienceInWhiteList(pxId)) |
| | 851 | | { |
| 0 | 852 | | confirmPx = !IsPortableExperienceAlreadyConfirmed(pxId); |
| | 853 | |
|
| 0 | 854 | | disablePx = IsPortableExperienceAlreadyConfirmed(pxId) |
| | 855 | | && !ShouldForceAcceptPortableExperience(pxId) |
| | 856 | | && !IsPortableExperienceConfirmedAndAccepted(pxId); |
| | 857 | | } |
| | 858 | | } |
| | 859 | |
|
| 2 | 860 | | IWorldState worldState = Environment.i.world.state; |
| 2 | 861 | | IParcelScene scene = worldState.GetScene(worldState.GetCurrentSceneNumber()); |
| | 862 | |
|
| 2 | 863 | | if (scene != null |
| | 864 | | && scene.sceneData.scenePortableExperienceFeatureToggles == ScenePortableExperienceFeatureToggles.Di |
| | 865 | | { |
| 0 | 866 | | confirmPx = false; |
| 0 | 867 | | disablePx = true; |
| | 868 | | } |
| | 869 | |
|
| 2 | 870 | | if (confirmPx) |
| 0 | 871 | | ConfirmPortableExperience(globalScene); |
| 2 | 872 | | else if (disablePx) |
| 0 | 873 | | DisablePortableExperience(globalScene.id, CreateDisabledPortableExperience(globalScene)); |
| | 874 | | else |
| 2 | 875 | | CreateGlobalSceneInternal(globalScene); |
| | 876 | | } |
| | 877 | | else |
| 5 | 878 | | CreateGlobalSceneInternal(globalScene); |
| 5 | 879 | | } |
| | 880 | |
|
| | 881 | | public void IsolateScene(IParcelScene sceneToActive) |
| | 882 | | { |
| 0 | 883 | | foreach (IParcelScene scene in Environment.i.world.state.GetScenesSortedByDistance()) |
| | 884 | | { |
| 0 | 885 | | if (scene != sceneToActive) |
| 0 | 886 | | scene.GetSceneTransform().gameObject.SetActive(false); |
| | 887 | | } |
| 0 | 888 | | } |
| | 889 | |
|
| | 890 | | public void ReIntegrateIsolatedScene() |
| | 891 | | { |
| 0 | 892 | | foreach (IParcelScene scene in Environment.i.world.state.GetScenesSortedByDistance()) { scene.GetSceneTransf |
| 0 | 893 | | } |
| | 894 | |
|
| | 895 | | //====================================================================== |
| | 896 | | #endregion |
| | 897 | |
|
| | 898 | | //====================================================================== |
| | 899 | |
|
| 440 | 900 | | public bool prewarmEntitiesPool { get; set; } = true; |
| | 901 | |
|
| | 902 | | private bool sceneSortDirty = false; |
| 440 | 903 | | private bool positionDirty = true; |
| | 904 | | private int lastSortFrame = 0; |
| | 905 | |
|
| | 906 | | public event Action OnSortScenes; |
| | 907 | | public event Action<IParcelScene, string> OnOpenExternalUrlRequest; |
| | 908 | | public event Action<IParcelScene> OnNewSceneAdded; |
| | 909 | | public event Action<IParcelScene> OnSceneRemoved; |
| | 910 | |
|
| 440 | 911 | | private Vector2Int currentGridSceneCoordinate = new Vector2Int(EnvironmentSettings.MORDOR_SCALAR, EnvironmentSet |
| | 912 | |
|
| | 913 | | private bool ShouldForceAcceptPortableExperience(string pxId) => |
| 0 | 914 | | DataStore.i.world.forcePortableExperience.Equals(pxId); |
| | 915 | |
|
| | 916 | | private bool IsPortableExperienceConfirmedAndAccepted(string pxId) => |
| 0 | 917 | | confirmedExperiencesRepository.Get(pxId); |
| | 918 | |
|
| | 919 | | private bool IsPortableExperienceAlreadyConfirmed(string pxId) => |
| 0 | 920 | | confirmedExperiencesRepository.Contains(pxId); |
| | 921 | |
|
| | 922 | | private bool IsPortableExperienceInWhiteList(string pxId) |
| | 923 | | { |
| 0 | 924 | | FeatureFlag flags = DataStore.i.featureFlags.flags.Get(); |
| 0 | 925 | | FeatureFlagVariantPayload payload = flags.GetFeatureFlagVariantPayload("initial_portable_experiences:calenda |
| | 926 | |
|
| 0 | 927 | | if (payload == null) return false; |
| | 928 | |
|
| 0 | 929 | | string[] whitelistedPxs = JsonConvert.DeserializeObject<string[]>(payload.value); |
| | 930 | |
|
| 0 | 931 | | if (whitelistedPxs == null) return false; |
| | 932 | |
|
| 0 | 933 | | for (var i = 0; i < whitelistedPxs.Length; i++) |
| 0 | 934 | | if (whitelistedPxs[i].StartsWith(pxId)) return true; |
| | 935 | |
|
| 0 | 936 | | return false; |
| | 937 | | } |
| | 938 | |
|
| | 939 | | private void OnAdultContentSettingChange(bool isEnabled, bool previousIsEnabled) |
| | 940 | | { |
| 1 | 941 | | if (!isContentModerationFeatureEnabled) |
| 1 | 942 | | return; |
| | 943 | |
|
| 0 | 944 | | if (isEnabled == previousIsEnabled) |
| 0 | 945 | | return; |
| | 946 | |
|
| 0 | 947 | | var loadedScenes = Environment.i.world.state.GetLoadedScenes(); |
| 0 | 948 | | reloadAdultScenesCts = reloadAdultScenesCts.SafeRestart(); |
| 0 | 949 | | ReloadAdultScenesAsync(loadedScenes.ToList(), reloadAdultScenesCts.Token).Forget(); |
| 0 | 950 | | } |
| | 951 | |
|
| | 952 | | private async UniTaskVoid ReloadAdultScenesAsync(List<KeyValuePair<int, IParcelScene>> loadedScenes, Cancellatio |
| | 953 | | { |
| 0 | 954 | | foreach (KeyValuePair<int,IParcelScene> scene in loadedScenes) |
| | 955 | | { |
| 0 | 956 | | if (scene.Value.contentCategory != SceneContentCategory.ADULT) |
| | 957 | | continue; |
| | 958 | |
|
| 0 | 959 | | WebInterface.ReloadScene(scene.Value.sceneData.basePosition); |
| 0 | 960 | | await Task.Delay(TimeSpan.FromSeconds(0.5f), ct); |
| | 961 | |
|
| 0 | 962 | | if (ct.IsCancellationRequested) |
| 0 | 963 | | return; |
| | 964 | | } |
| 0 | 965 | | } |
| | 966 | | } |
| | 967 | | } |