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