| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using System.Linq; |
| | 5 | | using DCL.Camera; |
| | 6 | | using DCL.Configuration; |
| | 7 | | using DCL.Controllers; |
| | 8 | | using DCL.Helpers; |
| | 9 | | using UnityEngine; |
| | 10 | | using Cysharp.Threading.Tasks; |
| | 11 | | using DCL.Builder.Manifest; |
| | 12 | | using DCL.Components; |
| | 13 | | using DCL.Interface; |
| | 14 | | using DCL.Models; |
| | 15 | | using Newtonsoft.Json; |
| | 16 | | using Newtonsoft.Json.Linq; |
| | 17 | |
|
| | 18 | | namespace DCL.Builder |
| | 19 | | { |
| | 20 | | public class SceneManager : ISceneManager |
| | 21 | | { |
| | 22 | | internal static bool BYPASS_LAND_OWNERSHIP_CHECK = false; |
| | 23 | | private const float MAX_DISTANCE_STOP_TRYING_TO_ENTER = 16; |
| | 24 | |
|
| | 25 | | private const string SOURCE_BUILDER_PANEl = "BuilderPanel"; |
| | 26 | | private const string SOURCE_SHORTCUT = "Shortcut"; |
| | 27 | |
|
| | 28 | | public enum State |
| | 29 | | { |
| | 30 | | IDLE = 0, |
| | 31 | | LOADING_CATALOG = 1, |
| | 32 | | CATALOG_LOADED = 2, |
| | 33 | | LOADING_SCENE = 3, |
| | 34 | | SCENE_LOADED = 4, |
| | 35 | | EDITING = 5 |
| | 36 | | } |
| | 37 | |
|
| | 38 | | internal State currentState = State.IDLE; |
| | 39 | |
|
| | 40 | | private InputAction_Trigger editModeChangeInputAction; |
| | 41 | |
|
| | 42 | | internal IContext context; |
| | 43 | | internal string sceneToEditId; |
| | 44 | | private UserProfile userProfile; |
| | 45 | | internal Coroutine updateLandsWithAcessCoroutine; |
| | 46 | |
|
| | 47 | | private bool alreadyAskedForLandPermissions = false; |
| | 48 | | private Vector3 askPermissionLastPosition; |
| | 49 | | private IWebRequestAsyncOperation catalogAsyncOp; |
| | 50 | | internal bool isWaitingForPermission = false; |
| | 51 | | internal IBuilderScene sceneToEdit; |
| | 52 | | private BiwSceneMetricsAnalyticsHelper sceneMetricsAnalyticsHelper; |
| | 53 | | private InputController inputController; |
| | 54 | | internal BuilderInWorldBridge builderInWorldBridge; |
| | 55 | | internal IInitialStateManager initialStateManager; |
| | 56 | | internal IBuilderInWorldLoadingController initialLoadingController; |
| | 57 | | private float beginStartFlowTimeStamp = 0; |
| | 58 | | internal bool catalogLoaded = false; |
| 14 | 59 | | internal List<string> portableExperiencesToResume = new List<string>(); |
| | 60 | | private BuilderInWorldBridge bridge; |
| | 61 | |
|
| | 62 | | public void Initialize(IContext context) |
| | 63 | | { |
| 14 | 64 | | this.context = context; |
| 14 | 65 | | editModeChangeInputAction = context.inputsReferencesAsset.editModeChangeInputAction; |
| 14 | 66 | | editModeChangeInputAction.OnTriggered += ChangeEditModeStatusByShortcut; |
| 14 | 67 | | inputController = context.sceneReferences.inputController; |
| | 68 | |
|
| 14 | 69 | | builderInWorldBridge = context.sceneReferences.biwBridgeGameObject.GetComponent<BuilderInWorldBridge>(); |
| 14 | 70 | | userProfile = UserProfile.GetOwnUserProfile(); |
| | 71 | |
|
| 14 | 72 | | bridge = context.sceneReferences.biwBridgeGameObject.GetComponent<BuilderInWorldBridge>(); |
| | 73 | |
|
| 14 | 74 | | context.editorContext.editorHUD.OnStartExitAction += StartExitMode; |
| 14 | 75 | | context.editorContext.editorHUD.OnLogoutAction += ExitEditMode; |
| | 76 | |
|
| 14 | 77 | | BIWTeleportAndEdit.OnTeleportEnd += OnPlayerTeleportedToEditScene; |
| 14 | 78 | | context.builderAPIController.OnWebRequestCreated += WebRequestCreated; |
| | 79 | |
|
| 14 | 80 | | initialStateManager = new InitialStateManager(); |
| | 81 | |
|
| 14 | 82 | | ConfigureLoadingController(); |
| 14 | 83 | | } |
| | 84 | |
|
| | 85 | | public void Dispose() |
| | 86 | | { |
| 14 | 87 | | if (context.editorContext.editorHUD != null) |
| | 88 | | { |
| 14 | 89 | | context.editorContext.editorHUD.OnStartExitAction -= StartExitMode; |
| 14 | 90 | | context.editorContext.editorHUD.OnLogoutAction -= ExitEditMode; |
| | 91 | | } |
| | 92 | |
|
| 14 | 93 | | sceneMetricsAnalyticsHelper?.Dispose(); |
| | 94 | |
|
| 14 | 95 | | initialLoadingController?.Dispose(); |
| | 96 | |
|
| 14 | 97 | | Environment.i.world.sceneController.OnNewSceneAdded -= NewSceneAdded; |
| 14 | 98 | | Environment.i.world.sceneController.OnReadyScene -= NewSceneReady; |
| 14 | 99 | | BIWTeleportAndEdit.OnTeleportEnd -= OnPlayerTeleportedToEditScene; |
| 14 | 100 | | DCLCharacterController.OnPositionSet -= ExitAfterCharacterTeleport; |
| | 101 | |
|
| 14 | 102 | | if (sceneToEdit?.scene != null) |
| 8 | 103 | | sceneToEdit.scene.OnLoadingStateUpdated -= UpdateSceneLoadingProgress; |
| | 104 | |
|
| 14 | 105 | | editModeChangeInputAction.OnTriggered -= ChangeEditModeStatusByShortcut; |
| 14 | 106 | | context.builderAPIController.OnWebRequestCreated -= WebRequestCreated; |
| | 107 | |
|
| 14 | 108 | | CoroutineStarter.Stop(updateLandsWithAcessCoroutine); |
| 14 | 109 | | } |
| | 110 | |
|
| | 111 | | private void ConfigureLoadingController() |
| | 112 | | { |
| 14 | 113 | | initialLoadingController = new BuilderInWorldLoadingController(); |
| 14 | 114 | | initialLoadingController.Initialize(); |
| 14 | 115 | | } |
| | 116 | |
|
| | 117 | | public void NextState() |
| | 118 | | { |
| 15 | 119 | | currentState++; |
| 15 | 120 | | switch (currentState) |
| | 121 | | { |
| | 122 | | case State.LOADING_CATALOG: |
| 4 | 123 | | if (!catalogLoaded) |
| 1 | 124 | | GetCatalog(); |
| | 125 | | else |
| 3 | 126 | | NextState(); |
| 3 | 127 | | break; |
| | 128 | |
|
| | 129 | | case State.CATALOG_LOADED: |
| 5 | 130 | | NextState(); |
| 5 | 131 | | break; |
| | 132 | |
|
| | 133 | | case State.LOADING_SCENE: |
| 5 | 134 | | LoadScene(); |
| 5 | 135 | | break; |
| | 136 | |
|
| | 137 | | case State.SCENE_LOADED: |
| 1 | 138 | | EnterEditMode(); |
| | 139 | | break; |
| | 140 | | } |
| 1 | 141 | | } |
| | 142 | |
|
| | 143 | | private void SendManifestToScene() |
| | 144 | | { |
| | 145 | | //We remove the old assets to they don't collide with the new ones |
| 1 | 146 | | BIWUtils.RemoveAssetsFromCurrentScene(); |
| | 147 | |
|
| | 148 | | //We add the assets from the scene to the catalog |
| 1 | 149 | | var assets = sceneToEdit.manifest.scene.assets.Values.ToArray(); |
| 1 | 150 | | AssetCatalogBridge.i.AddScenesObjectToSceneCatalog(assets); |
| | 151 | |
|
| | 152 | | //We prepare the mappings to the scenes |
| 1 | 153 | | Dictionary<string, string> contentDictionary = new Dictionary<string, string>(); |
| | 154 | |
|
| 2 | 155 | | foreach (var sceneObject in assets) |
| | 156 | | { |
| 0 | 157 | | foreach (var content in sceneObject.contents) |
| | 158 | | { |
| 0 | 159 | | if (!contentDictionary.ContainsKey(content.Key)) |
| 0 | 160 | | contentDictionary.Add(content.Key, content.Value); |
| | 161 | | } |
| | 162 | | } |
| | 163 | |
|
| | 164 | | //We add the mappings to the scene |
| 1 | 165 | | BIWUtils.AddSceneMappings(contentDictionary, BIWUrlUtils.GetUrlSceneObjectContent(), sceneToEdit.scene.scene |
| | 166 | |
|
| | 167 | | // We iterate all the entities to create the entity in the scene |
| 2 | 168 | | foreach (BuilderEntity builderEntity in sceneToEdit.manifest.scene.entities.Values) |
| | 169 | | { |
| 0 | 170 | | var entity = sceneToEdit.scene.CreateEntity(builderEntity.id.GetHashCode()); |
| | 171 | |
|
| 0 | 172 | | bool nameComponentFound = false; |
| | 173 | | // We iterate all the id of components in the entity, to add the component |
| 0 | 174 | | foreach (string idComponent in builderEntity.components) |
| | 175 | | { |
| | 176 | | //This shouldn't happen, the component should be always in the scene, but just in case |
| 0 | 177 | | if (!sceneToEdit.manifest.scene.components.ContainsKey(idComponent)) |
| | 178 | | continue; |
| | 179 | |
|
| | 180 | | // We get the component from the scene and create it in the entity |
| 0 | 181 | | BuilderComponent component = sceneToEdit.manifest.scene.components[idComponent]; |
| | 182 | |
|
| 0 | 183 | | switch (component.type) |
| | 184 | | { |
| | 185 | | case "Transform": |
| | 186 | | DCLTransform.Model model; |
| | 187 | |
|
| | 188 | | try |
| | 189 | | { |
| | 190 | | // This is a very ugly way to handle the things because some times the data can come ser |
| | 191 | | // It will be deleted when we create the new builder server that only have 1 way to hand |
| 0 | 192 | | model = JsonConvert.DeserializeObject<DCLTransform.Model>(component.data.ToString()); |
| 0 | 193 | | } |
| 0 | 194 | | catch (Exception e) |
| | 195 | | { |
| | 196 | | // We may have create the component so de data is not serialized |
| 0 | 197 | | model = JsonConvert.DeserializeObject<DCLTransform.Model>(JsonConvert.SerializeObject(co |
| 0 | 198 | | } |
| | 199 | |
|
| 0 | 200 | | EntityComponentsUtils.AddTransformComponent(sceneToEdit.scene, entity, model); |
| 0 | 201 | | break; |
| | 202 | |
|
| | 203 | | case "GLTFShape": |
| | 204 | | LoadableShape.Model gltfModel; |
| | 205 | |
|
| | 206 | | try |
| | 207 | | { |
| | 208 | | // This is a very ugly way to handle the things because some times the data can come ser |
| | 209 | | // It will be deleted when we create the new builder server that only have 1 way to hand |
| 0 | 210 | | gltfModel = JsonConvert.DeserializeObject<LoadableShape.Model>(component.data.ToString() |
| 0 | 211 | | } |
| 0 | 212 | | catch (Exception e) |
| | 213 | | { |
| | 214 | | // We may have create the component so de data is not serialized |
| 0 | 215 | | gltfModel = (GLTFShape.Model)component.data; |
| 0 | 216 | | } |
| | 217 | |
|
| 0 | 218 | | EntityComponentsUtils.AddGLTFComponent(sceneToEdit.scene, entity, gltfModel, component.id); |
| 0 | 219 | | break; |
| | 220 | |
|
| | 221 | | case "NFTShape": |
| | 222 | | //Builder use a different way to load the NFT so we convert it to our system |
| 0 | 223 | | JObject jObject = JObject.Parse(component.data.ToString()); |
| | 224 | |
|
| 0 | 225 | | string url = jObject["url"].ToString(); |
| 0 | 226 | | string assedId = url.Replace(BIWSettings.NFT_ETHEREUM_PROTOCOL, ""); |
| 0 | 227 | | int index = assedId.IndexOf("/", StringComparison.Ordinal); |
| 0 | 228 | | string partToremove = assedId.Substring(index); |
| 0 | 229 | | assedId = assedId.Replace(partToremove, ""); |
| | 230 | |
|
| 0 | 231 | | NFTShape.Model nftModel = new NFTShape.Model(); |
| 0 | 232 | | nftModel.color = new Color(0.6404918f, 0.611472f, 0.8584906f); |
| 0 | 233 | | nftModel.src = url; |
| 0 | 234 | | nftModel.assetId = assedId; |
| | 235 | |
|
| 0 | 236 | | EntityComponentsUtils.AddNFTShapeComponent(sceneToEdit.scene, entity, nftModel, component.id |
| 0 | 237 | | break; |
| | 238 | |
|
| | 239 | | case "Name": |
| 0 | 240 | | nameComponentFound = true; |
| 0 | 241 | | DCLName.Model nameModel = JsonConvert.DeserializeObject<DCLName.Model>(component.data.ToStri |
| 0 | 242 | | nameModel.builderValue = builderEntity.name; |
| 0 | 243 | | EntityComponentsUtils.AddNameComponent(sceneToEdit.scene , entity, nameModel, Guid.NewGuid() |
| 0 | 244 | | break; |
| | 245 | |
|
| | 246 | | case "LockedOnEdit": |
| 0 | 247 | | DCLLockedOnEdit.Model lockedModel = JsonConvert.DeserializeObject<DCLLockedOnEdit.Model>(com |
| 0 | 248 | | EntityComponentsUtils.AddLockedOnEditComponent(sceneToEdit.scene , entity, lockedModel, Guid |
| 0 | 249 | | break; |
| | 250 | | case "Script": |
| 0 | 251 | | SmartItemComponent.Model smartModel = JsonConvert.DeserializeObject<SmartItemComponent.Model |
| 0 | 252 | | sceneToEdit.scene.componentsManagerLegacy.EntityComponentCreateOrUpdate(entity.entityId, CLA |
| | 253 | | break; |
| | 254 | | } |
| | 255 | | } |
| | 256 | |
|
| | 257 | | // We need to mantain the builder name of the entity, so we create the equivalent part in biw. We do thi |
| 0 | 258 | | if (!nameComponentFound) |
| | 259 | | { |
| 0 | 260 | | DCLName.Model nameModel = new DCLName.Model(); |
| 0 | 261 | | nameModel.value = builderEntity.name; |
| 0 | 262 | | nameModel.builderValue = builderEntity.name; |
| 0 | 263 | | EntityComponentsUtils.AddNameComponent(sceneToEdit.scene , entity, nameModel, Guid.NewGuid().ToStrin |
| | 264 | | } |
| | 265 | | } |
| 1 | 266 | | } |
| | 267 | |
|
| | 268 | | public void WebRequestCreated(IWebRequestAsyncOperation webRequest) |
| | 269 | | { |
| 0 | 270 | | if (currentState == State.LOADING_CATALOG) |
| 0 | 271 | | catalogAsyncOp = webRequest; |
| 0 | 272 | | } |
| | 273 | |
|
| | 274 | | public void Update() |
| | 275 | | { |
| 0 | 276 | | if (currentState != State.LOADING_CATALOG) |
| 0 | 277 | | return; |
| | 278 | |
|
| 0 | 279 | | if (catalogAsyncOp?.webRequest != null) |
| 0 | 280 | | UpdateCatalogLoadingProgress(catalogAsyncOp.webRequest.downloadProgress * 100); |
| 0 | 281 | | } |
| | 282 | |
|
| | 283 | | private void OnPlayerTeleportedToEditScene(Vector2Int coords) |
| | 284 | | { |
| 0 | 285 | | StartFlowFromLandWithPermission(Environment.i.world.state.GetScene(coords), SOURCE_BUILDER_PANEl); |
| 0 | 286 | | } |
| | 287 | |
|
| | 288 | | public void StartFlowFromProject(Manifest.Manifest manifest) |
| | 289 | | { |
| 0 | 290 | | bool hasBeenCreatedThisSession = !string.IsNullOrEmpty(DataStore.i.builderInWorld.lastProjectIdCreated.Get() |
| 0 | 291 | | DataStore.i.builderInWorld.lastProjectIdCreated.Set(""); |
| | 292 | |
|
| 0 | 293 | | BuilderScene builderScene = new BuilderScene(manifest, IBuilderScene.SceneType.PROJECT,hasBeenCreatedThisSes |
| 0 | 294 | | StartFlow(builderScene, SOURCE_BUILDER_PANEl); |
| 0 | 295 | | } |
| | 296 | |
|
| | 297 | | public void StartFlowFromLandCoords(Vector2Int coords) |
| | 298 | | { |
| 0 | 299 | | Scene deployedScene = GetDeployedSceneFromParcel(coords); |
| 0 | 300 | | Vector2Int parcelSize = BIWUtils.GetSceneSize(deployedScene.parcels); |
| | 301 | |
|
| 0 | 302 | | StartFromLand(deployedScene.@base, deployedScene, parcelSize, SOURCE_BUILDER_PANEl); |
| 0 | 303 | | } |
| | 304 | |
|
| | 305 | | public void ShowBuilderLoading() |
| | 306 | | { |
| 1 | 307 | | initialLoadingController.Show(); |
| 1 | 308 | | initialLoadingController.SetPercentage(0f); |
| 1 | 309 | | } |
| | 310 | |
|
| | 311 | | public void HideBuilderLoading() |
| | 312 | | { |
| 0 | 313 | | initialLoadingController.Hide(); |
| 0 | 314 | | } |
| | 315 | |
|
| | 316 | | public void StartExitMode() |
| | 317 | | { |
| 2 | 318 | | context.cameraController.TakeSceneScreenshotFromResetPosition((sceneSnapshot) => |
| | 319 | | { |
| 0 | 320 | | if (sceneSnapshot != null) |
| | 321 | | { |
| 0 | 322 | | sceneToEdit.sceneScreenshotTexture = sceneSnapshot; |
| | 323 | |
|
| 0 | 324 | | if (sceneToEdit.manifest != null) |
| 0 | 325 | | context.builderAPIController.SetThumbnail(sceneToEdit.manifest.project.id, sceneSnapshot); |
| | 326 | | } |
| 0 | 327 | | }); |
| | 328 | |
|
| 2 | 329 | | if (context.editorContext.editorHUD == null ) |
| 0 | 330 | | return; |
| | 331 | |
|
| 2 | 332 | | if (context.editorContext.publishController.HasUnpublishChanges() && sceneToEdit.sceneType == IBuilderScene. |
| | 333 | | { |
| 0 | 334 | | if (sceneToEdit.sceneType == IBuilderScene.SceneType.LAND) |
| 0 | 335 | | context.editorContext.editorHUD.ConfigureConfirmationModal( |
| | 336 | | BIWSettings.EXIT_MODAL_TITLE, |
| | 337 | | BIWSettings.EXIT_WITHOUT_PUBLISH_MODAL_SUBTITLE, |
| | 338 | | BIWSettings.EXIT_WITHOUT_PUBLISH_MODAL_CANCEL_BUTTON, |
| | 339 | | BIWSettings.EXIT_WITHOUT_PUBLISH_MODAL_CONFIRM_BUTTON); |
| 0 | 340 | | } |
| | 341 | | else |
| | 342 | | { |
| 2 | 343 | | context.editorContext.editorHUD.ConfigureConfirmationModal( |
| | 344 | | BIWSettings.EXIT_MODAL_TITLE, |
| | 345 | | BIWSettings.EXIT_MODAL_SUBTITLE, |
| | 346 | | BIWSettings.EXIT_MODAL_CANCEL_BUTTON, |
| | 347 | | BIWSettings.EXIT_MODAL_CONFIRM_BUTTON); |
| | 348 | | } |
| 2 | 349 | | } |
| | 350 | |
|
| | 351 | | public IParcelScene FindSceneToEdit() |
| | 352 | | { |
| 6 | 353 | | foreach (IParcelScene scene in Environment.i.world.state.GetScenesSortedByDistance()) |
| | 354 | | { |
| 2 | 355 | | if (WorldStateUtils.IsCharacterInsideScene(scene)) |
| 2 | 356 | | return scene; |
| | 357 | | } |
| | 358 | |
|
| 0 | 359 | | return null; |
| 2 | 360 | | } |
| | 361 | |
|
| | 362 | | private void UpdateLandsWithAccess() |
| | 363 | | { |
| 2 | 364 | | ICatalyst catalyst = Environment.i.platform.serviceProviders.catalyst; |
| 2 | 365 | | ITheGraph theGraph = Environment.i.platform.serviceProviders.theGraph; |
| | 366 | |
|
| 2 | 367 | | DeployedScenesFetcher.FetchLandsFromOwner( |
| | 368 | | catalyst, |
| | 369 | | theGraph, |
| | 370 | | userProfile.ethAddress, |
| | 371 | | KernelConfig.i.Get().network, |
| | 372 | | BIWSettings.CACHE_TIME_LAND, |
| | 373 | | BIWSettings.CACHE_TIME_SCENES) |
| | 374 | | .Then(lands => |
| | 375 | | { |
| 0 | 376 | | DataStore.i.builderInWorld.landsWithAccess.Set(lands.ToArray(), true); |
| 0 | 377 | | if (isWaitingForPermission && Vector3.Distance(askPermissionLastPosition, DCLCharac |
| | 378 | | { |
| 0 | 379 | | CheckSceneToEditByShorcut(); |
| | 380 | | } |
| | 381 | |
|
| 0 | 382 | | isWaitingForPermission = false; |
| 0 | 383 | | alreadyAskedForLandPermissions = true; |
| 0 | 384 | | }); |
| 2 | 385 | | } |
| | 386 | |
|
| | 387 | | internal void CatalogLoaded() |
| | 388 | | { |
| 5 | 389 | | catalogLoaded = true; |
| 5 | 390 | | if ( context.editorContext.editorHUD != null) |
| 5 | 391 | | context.editorContext.editorHUD.RefreshCatalogContent(); |
| 5 | 392 | | NextState(); |
| 5 | 393 | | } |
| | 394 | |
|
| | 395 | | internal void StartFlow(IBuilderScene targetScene, string source) |
| | 396 | | { |
| 2 | 397 | | if (currentState != State.IDLE || targetScene == null) |
| 1 | 398 | | return; |
| | 399 | |
|
| 1 | 400 | | DataStore.i.exploreV2.isOpen.Set(false); |
| | 401 | |
|
| 1 | 402 | | sceneToEditId = targetScene.manifest.project.scene_id; |
| 1 | 403 | | sceneToEdit = targetScene; |
| | 404 | |
|
| 1 | 405 | | NotificationsController.i.allowNotifications = false; |
| 1 | 406 | | CommonScriptableObjects.allUIHidden.Set(true); |
| 1 | 407 | | NotificationsController.i.allowNotifications = true; |
| 1 | 408 | | inputController.inputTypeMode = InputTypeMode.BUILD_MODE_LOADING; |
| | 409 | |
|
| | 410 | | // We prepare the bridge for the current scene |
| 1 | 411 | | bridge.SetScene(targetScene); |
| | 412 | |
|
| | 413 | | // We configure the loading part |
| 1 | 414 | | ShowBuilderLoading(); |
| | 415 | |
|
| 1 | 416 | | DataStore.i.common.appMode.Set(AppMode.BUILDER_IN_WORLD_EDITION); |
| 1 | 417 | | DataStore.i.virtualAudioMixer.sceneSFXVolume.Set(0f); |
| 1 | 418 | | BIWAnalytics.StartEditorFlow(source); |
| 1 | 419 | | beginStartFlowTimeStamp = Time.realtimeSinceStartup; |
| | 420 | |
|
| 1 | 421 | | NextState(); |
| 1 | 422 | | } |
| | 423 | |
|
| | 424 | | internal void GetCatalog() |
| | 425 | | { |
| 3 | 426 | | BIWNFTController.i.StartFetchingNft(); |
| 3 | 427 | | var catalogPromise = context.builderAPIController.GetCompleteCatalog(userProfile.ethAddress); |
| 3 | 428 | | catalogPromise.Then(x => |
| | 429 | | { |
| 3 | 430 | | CatalogLoaded(); |
| 3 | 431 | | }); |
| 3 | 432 | | catalogPromise.Catch(error => |
| | 433 | | { |
| 0 | 434 | | BIWUtils.ShowGenericNotification(error); |
| 0 | 435 | | }); |
| 3 | 436 | | } |
| | 437 | |
|
| | 438 | | public void ChangeEditModeStatusByShortcut(DCLAction_Trigger action) |
| | 439 | | { |
| 1 | 440 | | if (currentState != State.EDITING && currentState != State.IDLE) |
| 0 | 441 | | return; |
| | 442 | |
|
| 1 | 443 | | if (currentState == State.EDITING ) |
| | 444 | | { |
| 0 | 445 | | context.editorContext.editorHUD.ExitStart(); |
| 0 | 446 | | return; |
| | 447 | | } |
| | 448 | |
|
| 1 | 449 | | if (DataStore.i.builderInWorld.landsWithAccess.Get().Length == 0 && !alreadyAskedForLandPermissions) |
| | 450 | | { |
| 1 | 451 | | ActivateLandAccessBackgroundChecker(); |
| 1 | 452 | | BIWUtils.ShowGenericNotification(BIWSettings.LAND_EDITION_WAITING_FOR_PERMISSIONS_MESSAGE, DCL.Notificat |
| 1 | 453 | | isWaitingForPermission = true; |
| 1 | 454 | | askPermissionLastPosition = DCLCharacterController.i.characterPosition.unityPosition; |
| 1 | 455 | | } |
| | 456 | | else |
| | 457 | | { |
| 0 | 458 | | CheckSceneToEditByShorcut(); |
| | 459 | | } |
| 0 | 460 | | } |
| | 461 | |
|
| | 462 | | internal void CheckSceneToEditByShorcut() |
| | 463 | | { |
| 1 | 464 | | var scene = FindSceneToEdit(); |
| 1 | 465 | | StartFlowFromLandWithPermission(scene, SOURCE_SHORTCUT); |
| 1 | 466 | | } |
| | 467 | |
|
| | 468 | | internal void NewSceneAdded(IParcelScene newScene) |
| | 469 | | { |
| 1 | 470 | | if (newScene.sceneData.id != sceneToEditId) |
| 0 | 471 | | return; |
| | 472 | |
|
| 1 | 473 | | Environment.i.world.sceneController.OnNewSceneAdded -= NewSceneAdded; |
| | 474 | |
|
| 1 | 475 | | var scene = Environment.i.world.state.GetScene(sceneToEditId); |
| 1 | 476 | | sceneToEdit.SetScene(scene); |
| 1 | 477 | | sceneMetricsAnalyticsHelper = new BiwSceneMetricsAnalyticsHelper(sceneToEdit.scene); |
| 1 | 478 | | sceneToEdit.scene.OnLoadingStateUpdated += UpdateSceneLoadingProgress; |
| 1 | 479 | | SendManifestToScene(); |
| 1 | 480 | | context.cameraController.ActivateCamera(sceneToEdit.scene); |
| 1 | 481 | | } |
| | 482 | |
|
| | 483 | | private void NewSceneReady(string id) |
| | 484 | | { |
| 2 | 485 | | if (sceneToEditId != id) |
| 1 | 486 | | return; |
| | 487 | |
|
| 1 | 488 | | sceneToEdit.scene.OnLoadingStateUpdated -= UpdateSceneLoadingProgress; |
| 1 | 489 | | Environment.i.world.sceneController.OnReadyScene -= NewSceneReady; |
| 1 | 490 | | sceneToEditId = null; |
| 1 | 491 | | NextState(); |
| 1 | 492 | | } |
| | 493 | |
|
| | 494 | | internal bool UserHasPermissionOnParcelScene(IParcelScene sceneToCheck) |
| | 495 | | { |
| 2 | 496 | | if (BYPASS_LAND_OWNERSHIP_CHECK) |
| 0 | 497 | | return true; |
| | 498 | |
|
| 4 | 499 | | List<Vector2Int> allParcelsWithAccess = DataStore.i.builderInWorld.landsWithAccess.Get().SelectMany(land => |
| 6 | 500 | | foreach (Vector2Int parcel in allParcelsWithAccess) |
| | 501 | | { |
| 4 | 502 | | if (sceneToCheck.sceneData.parcels.Any(currentParcel => currentParcel.x == parcel.x && currentParcel.y = |
| 2 | 503 | | return true; |
| | 504 | | } |
| | 505 | |
|
| 0 | 506 | | return false; |
| 2 | 507 | | } |
| | 508 | |
|
| | 509 | | internal Scene GetDeployedSceneFromParcel(Vector2Int coords) |
| | 510 | | { |
| 0 | 511 | | List<Scene> allDeployedScenesWithAccess = DataStore.i.builderInWorld.landsWithAccess.Get().SelectMany(land = |
| 0 | 512 | | foreach (Scene scene in allDeployedScenesWithAccess) |
| | 513 | | { |
| 0 | 514 | | List<Vector2Int> scenes = scene.parcels.ToList(); |
| 0 | 515 | | foreach (Vector2Int parcel in scenes) |
| | 516 | | { |
| 0 | 517 | | if (coords.x == parcel.x && coords.y == parcel.y) |
| 0 | 518 | | return scene; |
| | 519 | | } |
| | 520 | | } |
| 0 | 521 | | return null; |
| 0 | 522 | | } |
| | 523 | |
|
| | 524 | | internal Scene GetDeployedSceneFromParcel(IParcelScene sceneToCheck) |
| | 525 | | { |
| 2 | 526 | | List<Scene> allDeployedScenesWithAccess = DataStore.i.builderInWorld.landsWithAccess.Get().SelectMany(land = |
| 2 | 527 | | foreach (Scene scene in allDeployedScenesWithAccess) |
| | 528 | | { |
| 0 | 529 | | List<Vector2Int> scenes = scene.parcels.ToList(); |
| 0 | 530 | | foreach (Vector2Int parcel in scenes) |
| | 531 | | { |
| 0 | 532 | | if (sceneToCheck.sceneData.parcels.Any(currentParcel => currentParcel.x == parcel.x && currentParcel |
| 0 | 533 | | return scene; |
| | 534 | | } |
| | 535 | | } |
| 1 | 536 | | return null; |
| 0 | 537 | | } |
| | 538 | |
|
| | 539 | | internal bool IsParcelSceneDeployedFromSDK(IParcelScene sceneToCheck) |
| | 540 | | { |
| 4 | 541 | | List<Scene> allDeployedScenesWithAccess = DataStore.i.builderInWorld.landsWithAccess.Get().SelectMany(land = |
| 5 | 542 | | foreach (Scene scene in allDeployedScenesWithAccess) |
| | 543 | | { |
| 1 | 544 | | if (scene.source != Scene.Source.SDK) |
| | 545 | | continue; |
| | 546 | |
|
| 1 | 547 | | List<Vector2Int> parcelsDeployedFromSDK = scene.parcels.ToList(); |
| 3 | 548 | | foreach (Vector2Int parcel in parcelsDeployedFromSDK) |
| | 549 | | { |
| 2 | 550 | | if (sceneToCheck.sceneData.parcels.Any(currentParcel => currentParcel.x == parcel.x && currentParcel |
| 1 | 551 | | return true; |
| | 552 | | } |
| | 553 | | } |
| | 554 | |
|
| 1 | 555 | | return false; |
| 1 | 556 | | } |
| | 557 | |
|
| | 558 | | internal void EnterEditMode() |
| | 559 | | { |
| 1 | 560 | | initialLoadingController.SetPercentage(100f); |
| 1 | 561 | | initialLoadingController.Hide(true, onHideAction: () => |
| | 562 | | { |
| 0 | 563 | | inputController.inputTypeMode = InputTypeMode.BUILD_MODE; |
| 0 | 564 | | context.editorContext.editorHUD?.SetVisibility(true); |
| 0 | 565 | | CommonScriptableObjects.allUIHidden.Set(true); |
| 0 | 566 | | }); |
| | 567 | |
|
| 1 | 568 | | DCLCharacterController.OnPositionSet += ExitAfterCharacterTeleport; |
| | 569 | |
|
| 1 | 570 | | portableExperiencesToResume = DataStore.i.experiencesViewer.activeExperience.Get(); |
| 1 | 571 | | WebInterface.SetDisabledPortableExperiences(DataStore.i.experiencesViewer.activeExperience.Get().ToArray()); |
| | 572 | |
|
| 1 | 573 | | context.editor.EnterEditMode(sceneToEdit); |
| 1 | 574 | | DataStore.i.player.canPlayerMove.Set(false); |
| 1 | 575 | | BIWAnalytics.EnterEditor( Time.realtimeSinceStartup - beginStartFlowTimeStamp); |
| 1 | 576 | | } |
| | 577 | |
|
| | 578 | | internal void ExitEditMode() |
| | 579 | | { |
| 2 | 580 | | currentState = State.IDLE; |
| 2 | 581 | | DataStore.i.HUDs.loadingHUD.visible.Set(true); |
| 2 | 582 | | initialLoadingController.Hide(true); |
| 2 | 583 | | inputController.inputTypeMode = InputTypeMode.GENERAL; |
| 2 | 584 | | CommonScriptableObjects.allUIHidden.Set(false); |
| 2 | 585 | | context.cameraController.DeactivateCamera(); |
| 2 | 586 | | context.editor.ExitEditMode(); |
| | 587 | |
|
| 2 | 588 | | builderInWorldBridge.StopIsolatedMode(); |
| | 589 | |
|
| 2 | 590 | | Utils.UnlockCursor(); |
| | 591 | |
|
| 2 | 592 | | DataStore.i.player.canPlayerMove.Set(true); |
| 2 | 593 | | DCLCharacterController.OnPositionSet -= ExitAfterCharacterTeleport; |
| 2 | 594 | | } |
| | 595 | |
|
| | 596 | | public void StartFlowFromLandWithPermission(IParcelScene targetScene, string source) |
| | 597 | | { |
| 2 | 598 | | if (currentState != State.IDLE || targetScene == null) |
| 1 | 599 | | return; |
| | 600 | |
|
| 1 | 601 | | if (!UserHasPermissionOnParcelScene(targetScene)) |
| | 602 | | { |
| 0 | 603 | | BIWUtils.ShowGenericNotification(BIWSettings.LAND_EDITION_NOT_ALLOWED_BY_PERMISSIONS_MESSAGE); |
| 0 | 604 | | return; |
| | 605 | | } |
| 1 | 606 | | else if (IsParcelSceneDeployedFromSDK(targetScene)) |
| | 607 | | { |
| 0 | 608 | | BIWUtils.ShowGenericNotification(BIWSettings.LAND_EDITION_NOT_ALLOWED_BY_SDK_LIMITATION_MESSAGE); |
| 0 | 609 | | return; |
| | 610 | | } |
| | 611 | |
|
| 1 | 612 | | Scene deployedScene = GetDeployedSceneFromParcel(targetScene); |
| 1 | 613 | | Vector2Int parcelSize = BIWUtils.GetSceneSize(targetScene); |
| | 614 | |
|
| 1 | 615 | | StartFromLand(targetScene.sceneData.basePosition, deployedScene, parcelSize, source); |
| 1 | 616 | | } |
| | 617 | |
|
| | 618 | | private void StartFromLand(Vector2Int landCoordsVector, Scene deployedScene, Vector2Int parcelSize, string sourc |
| | 619 | | { |
| 1 | 620 | | string landCoords = landCoordsVector.x + "," + landCoordsVector.y; |
| 1 | 621 | | Promise<InitialStateResponse> manifestPromise = initialStateManager.GetInitialManifest(context.builderAPICon |
| | 622 | |
|
| 1 | 623 | | manifestPromise.Then(response => |
| | 624 | | { |
| 1 | 625 | | BuilderScene builderScene = new BuilderScene(response.manifest, IBuilderScene.SceneType.LAND, response.h |
| 1 | 626 | | builderScene.landCoordsAsociated = landCoordsVector; |
| 1 | 627 | | StartFlow(builderScene, source); |
| 1 | 628 | | }); |
| | 629 | |
|
| 1 | 630 | | manifestPromise.Catch( error => |
| | 631 | | { |
| 0 | 632 | | BIWUtils.ShowGenericNotification(error); |
| 0 | 633 | | ExitEditMode(); |
| 0 | 634 | | }); |
| 1 | 635 | | } |
| | 636 | |
|
| | 637 | | private void LoadScene() |
| | 638 | | { |
| 5 | 639 | | Environment.i.platform.cullingController.Stop(); |
| | 640 | |
|
| | 641 | | // In this point we're sure that the catalog loading (the first half of our progress bar) has already finish |
| 5 | 642 | | initialLoadingController.SetPercentage(50f); |
| 5 | 643 | | Environment.i.world.sceneController.OnNewSceneAdded += NewSceneAdded; |
| 5 | 644 | | Environment.i.world.sceneController.OnReadyScene += NewSceneReady; |
| 5 | 645 | | Environment.i.world.blockersController.SetEnabled(false); |
| | 646 | |
|
| 5 | 647 | | ILand land = BIWUtils.CreateILandFromManifest(sceneToEdit.manifest, DataStore.i.player.playerGridPosition.Ge |
| | 648 | |
|
| 5 | 649 | | builderInWorldBridge.StartIsolatedMode(land); |
| 5 | 650 | | } |
| | 651 | |
|
| | 652 | | internal void ActivateLandAccessBackgroundChecker() |
| | 653 | | { |
| 2 | 654 | | userProfile = UserProfile.GetOwnUserProfile(); |
| 2 | 655 | | if (!string.IsNullOrEmpty(userProfile.userId)) |
| | 656 | | { |
| 2 | 657 | | if (updateLandsWithAcessCoroutine != null) |
| 0 | 658 | | CoroutineStarter.Stop(updateLandsWithAcessCoroutine); |
| 2 | 659 | | updateLandsWithAcessCoroutine = CoroutineStarter.Start(CheckLandsAccess()); |
| | 660 | | } |
| 2 | 661 | | } |
| | 662 | |
|
| 0 | 663 | | private void UpdateSceneLoadingProgress(float sceneLoadingProgress) { initialLoadingController.SetPercentage(50f |
| | 664 | |
|
| 0 | 665 | | private void UpdateCatalogLoadingProgress(float catalogLoadingProgress) { initialLoadingController.SetPercentage |
| | 666 | |
|
| 2 | 667 | | internal void ExitAfterCharacterTeleport(DCLCharacterPosition position) { ExitEditMode(); } |
| | 668 | |
|
| | 669 | | private IEnumerator CheckLandsAccess() |
| | 670 | | { |
| 0 | 671 | | while (true) |
| | 672 | | { |
| 2 | 673 | | UpdateLandsWithAccess(); |
| 2 | 674 | | yield return WaitForSecondsCache.Get(BIWSettings.REFRESH_LANDS_WITH_ACCESS_INTERVAL); |
| | 675 | | } |
| | 676 | | } |
| | 677 | | } |
| | 678 | | } |