| | 1 | | using DCL; |
| | 2 | | using DCL.Configuration; |
| | 3 | | using DCL.Controllers; |
| | 4 | | using DCL.Tutorial; |
| | 5 | | using Newtonsoft.Json; |
| | 6 | | using System; |
| | 7 | | using System.Collections; |
| | 8 | | using System.Collections.Generic; |
| | 9 | | using System.Linq; |
| | 10 | | using UnityEngine; |
| | 11 | | using Environment = DCL.Environment; |
| | 12 | |
|
| | 13 | | public class BIWMainController : PluginFeature |
| | 14 | | { |
| | 15 | | internal static bool BYPASS_LAND_OWNERSHIP_CHECK = false; |
| | 16 | | private const float DISTANCE_TO_DISABLE_BUILDER_IN_WORLD = 45f; |
| | 17 | | private const float MAX_DISTANCE_STOP_TRYING_TO_ENTER = 16; |
| | 18 | |
|
| | 19 | | private GameObject cursorGO; |
| | 20 | | private InputController inputController; |
| | 21 | | private GameObject[] groundVisualsGO; |
| | 22 | |
|
| | 23 | | internal BIWOutlinerController outlinerController; |
| | 24 | | internal BIWInputHandler inputHandler; |
| | 25 | | internal BIWPublishController publishController; |
| | 26 | | internal BIWCreatorController creatorController; |
| | 27 | | internal BIWModeController modeController; |
| | 28 | | internal BIWFloorHandler floorHandler; |
| | 29 | | internal BIWEntityHandler entityHandler; |
| | 30 | | internal BIWActionController actionController; |
| | 31 | | internal BIWSaveController saveController; |
| | 32 | | internal BIWInputWrapper inputWrapper; |
| | 33 | | internal BIWRaycastController raycastController; |
| | 34 | | internal BIWGizmosController gizmosController; |
| | 35 | |
|
| | 36 | | private BuilderInWorldBridge builderInWorldBridge; |
| | 37 | | private BuilderInWorldAudioHandler biwAudioHandler; |
| | 38 | | private BIWContext context; |
| | 39 | |
|
| 26 | 40 | | private readonly List<IBIWController> controllers = new List<IBIWController>(); |
| | 41 | |
|
| | 42 | | internal ParcelScene sceneToEdit; |
| | 43 | |
|
| | 44 | | private Material skyBoxMaterial; |
| | 45 | |
|
| 0 | 46 | | public bool isBuilderInWorldActivated { get; internal set; } = false; |
| | 47 | |
|
| | 48 | | private InputAction_Trigger editModeChangeInputAction; |
| | 49 | |
|
| | 50 | | internal int checkerInsideSceneOptimizationCounter = 0; |
| | 51 | | internal string sceneToEditId; |
| | 52 | | internal bool catalogAdded = false; |
| | 53 | | private bool sceneReady = false; |
| | 54 | | private bool isInit = false; |
| | 55 | | private Material previousSkyBoxMaterial; |
| | 56 | | private Vector3 parcelUnityMiddlePoint; |
| | 57 | | private bool previousAllUIHidden; |
| | 58 | | private WebRequestAsyncOperation catalogAsyncOp; |
| | 59 | | private bool isCatalogLoading = false; |
| | 60 | | internal bool areCatalogHeadersReady = false; |
| | 61 | | private float beginStartFlowTimeStamp = 0; |
| | 62 | | private float startEditorTimeStamp = 0; |
| | 63 | | internal bool isCatalogRequested = false; |
| | 64 | | internal bool isEnteringEditMode = false; |
| | 65 | | private bool activeFeature = false; |
| | 66 | |
|
| | 67 | | internal IBuilderInWorldLoadingController initialLoadingController; |
| | 68 | |
|
| | 69 | | private UserProfile userProfile; |
| | 70 | | internal Coroutine updateLandsWithAcessCoroutine; |
| | 71 | | private Dictionary<string, string> catalogCallHeaders; |
| | 72 | |
|
| | 73 | | internal bool isWaitingForPermission = false; |
| | 74 | | private bool alreadyAskedForLandPermissions = false; |
| | 75 | | private Vector3 askPermissionLastPosition; |
| | 76 | |
|
| | 77 | | public override void Initialize() |
| | 78 | | { |
| 26 | 79 | | base.Initialize(); |
| | 80 | |
|
| 26 | 81 | | if (isInit) |
| 0 | 82 | | return; |
| | 83 | |
|
| 26 | 84 | | activeFeature = true; |
| 26 | 85 | | isInit = true; |
| | 86 | |
|
| | 87 | | //We init the lands so we don't have a null reference |
| 26 | 88 | | DataStore.i.builderInWorld.landsWithAccess.Set(new LandWithAccess[0]); |
| | 89 | |
|
| 26 | 90 | | BIWCatalogManager.Init(); |
| | 91 | |
|
| 26 | 92 | | CreateControllers(); |
| 26 | 93 | | InitReferences(InitialSceneReferences.i); |
| | 94 | |
|
| 26 | 95 | | if (builderInWorldBridge != null) |
| | 96 | | { |
| 26 | 97 | | builderInWorldBridge.OnCatalogHeadersReceived += CatalogHeadersReceived; |
| 26 | 98 | | builderInWorldBridge.OnBuilderProjectInfo += BuilderProjectPanelInfo; |
| | 99 | | } |
| | 100 | |
|
| 26 | 101 | | InitHUD(); |
| | 102 | |
|
| 26 | 103 | | BIWTeleportAndEdit.OnTeleportEnd += OnPlayerTeleportedToEditScene; |
| | 104 | |
|
| 26 | 105 | | ConfigureLoadingController(); |
| 26 | 106 | | InitControllers(); |
| | 107 | |
|
| 26 | 108 | | CommonScriptableObjects.builderInWorldNotNecessaryUIVisibilityStatus.Set(true); |
| | 109 | |
|
| 26 | 110 | | builderInWorldBridge.AskKernelForCatalogHeaders(); |
| | 111 | |
|
| 26 | 112 | | isCatalogLoading = true; |
| 26 | 113 | | BIWNFTController.i.Initialize(); |
| 26 | 114 | | BIWNFTController.i.OnNFTUsageChange += OnNFTUsageChange; |
| | 115 | |
|
| 26 | 116 | | editModeChangeInputAction = context.inputsReferencesAsset.editModeChangeInputAction; |
| 26 | 117 | | editModeChangeInputAction.OnTriggered += ChangeEditModeStatusByShortcut; |
| | 118 | |
|
| 26 | 119 | | biwAudioHandler = GameObject.Instantiate(context.projectReferencesAsset.audioPrefab, Vector3.zero, Quaternion.id |
| 26 | 120 | | biwAudioHandler.Init(context); |
| 26 | 121 | | biwAudioHandler.gameObject.SetActive(false); |
| 26 | 122 | | } |
| | 123 | |
|
| | 124 | | public void InitReferences(InitialSceneReferences initalReference) |
| | 125 | | { |
| | 126 | |
|
| 26 | 127 | | builderInWorldBridge = initalReference.builderInWorldBridge; |
| 26 | 128 | | cursorGO = initalReference.cursorCanvas; |
| 26 | 129 | | inputController = initalReference.inputController; |
| | 130 | |
|
| 26 | 131 | | List<GameObject> grounds = new List<GameObject>(); |
| 52 | 132 | | for (int i = 0; i < InitialSceneReferences.i.groundVisual.transform.transform.childCount; i++) |
| | 133 | | { |
| 0 | 134 | | grounds.Add(InitialSceneReferences.i.groundVisual.transform.transform.GetChild(i).gameObject); |
| | 135 | | } |
| 26 | 136 | | groundVisualsGO = grounds.ToArray(); |
| | 137 | |
|
| 26 | 138 | | context = new BIWContext(); |
| 26 | 139 | | context.Init( |
| | 140 | | outlinerController, |
| | 141 | | inputHandler, |
| | 142 | | inputWrapper, |
| | 143 | | publishController, |
| | 144 | | creatorController, |
| | 145 | | modeController, |
| | 146 | | floorHandler, |
| | 147 | | entityHandler, |
| | 148 | | actionController, |
| | 149 | | saveController, |
| | 150 | | raycastController, |
| | 151 | | gizmosController, |
| | 152 | | InitialSceneReferences.i |
| | 153 | | ); |
| | 154 | |
|
| 26 | 155 | | skyBoxMaterial = context.projectReferencesAsset.skyBoxMaterial; |
| 26 | 156 | | } |
| | 157 | |
|
| | 158 | | private void CreateControllers() |
| | 159 | | { |
| 26 | 160 | | outlinerController = new BIWOutlinerController(); |
| 26 | 161 | | inputHandler = new BIWInputHandler(); |
| 26 | 162 | | publishController = new BIWPublishController(); |
| 26 | 163 | | creatorController = new BIWCreatorController(); |
| 26 | 164 | | modeController = new BIWModeController(); |
| 26 | 165 | | floorHandler = new BIWFloorHandler(); |
| 26 | 166 | | entityHandler = new BIWEntityHandler(); |
| 26 | 167 | | actionController = new BIWActionController(); |
| 26 | 168 | | saveController = new BIWSaveController(); |
| 26 | 169 | | inputWrapper = new BIWInputWrapper(); |
| 26 | 170 | | raycastController = new BIWRaycastController(); |
| 26 | 171 | | gizmosController = new BIWGizmosController(); |
| 26 | 172 | | } |
| | 173 | |
|
| | 174 | | private void InitBuilderProjectPanel() |
| | 175 | | { |
| 0 | 176 | | if (HUDController.i.builderProjectsPanelController != null) |
| 0 | 177 | | HUDController.i.builderProjectsPanelController.OnJumpInOrEdit += GetCatalog; |
| 0 | 178 | | } |
| | 179 | |
|
| | 180 | | private void InitHUD() |
| | 181 | | { |
| 26 | 182 | | HUDConfiguration hudConfig = new HUDConfiguration(); |
| 26 | 183 | | hudConfig.active = true; |
| 26 | 184 | | hudConfig.visible = false; |
| 26 | 185 | | HUDController.i.CreateHudElement(hudConfig, HUDElementID.BUILDER_IN_WORLD_MAIN); |
| 26 | 186 | | HUDController.i.OnBuilderProjectPanelCreation += InitBuilderProjectPanel; |
| | 187 | |
|
| 26 | 188 | | HUDController.i.builderInWorldMainHud.Initialize(); |
| | 189 | |
|
| 26 | 190 | | HUDController.i.builderInWorldMainHud.OnTutorialAction += StartTutorial; |
| 26 | 191 | | HUDController.i.builderInWorldMainHud.OnStartExitAction += StartExitMode; |
| 26 | 192 | | HUDController.i.builderInWorldMainHud.OnLogoutAction += ExitEditMode; |
| | 193 | |
|
| 26 | 194 | | if (HUDController.i.builderProjectsPanelController != null) |
| 0 | 195 | | HUDController.i.builderProjectsPanelController.OnJumpInOrEdit += GetCatalog; |
| 26 | 196 | | } |
| | 197 | |
|
| | 198 | | public override void Dispose() |
| | 199 | | { |
| 27 | 200 | | base.Dispose(); |
| | 201 | |
|
| 27 | 202 | | if (userProfile != null) |
| 3 | 203 | | userProfile.OnUpdate -= OnUserProfileUpdate; |
| | 204 | |
|
| 27 | 205 | | CoroutineStarter.Stop(updateLandsWithAcessCoroutine); |
| | 206 | |
|
| 27 | 207 | | if (sceneToEdit != null) |
| 12 | 208 | | sceneToEdit.OnLoadingStateUpdated -= UpdateSceneLoadingProgress; |
| | 209 | |
|
| 27 | 210 | | Environment.i.world.sceneController.OnNewSceneAdded -= NewSceneAdded; |
| 27 | 211 | | Environment.i.world.sceneController.OnReadyScene -= NewSceneReady; |
| | 212 | |
|
| | 213 | |
|
| 27 | 214 | | if (HUDController.i.builderInWorldMainHud != null) |
| | 215 | | { |
| 27 | 216 | | HUDController.i.builderInWorldMainHud.OnTutorialAction -= StartTutorial; |
| 27 | 217 | | HUDController.i.builderInWorldMainHud.OnStartExitAction -= StartExitMode; |
| 27 | 218 | | HUDController.i.builderInWorldMainHud.OnLogoutAction -= ExitEditMode; |
| | 219 | | } |
| | 220 | |
|
| 27 | 221 | | BIWTeleportAndEdit.OnTeleportEnd -= OnPlayerTeleportedToEditScene; |
| 27 | 222 | | DCLCharacterController.OnPositionSet -= ExitAfterCharacterTeleport; |
| | 223 | |
|
| 27 | 224 | | if (initialLoadingController != null) |
| 27 | 225 | | initialLoadingController.Dispose(); |
| | 226 | |
|
| 27 | 227 | | BIWNFTController.i.OnNFTUsageChange -= OnNFTUsageChange; |
| | 228 | |
|
| 27 | 229 | | BIWNFTController.i.Dispose(); |
| 27 | 230 | | builderInWorldBridge.OnCatalogHeadersReceived -= CatalogHeadersReceived; |
| 27 | 231 | | builderInWorldBridge.OnBuilderProjectInfo -= BuilderProjectPanelInfo; |
| | 232 | |
|
| 27 | 233 | | floorHandler.OnAllParcelsFloorLoaded -= OnAllParcelsFloorLoaded; |
| | 234 | |
|
| 27 | 235 | | CleanItems(); |
| | 236 | |
|
| 27 | 237 | | HUDController.i.OnBuilderProjectPanelCreation -= InitBuilderProjectPanel; |
| 27 | 238 | | editModeChangeInputAction.OnTriggered -= ChangeEditModeStatusByShortcut; |
| | 239 | |
|
| 27 | 240 | | biwAudioHandler.Dispose(); |
| 27 | 241 | | if (biwAudioHandler.gameObject != null) |
| 27 | 242 | | GameObject.Destroy(biwAudioHandler.gameObject); |
| | 243 | |
|
| 720 | 244 | | foreach (var controller in controllers) |
| | 245 | | { |
| 333 | 246 | | controller.Dispose(); |
| | 247 | | } |
| | 248 | |
|
| 27 | 249 | | context.Dispose(); |
| 27 | 250 | | } |
| | 251 | |
|
| | 252 | | public override void OnGUI() |
| | 253 | | { |
| 1 | 254 | | base.OnGUI(); |
| 1 | 255 | | if (!isBuilderInWorldActivated) |
| 0 | 256 | | return; |
| | 257 | |
|
| 28 | 258 | | foreach (var controller in controllers) |
| | 259 | | { |
| 13 | 260 | | controller.OnGUI(); |
| | 261 | | } |
| 1 | 262 | | } |
| | 263 | |
|
| | 264 | | public override void Update() |
| | 265 | | { |
| 3 | 266 | | base.Update(); |
| | 267 | |
|
| 3 | 268 | | if (isCatalogLoading && catalogAsyncOp?.webRequest != null) |
| 0 | 269 | | UpdateCatalogLoadingProgress(catalogAsyncOp.webRequest.downloadProgress * 100); |
| | 270 | |
|
| 3 | 271 | | if (!isBuilderInWorldActivated) |
| 1 | 272 | | return; |
| | 273 | |
|
| 54 | 274 | | foreach (var controller in controllers) |
| | 275 | | { |
| 25 | 276 | | controller.Update(); |
| | 277 | | } |
| | 278 | |
|
| 2 | 279 | | if (checkerInsideSceneOptimizationCounter >= 60) |
| | 280 | | { |
| 1 | 281 | | if (Vector3.Distance(DCLCharacterController.i.characterPosition.unityPosition, parcelUnityMiddlePoint) >= DI |
| 1 | 282 | | ExitEditMode(); |
| 1 | 283 | | checkerInsideSceneOptimizationCounter = 0; |
| 1 | 284 | | } |
| | 285 | | else |
| | 286 | | { |
| 1 | 287 | | checkerInsideSceneOptimizationCounter++; |
| | 288 | | } |
| 1 | 289 | | } |
| | 290 | |
|
| | 291 | | public override void LateUpdate() |
| | 292 | | { |
| 1 | 293 | | if (!isBuilderInWorldActivated) |
| 0 | 294 | | return; |
| | 295 | |
|
| 28 | 296 | | foreach (var controller in controllers) |
| | 297 | | { |
| 13 | 298 | | controller.LateUpdate(); |
| | 299 | | } |
| 1 | 300 | | } |
| | 301 | |
|
| | 302 | | private void OnNFTUsageChange() |
| | 303 | | { |
| 0 | 304 | | HUDController.i.builderInWorldMainHud.RefreshCatalogAssetPack(); |
| 0 | 305 | | HUDController.i.builderInWorldMainHud.RefreshCatalogContent(); |
| 0 | 306 | | } |
| | 307 | |
|
| | 308 | | internal void ActivateLandAccessBackgroundChecker() |
| | 309 | | { |
| 3 | 310 | | userProfile = UserProfile.GetOwnUserProfile(); |
| 3 | 311 | | if (!string.IsNullOrEmpty(userProfile.userId)) |
| | 312 | | { |
| 3 | 313 | | if (updateLandsWithAcessCoroutine != null) |
| 0 | 314 | | CoroutineStarter.Stop(updateLandsWithAcessCoroutine); |
| 3 | 315 | | updateLandsWithAcessCoroutine = CoroutineStarter.Start(CheckLandsAccess()); |
| 3 | 316 | | } |
| | 317 | | else |
| | 318 | | { |
| 0 | 319 | | userProfile.OnUpdate += OnUserProfileUpdate; |
| | 320 | | } |
| 0 | 321 | | } |
| | 322 | |
|
| 0 | 323 | | private void BuilderProjectPanelInfo(string title, string description) { HUDController.i.builderInWorldMainHud.SetBu |
| | 324 | |
|
| | 325 | | internal void CatalogReceived(string catalogJson) |
| | 326 | | { |
| 1 | 327 | | isCatalogLoading = false; |
| 1 | 328 | | AssetCatalogBridge.i.AddFullSceneObjectCatalog(catalogJson); |
| 1 | 329 | | CatalogLoaded(); |
| 1 | 330 | | } |
| | 331 | |
|
| | 332 | | public void CatalogLoaded() |
| | 333 | | { |
| 8 | 334 | | catalogAdded = true; |
| 8 | 335 | | if (HUDController.i.builderInWorldMainHud != null) |
| 8 | 336 | | HUDController.i.builderInWorldMainHud.RefreshCatalogContent(); |
| 8 | 337 | | StartEditMode(); |
| 8 | 338 | | } |
| | 339 | |
|
| | 340 | | internal void CatalogHeadersReceived(string rawHeaders) |
| | 341 | | { |
| 1 | 342 | | catalogCallHeaders = JsonConvert.DeserializeObject<Dictionary<string, string>>(rawHeaders); |
| 1 | 343 | | areCatalogHeadersReady = true; |
| 1 | 344 | | if (isCatalogRequested) |
| 0 | 345 | | GetCatalog(); |
| 1 | 346 | | } |
| | 347 | |
|
| | 348 | | internal void GetCatalog() |
| | 349 | | { |
| 2 | 350 | | if (catalogAdded) |
| 0 | 351 | | return; |
| | 352 | |
|
| 2 | 353 | | if (areCatalogHeadersReady) |
| 0 | 354 | | catalogAsyncOp = BIWUtils.MakeGetCall(BIWUrlUtils.GetUrlCatalog(), CatalogReceived, catalogCallHeaders); |
| | 355 | | else |
| 2 | 356 | | builderInWorldBridge.AskKernelForCatalogHeaders(); |
| | 357 | |
|
| 2 | 358 | | isCatalogRequested = true; |
| 2 | 359 | | } |
| | 360 | |
|
| | 361 | | private void ConfigureLoadingController() |
| | 362 | | { |
| 26 | 363 | | initialLoadingController = new BuilderInWorldLoadingController(); |
| 26 | 364 | | initialLoadingController.Initialize(); |
| 26 | 365 | | } |
| | 366 | |
|
| | 367 | | private void InitControllers() |
| | 368 | | { |
| 26 | 369 | | InitController(entityHandler); |
| 26 | 370 | | InitController(modeController); |
| 26 | 371 | | InitController(publishController); |
| 26 | 372 | | InitController(creatorController); |
| 26 | 373 | | InitController(outlinerController); |
| 26 | 374 | | InitController(floorHandler); |
| 26 | 375 | | InitController(inputHandler); |
| 26 | 376 | | InitController(saveController); |
| 26 | 377 | | InitController(actionController); |
| 26 | 378 | | InitController(inputWrapper); |
| 26 | 379 | | InitController(raycastController); |
| 26 | 380 | | InitController(gizmosController); |
| 26 | 381 | | } |
| | 382 | |
|
| | 383 | | public void InitController(IBIWController controller) |
| | 384 | | { |
| 320 | 385 | | controller.Init(context); |
| 320 | 386 | | controllers.Add(controller); |
| 320 | 387 | | } |
| | 388 | |
|
| 0 | 389 | | private void StartTutorial() { TutorialController.i.SetBuilderInWorldTutorialEnabled(); } |
| | 390 | |
|
| | 391 | | public void CleanItems() |
| | 392 | | { |
| 27 | 393 | | if (HUDController.i.builderInWorldMainHud != null) |
| 27 | 394 | | HUDController.i.builderInWorldMainHud.Dispose(); |
| | 395 | |
|
| 27 | 396 | | if (Camera.main != null) |
| | 397 | | { |
| 27 | 398 | | BIWOutline outliner = Camera.main.GetComponent<BIWOutline>(); |
| 27 | 399 | | GameObject.Destroy(outliner); |
| | 400 | | } |
| | 401 | |
|
| 27 | 402 | | floorHandler?.Clean(); |
| 27 | 403 | | creatorController?.Clean(); |
| 27 | 404 | | } |
| | 405 | |
|
| | 406 | | public void ChangeEditModeStatusByShortcut(DCLAction_Trigger action) |
| | 407 | | { |
| 1 | 408 | | if (!activeFeature) |
| 0 | 409 | | return; |
| | 410 | |
|
| 1 | 411 | | if (isEnteringEditMode) |
| 0 | 412 | | return; |
| | 413 | |
|
| 1 | 414 | | if (isBuilderInWorldActivated) |
| | 415 | | { |
| 0 | 416 | | HUDController.i.builderInWorldMainHud.ExitStart(); |
| 0 | 417 | | return; |
| | 418 | | } |
| | 419 | |
|
| 1 | 420 | | if (DataStore.i.builderInWorld.landsWithAccess.Get().Length == 0 && !alreadyAskedForLandPermissions) |
| | 421 | | { |
| 1 | 422 | | ActivateLandAccessBackgroundChecker(); |
| 1 | 423 | | ShowGenericNotification(BIWSettings.LAND_EDITION_WAITING_FOR_PERMISSIONS_MESSAGE, NotificationFactory.Type.G |
| 1 | 424 | | isWaitingForPermission = true; |
| 1 | 425 | | askPermissionLastPosition = DCLCharacterController.i.characterPosition.unityPosition; |
| 1 | 426 | | } |
| | 427 | | else |
| | 428 | | { |
| 0 | 429 | | CheckSceneToEditByShorcut(); |
| | 430 | | } |
| 0 | 431 | | } |
| | 432 | |
|
| | 433 | | internal void CheckSceneToEditByShorcut() |
| | 434 | | { |
| 2 | 435 | | FindSceneToEdit(); |
| | 436 | |
|
| 2 | 437 | | if (!UserHasPermissionOnParcelScene(sceneToEdit)) |
| | 438 | | { |
| 1 | 439 | | ShowGenericNotification(BIWSettings.LAND_EDITION_NOT_ALLOWED_BY_PERMISSIONS_MESSAGE); |
| 1 | 440 | | return; |
| | 441 | | } |
| 1 | 442 | | if (IsParcelSceneDeployedFromSDK(sceneToEdit)) |
| | 443 | | { |
| 0 | 444 | | ShowGenericNotification(BIWSettings.LAND_EDITION_NOT_ALLOWED_BY_SDK_LIMITATION_MESSAGE); |
| 0 | 445 | | return; |
| | 446 | | } |
| | 447 | |
|
| 1 | 448 | | GetCatalog(); |
| 1 | 449 | | TryStartEnterEditMode(true, null, "Shortcut"); |
| 1 | 450 | | } |
| | 451 | |
|
| | 452 | | internal void NewSceneAdded(IParcelScene newScene) |
| | 453 | | { |
| 1 | 454 | | if (newScene.sceneData.id != sceneToEditId) |
| 0 | 455 | | return; |
| | 456 | |
|
| 1 | 457 | | Environment.i.world.sceneController.OnNewSceneAdded -= NewSceneAdded; |
| | 458 | |
|
| 1 | 459 | | sceneToEdit = (ParcelScene)Environment.i.world.state.GetScene(sceneToEditId); |
| 1 | 460 | | sceneToEdit.metricsController = new BIWSceneMetricsController(sceneToEdit); |
| 1 | 461 | | sceneToEdit.OnLoadingStateUpdated += UpdateSceneLoadingProgress; |
| 1 | 462 | | } |
| | 463 | |
|
| | 464 | | private void NewSceneReady(string id) |
| | 465 | | { |
| 7 | 466 | | if (sceneToEditId != id) |
| 0 | 467 | | return; |
| | 468 | |
|
| 7 | 469 | | sceneToEdit.OnLoadingStateUpdated -= UpdateSceneLoadingProgress; |
| 7 | 470 | | Environment.i.world.sceneController.OnReadyScene -= NewSceneReady; |
| 7 | 471 | | sceneToEditId = null; |
| 7 | 472 | | sceneReady = true; |
| 7 | 473 | | CheckEnterEditMode(); |
| 7 | 474 | | } |
| | 475 | |
|
| | 476 | | internal bool UserHasPermissionOnParcelScene(ParcelScene sceneToCheck) |
| | 477 | | { |
| 11 | 478 | | if (BYPASS_LAND_OWNERSHIP_CHECK) |
| 10 | 479 | | return true; |
| | 480 | |
|
| 1 | 481 | | List<Vector2Int> allParcelsWithAccess = DataStore.i.builderInWorld.landsWithAccess.Get().SelectMany(land => land |
| 2 | 482 | | foreach (Vector2Int parcel in allParcelsWithAccess) |
| | 483 | | { |
| 0 | 484 | | if (sceneToCheck.sceneData.parcels.Any(currentParcel => currentParcel.x == parcel.x && currentParcel.y == pa |
| 0 | 485 | | return true; |
| | 486 | | } |
| | 487 | |
|
| 1 | 488 | | return false; |
| 0 | 489 | | } |
| | 490 | |
|
| | 491 | | internal bool IsParcelSceneDeployedFromSDK(ParcelScene sceneToCheck) |
| | 492 | | { |
| 13 | 493 | | List<DeployedScene> allDeployedScenesWithAccess = DataStore.i.builderInWorld.landsWithAccess.Get().SelectMany(la |
| 21 | 494 | | foreach (DeployedScene scene in allDeployedScenesWithAccess) |
| | 495 | | { |
| 1 | 496 | | if (scene.source != DeployedScene.Source.SDK) |
| | 497 | | continue; |
| | 498 | |
|
| 1 | 499 | | List<Vector2Int> parcelsDeployedFromSDK = scene.parcels.ToList(); |
| 3 | 500 | | foreach (Vector2Int parcel in parcelsDeployedFromSDK) |
| | 501 | | { |
| 2 | 502 | | if (sceneToCheck.sceneData.parcels.Any(currentParcel => currentParcel.x == parcel.x && currentParcel.y = |
| 1 | 503 | | return true; |
| | 504 | | } |
| | 505 | | } |
| | 506 | |
|
| 9 | 507 | | return false; |
| 1 | 508 | | } |
| | 509 | |
|
| | 510 | | private void CheckEnterEditMode() |
| | 511 | | { |
| 7 | 512 | | if (catalogAdded && sceneReady) |
| 7 | 513 | | EnterEditMode(); |
| 7 | 514 | | } |
| | 515 | |
|
| 0 | 516 | | public void TryStartEnterEditMode() { TryStartEnterEditMode(true, null); } |
| | 517 | |
|
| 0 | 518 | | public void TryStartEnterEditMode(IParcelScene targetScene) { TryStartEnterEditMode(true, targetScene); } |
| | 519 | |
|
| | 520 | | public void TryStartEnterEditMode(bool activateCamera, IParcelScene targetScene = null , string source = "BuilderPan |
| | 521 | | { |
| 8 | 522 | | if (sceneToEditId != null) |
| 0 | 523 | | return; |
| | 524 | |
|
| 8 | 525 | | FindSceneToEdit(targetScene); |
| | 526 | |
|
| 8 | 527 | | if (!UserHasPermissionOnParcelScene(sceneToEdit)) |
| | 528 | | { |
| 0 | 529 | | ShowGenericNotification(BIWSettings.LAND_EDITION_NOT_ALLOWED_BY_PERMISSIONS_MESSAGE); |
| 0 | 530 | | return; |
| | 531 | | } |
| 8 | 532 | | else if (IsParcelSceneDeployedFromSDK(sceneToEdit)) |
| | 533 | | { |
| 0 | 534 | | ShowGenericNotification(BIWSettings.LAND_EDITION_NOT_ALLOWED_BY_SDK_LIMITATION_MESSAGE); |
| 0 | 535 | | return; |
| | 536 | | } |
| | 537 | |
|
| | 538 | | //If the scene is still not loaded, we return as we still can't enter in builder in world |
| 8 | 539 | | if (sceneToEditId != null) |
| 0 | 540 | | return; |
| | 541 | |
|
| 8 | 542 | | isEnteringEditMode = true; |
| 8 | 543 | | previousAllUIHidden = CommonScriptableObjects.allUIHidden.Get(); |
| 8 | 544 | | NotificationsController.i.allowNotifications = false; |
| 8 | 545 | | CommonScriptableObjects.allUIHidden.Set(true); |
| 8 | 546 | | NotificationsController.i.allowNotifications = true; |
| 8 | 547 | | inputController.inputTypeMode = InputTypeMode.BUILD_MODE_LOADING; |
| 8 | 548 | | initialLoadingController.Show(); |
| 8 | 549 | | initialLoadingController.SetPercentage(0f); |
| 8 | 550 | | DataStore.i.appMode.Set(AppMode.BUILDER_IN_WORLD_EDITION); |
| 8 | 551 | | DataStore.i.virtualAudioMixer.sceneSFXVolume.Set(0f); |
| 8 | 552 | | BIWAnalytics.StartEditorFlow(source); |
| 8 | 553 | | beginStartFlowTimeStamp = Time.realtimeSinceStartup; |
| | 554 | |
|
| 8 | 555 | | biwAudioHandler.gameObject.SetActive(true); |
| | 556 | | //Note (Adrian) this should handle different when we have the full flow of the feature |
| 8 | 557 | | if (activateCamera) |
| 1 | 558 | | modeController.ActivateCamera(sceneToEdit); |
| | 559 | |
|
| 8 | 560 | | if (catalogAdded) |
| 7 | 561 | | StartEditMode(); |
| 8 | 562 | | } |
| | 563 | |
|
| | 564 | | private void StartEditMode() |
| | 565 | | { |
| 15 | 566 | | if (sceneToEdit == null) |
| 8 | 567 | | return; |
| | 568 | |
|
| 7 | 569 | | isEnteringEditMode = true; |
| | 570 | |
|
| 7 | 571 | | Environment.i.platform.cullingController.Stop(); |
| | 572 | |
|
| 7 | 573 | | sceneToEditId = sceneToEdit.sceneData.id; |
| | 574 | |
|
| | 575 | | // In this point we're sure that the catalog loading (the first half of our progress bar) has already finished |
| 7 | 576 | | initialLoadingController.SetPercentage(50f); |
| 7 | 577 | | Environment.i.world.sceneController.OnNewSceneAdded += NewSceneAdded; |
| 7 | 578 | | Environment.i.world.sceneController.OnReadyScene += NewSceneReady; |
| 7 | 579 | | Environment.i.world.blockersController.SetEnabled(false); |
| | 580 | |
|
| 7 | 581 | | builderInWorldBridge.StartKernelEditMode(sceneToEdit); |
| 7 | 582 | | } |
| | 583 | |
|
| | 584 | | private void EnterEditMode() |
| | 585 | | { |
| 7 | 586 | | if (!initialLoadingController.isActive) |
| 0 | 587 | | return; |
| | 588 | |
|
| 7 | 589 | | isEnteringEditMode = false; |
| 7 | 590 | | BIWNFTController.i.ClearNFTs(); |
| | 591 | |
|
| 7 | 592 | | ParcelSettings.VISUAL_LOADING_ENABLED = false; |
| | 593 | |
|
| 7 | 594 | | sceneToEdit.SetEditMode(true); |
| 7 | 595 | | cursorGO.SetActive(false); |
| 7 | 596 | | parcelUnityMiddlePoint = BIWUtils.CalculateUnityMiddlePoint(sceneToEdit); |
| | 597 | |
|
| 7 | 598 | | if (HUDController.i.builderInWorldMainHud != null) |
| | 599 | | { |
| 7 | 600 | | HUDController.i.builderInWorldMainHud.SetParcelScene(sceneToEdit); |
| 7 | 601 | | HUDController.i.builderInWorldMainHud.RefreshCatalogContent(); |
| 7 | 602 | | HUDController.i.builderInWorldMainHud.RefreshCatalogAssetPack(); |
| 7 | 603 | | HUDController.i.builderInWorldMainHud.SetVisibilityOfCatalog(true); |
| 7 | 604 | | HUDController.i.builderInWorldMainHud.SetVisibilityOfInspector(true); |
| | 605 | | } |
| | 606 | |
|
| 7 | 607 | | CommonScriptableObjects.builderInWorldNotNecessaryUIVisibilityStatus.Set(false); |
| 7 | 608 | | DataStore.i.builderInWorld.showTaskBar.Set(true); |
| | 609 | |
|
| 7 | 610 | | DCLCharacterController.OnPositionSet += ExitAfterCharacterTeleport; |
| | 611 | |
|
| 7 | 612 | | EnterBiwControllers(); |
| 7 | 613 | | Environment.i.world.sceneController.ActivateBuilderInWorldEditScene(); |
| | 614 | |
|
| 7 | 615 | | initialLoadingController.SetPercentage(100f); |
| | 616 | |
|
| 7 | 617 | | if (IsNewScene()) |
| | 618 | | { |
| 0 | 619 | | floorHandler.OnAllParcelsFloorLoaded -= OnAllParcelsFloorLoaded; |
| 0 | 620 | | floorHandler.OnAllParcelsFloorLoaded += OnAllParcelsFloorLoaded; |
| 0 | 621 | | SetupNewScene(); |
| 0 | 622 | | } |
| | 623 | | else |
| | 624 | | { |
| 7 | 625 | | initialLoadingController.Hide(onHideAction: () => |
| | 626 | | { |
| 0 | 627 | | inputController.inputTypeMode = InputTypeMode.BUILD_MODE; |
| 0 | 628 | | HUDController.i.builderInWorldMainHud?.SetVisibility(true); |
| 0 | 629 | | CommonScriptableObjects.allUIHidden.Set(previousAllUIHidden); |
| 0 | 630 | | OpenNewProjectDetailsIfNeeded(); |
| 0 | 631 | | }); |
| | 632 | | } |
| | 633 | |
|
| 7 | 634 | | isBuilderInWorldActivated = true; |
| | 635 | |
|
| 7 | 636 | | previousSkyBoxMaterial = RenderSettings.skybox; |
| 7 | 637 | | RenderSettings.skybox = skyBoxMaterial; |
| | 638 | |
|
| 14 | 639 | | foreach (var groundVisual in groundVisualsGO) |
| | 640 | | { |
| 0 | 641 | | groundVisual.SetActive(false); |
| | 642 | | } |
| 7 | 643 | | startEditorTimeStamp = Time.realtimeSinceStartup; |
| | 644 | |
|
| 7 | 645 | | BIWAnalytics.AddSceneInfo(sceneToEdit.sceneData.basePosition, BIWUtils.GetLandOwnershipType(DataStore.i.builderI |
| 7 | 646 | | BIWAnalytics.EnterEditor( Time.realtimeSinceStartup - beginStartFlowTimeStamp); |
| 7 | 647 | | } |
| | 648 | |
|
| | 649 | | internal void OnAllParcelsFloorLoaded() |
| | 650 | | { |
| 1 | 651 | | if (!initialLoadingController.isActive) |
| 0 | 652 | | return; |
| | 653 | |
|
| 1 | 654 | | floorHandler.OnAllParcelsFloorLoaded -= OnAllParcelsFloorLoaded; |
| 1 | 655 | | initialLoadingController.Hide(onHideAction: () => |
| | 656 | | { |
| 0 | 657 | | inputController.inputTypeMode = InputTypeMode.BUILD_MODE; |
| 0 | 658 | | HUDController.i.builderInWorldMainHud.SetVisibility(true); |
| 0 | 659 | | CommonScriptableObjects.allUIHidden.Set(previousAllUIHidden); |
| 0 | 660 | | OpenNewProjectDetailsIfNeeded(); |
| 0 | 661 | | }); |
| 1 | 662 | | } |
| | 663 | |
|
| | 664 | | private void OpenNewProjectDetailsIfNeeded() |
| | 665 | | { |
| 0 | 666 | | if (builderInWorldBridge.builderProject.isNewEmptyProject) |
| 0 | 667 | | modeController.OpenNewProjectDetails(); |
| 0 | 668 | | } |
| | 669 | |
|
| | 670 | | public void StartExitMode() |
| | 671 | | { |
| 1 | 672 | | if (saveController.GetSaveTimes() > 0) |
| | 673 | | { |
| 1 | 674 | | modeController.TakeSceneScreenshotForExit(); |
| | 675 | |
|
| 1 | 676 | | if ( HUDController.i.builderInWorldMainHud != null) |
| 1 | 677 | | HUDController.i.builderInWorldMainHud.ConfigureConfirmationModal( |
| | 678 | | BIWSettings.EXIT_MODAL_TITLE, |
| | 679 | | BIWSettings.EXIT_WITHOUT_PUBLISH_MODAL_SUBTITLE, |
| | 680 | | BIWSettings.EXIT_WITHOUT_PUBLISH_MODAL_CANCEL_BUTTON, |
| | 681 | | BIWSettings.EXIT_WITHOUT_PUBLISH_MODAL_CONFIRM_BUTTON); |
| 1 | 682 | | } |
| | 683 | | else |
| | 684 | | { |
| 0 | 685 | | HUDController.i.builderInWorldMainHud.ConfigureConfirmationModal( |
| | 686 | | BIWSettings.EXIT_MODAL_TITLE, |
| | 687 | | BIWSettings.EXIT_MODAL_SUBTITLE, |
| | 688 | | BIWSettings.EXIT_MODAL_CANCEL_BUTTON, |
| | 689 | | BIWSettings.EXIT_MODAL_CONFIRM_BUTTON); |
| | 690 | | } |
| 0 | 691 | | } |
| | 692 | |
|
| | 693 | | public void ExitEditMode() |
| | 694 | | { |
| 4 | 695 | | Environment.i.platform.cullingController.Start(); |
| | 696 | |
|
| 4 | 697 | | floorHandler.OnAllParcelsFloorLoaded -= OnAllParcelsFloorLoaded; |
| 4 | 698 | | initialLoadingController.Hide(true); |
| 4 | 699 | | inputController.inputTypeMode = InputTypeMode.GENERAL; |
| | 700 | |
|
| 4 | 701 | | CommonScriptableObjects.builderInWorldNotNecessaryUIVisibilityStatus.Set(true); |
| 4 | 702 | | DataStore.i.builderInWorld.showTaskBar.Set(true); |
| | 703 | |
|
| 4 | 704 | | ParcelSettings.VISUAL_LOADING_ENABLED = true; |
| | 705 | |
|
| 4 | 706 | | outlinerController.CancelAllOutlines(); |
| | 707 | |
|
| 4 | 708 | | cursorGO.SetActive(true); |
| | 709 | |
|
| 4 | 710 | | if (sceneToEdit != null) |
| 4 | 711 | | sceneToEdit.SetEditMode(false); |
| | 712 | |
|
| 4 | 713 | | DCLCharacterController.OnPositionSet -= ExitAfterCharacterTeleport; |
| | 714 | |
|
| 4 | 715 | | InmediateExit(); |
| | 716 | |
|
| 4 | 717 | | if (HUDController.i.builderInWorldMainHud != null) |
| | 718 | | { |
| 4 | 719 | | HUDController.i.builderInWorldMainHud.ClearEntityList(); |
| 4 | 720 | | HUDController.i.builderInWorldMainHud.SetVisibility(false); |
| | 721 | | } |
| | 722 | |
|
| 4 | 723 | | Environment.i.world.sceneController.DeactivateBuilderInWorldEditScene(); |
| 4 | 724 | | Environment.i.world.blockersController.SetEnabled(true); |
| | 725 | |
|
| 4 | 726 | | ExitBiwControllers(); |
| | 727 | |
|
| 8 | 728 | | foreach (var groundVisual in groundVisualsGO) |
| | 729 | | { |
| 0 | 730 | | groundVisual.SetActive(true); |
| | 731 | | } |
| | 732 | |
|
| 4 | 733 | | isBuilderInWorldActivated = false; |
| 4 | 734 | | RenderSettings.skybox = previousSkyBoxMaterial; |
| | 735 | |
|
| 4 | 736 | | biwAudioHandler.gameObject.SetActive(false); |
| 4 | 737 | | DataStore.i.appMode.Set(AppMode.DEFAULT); |
| 4 | 738 | | DataStore.i.virtualAudioMixer.sceneSFXVolume.Set(1f); |
| 4 | 739 | | BIWAnalytics.ExitEditor(Time.realtimeSinceStartup - startEditorTimeStamp); |
| 4 | 740 | | } |
| | 741 | |
|
| | 742 | | public void InmediateExit() |
| | 743 | | { |
| 4 | 744 | | CommonScriptableObjects.allUIHidden.Set(previousAllUIHidden); |
| 4 | 745 | | builderInWorldBridge.ExitKernelEditMode(sceneToEdit); |
| 4 | 746 | | } |
| | 747 | |
|
| | 748 | | public void EnterBiwControllers() |
| | 749 | | { |
| 192 | 750 | | foreach (var controller in controllers) |
| | 751 | | { |
| 89 | 752 | | controller.EnterEditMode(sceneToEdit); |
| | 753 | | } |
| | 754 | | //Note: This audio should inside the controllers, it is here because it is still a monobehaviour |
| 7 | 755 | | biwAudioHandler.EnterEditMode(sceneToEdit); |
| 7 | 756 | | } |
| | 757 | |
|
| | 758 | | public void ExitBiwControllers() |
| | 759 | | { |
| 106 | 760 | | foreach (var controller in controllers) |
| | 761 | | { |
| 49 | 762 | | controller.ExitEditMode(); |
| | 763 | | } |
| | 764 | |
|
| 4 | 765 | | biwAudioHandler.ExitEditMode(); |
| 4 | 766 | | } |
| | 767 | |
|
| 7 | 768 | | public bool IsNewScene() { return sceneToEdit.entities.Count <= 0; } |
| | 769 | |
|
| 2 | 770 | | public void SetupNewScene() { floorHandler.CreateDefaultFloor(); } |
| | 771 | |
|
| 2 | 772 | | internal void ExitAfterCharacterTeleport(DCLCharacterPosition position) { ExitEditMode(); } |
| | 773 | |
|
| | 774 | | public void FindSceneToEdit(IParcelScene targetScene) |
| | 775 | | { |
| 8 | 776 | | if (targetScene != null) |
| | 777 | | { |
| 7 | 778 | | var parcelSceneTarget = (ParcelScene)targetScene; |
| 7 | 779 | | if (sceneToEdit != null && sceneToEdit != parcelSceneTarget) |
| 0 | 780 | | actionController.Clear(); |
| | 781 | |
|
| 7 | 782 | | sceneToEdit = parcelSceneTarget; |
| 7 | 783 | | } |
| | 784 | | else |
| | 785 | | { |
| 1 | 786 | | FindSceneToEdit(); |
| | 787 | | } |
| 1 | 788 | | } |
| | 789 | |
|
| | 790 | | public IParcelScene FindSceneToEdit() |
| | 791 | | { |
| 15 | 792 | | foreach (IParcelScene scene in Environment.i.world.state.scenesSortedByDistance) |
| | 793 | | { |
| 4 | 794 | | if (WorldStateUtils.IsCharacterInsideScene(scene)) |
| | 795 | | { |
| 1 | 796 | | ParcelScene parcelScene = (ParcelScene)scene; |
| | 797 | |
|
| 1 | 798 | | if (sceneToEdit != null && sceneToEdit != parcelScene) |
| 0 | 799 | | actionController.Clear(); |
| | 800 | |
|
| 1 | 801 | | sceneToEdit = parcelScene; |
| 1 | 802 | | return sceneToEdit; |
| | 803 | | } |
| | 804 | | } |
| 3 | 805 | | return null; |
| 1 | 806 | | } |
| | 807 | |
|
| | 808 | | private void OnPlayerTeleportedToEditScene(Vector2Int coords) |
| | 809 | | { |
| 0 | 810 | | if (activeFeature) |
| | 811 | | { |
| 0 | 812 | | var targetScene = Environment.i.world.state.scenesSortedByDistance |
| 0 | 813 | | .FirstOrDefault(scene => scene.sceneData.parcels.Contains(coords)); |
| 0 | 814 | | TryStartEnterEditMode(targetScene); |
| | 815 | | } |
| 0 | 816 | | } |
| | 817 | |
|
| 0 | 818 | | private void UpdateCatalogLoadingProgress(float catalogLoadingProgress) { initialLoadingController.SetPercentage(cat |
| | 819 | |
|
| 0 | 820 | | private void UpdateSceneLoadingProgress(float sceneLoadingProgress) { initialLoadingController.SetPercentage(50f + ( |
| | 821 | |
|
| | 822 | | internal void OnUserProfileUpdate(UserProfile user) |
| | 823 | | { |
| 1 | 824 | | userProfile.OnUpdate -= OnUserProfileUpdate; |
| 1 | 825 | | updateLandsWithAcessCoroutine = CoroutineStarter.Start(CheckLandsAccess()); |
| 1 | 826 | | } |
| | 827 | |
|
| | 828 | | private IEnumerator CheckLandsAccess() |
| | 829 | | { |
| 0 | 830 | | while (true) |
| | 831 | | { |
| 4 | 832 | | UpdateLandsWithAccess(); |
| 4 | 833 | | yield return WaitForSecondsCache.Get(BIWSettings.REFRESH_LANDS_WITH_ACCESS_INTERVAL); |
| | 834 | | } |
| | 835 | | } |
| | 836 | |
|
| | 837 | | private void UpdateLandsWithAccess() |
| | 838 | | { |
| 4 | 839 | | if (isBuilderInWorldActivated) |
| 0 | 840 | | return; |
| | 841 | |
|
| 4 | 842 | | DeployedScenesFetcher.FetchLandsFromOwner( |
| | 843 | | Environment.i.platform.serviceProviders.catalyst, |
| | 844 | | Environment.i.platform.serviceProviders.theGraph, |
| | 845 | | userProfile.ethAddress, |
| | 846 | | KernelConfig.i.Get().network, |
| | 847 | | BIWSettings.CACHE_TIME_LAND, |
| | 848 | | BIWSettings.CACHE_TIME_SCENES) |
| | 849 | | .Then(lands => |
| | 850 | | { |
| 4 | 851 | | DataStore.i.builderInWorld.landsWithAccess.Set(lands.ToArray(), true); |
| 4 | 852 | | if (isWaitingForPermission && Vector3.Distance(askPermissionLastPosition, DCLCharacterC |
| | 853 | | { |
| 1 | 854 | | CheckSceneToEditByShorcut(); |
| | 855 | | } |
| 4 | 856 | | isWaitingForPermission = false; |
| 4 | 857 | | alreadyAskedForLandPermissions = true; |
| 4 | 858 | | }); |
| 4 | 859 | | } |
| | 860 | |
|
| | 861 | | private static void ShowGenericNotification(string message, NotificationFactory.Type type = NotificationFactory.Type |
| | 862 | | { |
| 2 | 863 | | Notification.Model notificationModel = new Notification.Model(); |
| 2 | 864 | | notificationModel.message = message; |
| 2 | 865 | | notificationModel.type = type; |
| 2 | 866 | | notificationModel.timer = timer; |
| 2 | 867 | | if (HUDController.i.notificationHud != null) |
| 0 | 868 | | HUDController.i.notificationHud.ShowNotification(notificationModel); |
| 2 | 869 | | } |
| | 870 | | } |