< Summary

Class:BuilderInWorldEditor
Assembly:BuilderInWorld
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Scripts/BuilderInWorldEditor.cs
Covered lines:145
Uncovered lines:13
Coverable lines:158
Total lines:313
Line coverage:91.7% (145 of 158)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
BuilderInWorldEditor()0%110100%
Initialize(...)0%33093.33%
InitReferences(...)0%3.433063.64%
InitHUD(...)0%110100%
Dispose()0%330100%
OnGUI()0%3.033085.71%
Update()0%330100%
LateUpdate()0%3.033085.71%
OnNFTUsageChange()0%2100%
BuilderProjectPanelInfo(...)0%2100%
InitControllers()0%110100%
InitController(...)0%110100%
StartTutorial()0%2100%
CleanItems()0%550100%
EnterEditMode(...)0%6.016092.86%
ExitEditMode()0%4.014092.31%
InmediateExit()0%110100%
EnterBiwControllers()0%220100%
ExitBiwControllers()0%330100%
IsNewScene()0%110100%
SetupNewScene()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Scripts/BuilderInWorldEditor.cs

#LineLine coverage
 1using DCL;
 2using DCL.Configuration;
 3using DCL.Controllers;
 4using DCL.Tutorial;
 5using Newtonsoft.Json;
 6using System.Collections;
 7using System.Collections.Generic;
 8using System.Linq;
 9using DCL.Builder;
 10using UnityEngine;
 11using Environment = DCL.Environment;
 12
 13public class BuilderInWorldEditor : IBIWEditor
 14{
 15    private GameObject cursorGO;
 16    private GameObject[] groundVisualsGO;
 17
 918    internal IBIWOutlinerController outlinerController => context.editorContext.outlinerController;
 819    internal IBIWInputHandler inputHandler => context.editorContext.inputHandler;
 820    internal IBIWPublishController publishController => context.editorContext.publishController;
 1621    internal IBIWCreatorController creatorController => context.editorContext.creatorController;
 822    internal IBIWModeController modeController => context.editorContext.modeController;
 2223    internal IBIWFloorHandler floorHandler => context.editorContext.floorHandler;
 824    internal IBIWEntityHandler entityHandler => context.editorContext.entityHandler;
 825    internal IBIWActionController actionController => context.editorContext.actionController;
 826    internal IBIWSaveController saveController => context.editorContext.saveController;
 827    internal IBIWInputWrapper inputWrapper => context.editorContext.inputWrapper;
 828    internal IBIWRaycastController raycastController => context.editorContext.raycastController;
 829    internal IBIWGizmosController gizmosController => context.editorContext.gizmosController;
 30
 31    private BuilderInWorldBridge builderInWorldBridge;
 32    private BuilderInWorldAudioHandler biwAudioHandler;
 33    internal IContext context;
 34
 835    private readonly List<IBIWController> controllers = new List<IBIWController>();
 36    private Material skyBoxMaterial;
 37
 038    public bool isBuilderInWorldActivated { get; internal set; } = false;
 39
 40    private bool isInit = false;
 41    private Material previousSkyBoxMaterial;
 42
 43    private float startEditorTimeStamp = 0;
 44    internal IParcelScene sceneToEdit;
 45
 46    public void Initialize(IContext context)
 47    {
 848        if (isInit)
 049            return;
 50
 851        isInit = true;
 52
 853        this.context = context;
 54
 855        InitReferences(SceneReferences.i);
 56
 857        if (builderInWorldBridge != null)
 858            builderInWorldBridge.OnBuilderProjectInfo += BuilderProjectPanelInfo;
 59
 860        BIWNFTController.i.OnNFTUsageChange += OnNFTUsageChange;
 61
 862        InitHUD(context);
 63
 864        InitControllers();
 65
 866        CommonScriptableObjects.builderInWorldNotNecessaryUIVisibilityStatus.Set(true);
 67
 868        biwAudioHandler = UnityEngine.Object.Instantiate(context.projectReferencesAsset.audioPrefab, Vector3.zero, Quate
 869        biwAudioHandler.Initialize(context);
 870        biwAudioHandler.gameObject.SetActive(false);
 871    }
 72
 73    public void InitReferences(SceneReferences sceneReferences)
 74    {
 875        builderInWorldBridge = sceneReferences.biwBridgeGameObject.GetComponent<BuilderInWorldBridge>();
 876        cursorGO = sceneReferences.cursorCanvas;
 77
 878        List<GameObject> grounds = new List<GameObject>();
 79
 880        if (sceneReferences.groundVisual != null)
 81        {
 082            for (int i = 0; i < sceneReferences.groundVisual.transform.transform.childCount; i++)
 83            {
 084                grounds.Add(sceneReferences.groundVisual.transform.transform.GetChild(i).gameObject);
 85            }
 86        }
 87
 888        groundVisualsGO = grounds.ToArray();
 889        skyBoxMaterial = context.projectReferencesAsset.skyBoxMaterial;
 890    }
 91
 92    private void InitHUD(IContext context)
 93    {
 894        context.editorContext.editorHUD.Initialize(context);
 895        context.editorContext.editorHUD.OnTutorialAction += StartTutorial;
 896    }
 97
 98    public void Dispose()
 99    {
 8100        if (context.editorContext.editorHUD != null)
 8101            context.editorContext.editorHUD.OnTutorialAction -= StartTutorial;
 102
 103
 8104        BIWNFTController.i.OnNFTUsageChange -= OnNFTUsageChange;
 105
 8106        BIWNFTController.i.Dispose();
 8107        builderInWorldBridge.OnBuilderProjectInfo -= BuilderProjectPanelInfo;
 108
 8109        CleanItems();
 110
 8111        if (biwAudioHandler.gameObject != null)
 112        {
 8113            biwAudioHandler.Dispose();
 8114            UnityEngine.Object.Destroy(biwAudioHandler.gameObject);
 115        }
 8116    }
 117
 118    public void OnGUI()
 119    {
 1120        if (!isBuilderInWorldActivated)
 0121            return;
 122
 28123        foreach (var controller in controllers)
 124        {
 13125            controller.OnGUI();
 126        }
 1127    }
 128
 129    public void Update()
 130    {
 2131        if (!isBuilderInWorldActivated)
 1132            return;
 133
 28134        foreach (var controller in controllers)
 135        {
 13136            controller.Update();
 137        }
 1138    }
 139
 140    public void LateUpdate()
 141    {
 1142        if (!isBuilderInWorldActivated)
 0143            return;
 144
 28145        foreach (var controller in controllers)
 146        {
 13147            controller.LateUpdate();
 148        }
 1149    }
 150
 151    private void OnNFTUsageChange()
 152    {
 0153        context.editorContext.editorHUD.RefreshCatalogAssetPack();
 0154        context.editorContext.editorHUD.RefreshCatalogContent();
 0155    }
 156
 0157    private void BuilderProjectPanelInfo(string title, string description) {  context.editorContext.editorHUD.SetBuilder
 158
 159    private void InitControllers()
 160    {
 8161        InitController(entityHandler);
 8162        InitController(modeController);
 8163        InitController(publishController);
 8164        InitController(creatorController);
 8165        InitController(outlinerController);
 8166        InitController(floorHandler);
 8167        InitController(inputHandler);
 8168        InitController(saveController);
 8169        InitController(actionController);
 8170        InitController(inputWrapper);
 8171        InitController(raycastController);
 8172        InitController(gizmosController);
 8173    }
 174
 175    public void InitController(IBIWController controller)
 176    {
 103177        controller.Initialize(context);
 103178        controllers.Add(controller);
 103179    }
 180
 0181    private void StartTutorial() { TutorialController.i.SetBuilderInWorldTutorialEnabled(); }
 182
 183    public void CleanItems()
 184    {
 8185        if ( context.editorContext.editorHUD != null)
 8186            context.editorContext.editorHUD.Dispose();
 187
 8188        Camera camera = Camera.main;
 189
 8190        if (camera != null)
 191        {
 8192            BIWOutline outliner = camera.GetComponent<BIWOutline>();
 8193            UnityEngine.Object.Destroy(outliner);
 194        }
 195
 8196        floorHandler?.CleanUp();
 8197        creatorController?.CleanUp();
 8198    }
 199
 200    public void EnterEditMode(IParcelScene sceneToEdit)
 201    {
 5202        this.sceneToEdit = sceneToEdit;
 203
 5204        BIWNFTController.i.StartEditMode();
 5205        if (biwAudioHandler != null && biwAudioHandler.gameObject != null)
 5206            biwAudioHandler.gameObject.SetActive(true);
 207
 5208        ParcelSettings.VISUAL_LOADING_ENABLED = false;
 5209        cursorGO.SetActive(false);
 210
 5211        if ( context.editorContext.editorHUD != null)
 212        {
 5213            context.editorContext.editorHUD.SetParcelScene(sceneToEdit);
 5214            context.editorContext.editorHUD.RefreshCatalogContent();
 5215            context.editorContext.editorHUD.RefreshCatalogAssetPack();
 5216            context.editorContext.editorHUD.SetVisibilityOfCatalog(true);
 5217            context.editorContext.editorHUD.SetVisibilityOfInspector(true);
 218        }
 219
 5220        CommonScriptableObjects.builderInWorldNotNecessaryUIVisibilityStatus.Set(false);
 5221        DataStore.i.builderInWorld.showTaskBar.Set(true);
 222
 5223        EnterBiwControllers();
 5224        Environment.i.world.sceneController.ActivateBuilderInWorldEditScene();
 225
 5226        if (IsNewScene())
 5227            SetupNewScene();
 228
 5229        isBuilderInWorldActivated = true;
 230
 5231        previousSkyBoxMaterial = RenderSettings.skybox;
 5232        RenderSettings.skybox = skyBoxMaterial;
 233
 10234        foreach (var groundVisual in groundVisualsGO)
 235        {
 0236            groundVisual.SetActive(false);
 237        }
 238
 5239        startEditorTimeStamp = Time.realtimeSinceStartup;
 240
 5241        BIWAnalytics.AddSceneInfo(sceneToEdit.sceneData.basePosition, BIWUtils.GetLandOwnershipType(DataStore.i.builderI
 5242    }
 243
 244    public void ExitEditMode()
 245    {
 1246        Environment.i.platform.cullingController.Start();
 1247        BIWNFTController.i.ExitEditMode();
 248
 1249        CommonScriptableObjects.builderInWorldNotNecessaryUIVisibilityStatus.Set(true);
 1250        DataStore.i.builderInWorld.showTaskBar.Set(true);
 251
 1252        ParcelSettings.VISUAL_LOADING_ENABLED = true;
 253
 1254        outlinerController.CancelAllOutlines();
 255
 1256        cursorGO.SetActive(true);
 257
 1258        InmediateExit();
 259
 1260        if ( context.editorContext.editorHUD != null)
 261        {
 1262            context.editorContext.editorHUD.ClearEntityList();
 1263            context.editorContext.editorHUD.SetVisibility(false);
 264        }
 265
 1266        Environment.i.world.sceneController.DeactivateBuilderInWorldEditScene();
 1267        Environment.i.world.blockersController.SetEnabled(true);
 268
 1269        ExitBiwControllers();
 270
 2271        foreach (var groundVisual in groundVisualsGO)
 272        {
 0273            groundVisual.SetActive(true);
 274        }
 275
 1276        isBuilderInWorldActivated = false;
 1277        RenderSettings.skybox = previousSkyBoxMaterial;
 278
 1279        if (biwAudioHandler.gameObject != null)
 1280            biwAudioHandler.gameObject.SetActive(false);
 1281        DataStore.i.common.appMode.Set(AppMode.DEFAULT);
 1282        DataStore.i.virtualAudioMixer.sceneSFXVolume.Set(1f);
 1283        BIWAnalytics.ExitEditor(Time.realtimeSinceStartup - startEditorTimeStamp);
 1284    }
 285
 2286    public void InmediateExit() { builderInWorldBridge.ExitKernelEditMode(sceneToEdit); }
 287
 288    public void EnterBiwControllers()
 289    {
 166290        foreach (var controller in controllers)
 291        {
 77292            controller.EnterEditMode(sceneToEdit);
 293        }
 294
 295        //Note: This audio should inside the controllers, it is here because it is still a monobehaviour
 6296        biwAudioHandler.EnterEditMode(sceneToEdit);
 6297    }
 298
 299    public void ExitBiwControllers()
 300    {
 28301        foreach (var controller in controllers)
 302        {
 13303            controller.ExitEditMode();
 304        }
 305
 1306        if (biwAudioHandler.gameObject != null)
 1307            biwAudioHandler.ExitEditMode();
 1308    }
 309
 5310    public bool IsNewScene() { return sceneToEdit.entities.Count <= 0; }
 311
 12312    public void SetupNewScene() { floorHandler.CreateDefaultFloor(); }
 313}