< Summary

Class:BIWEntityHandler
Assembly:BuilderInWorld
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Scripts/Controllers/BIWEntityHandler.cs
Covered lines:360
Uncovered lines:71
Coverable lines:431
Total lines:879
Line coverage:83.5% (360 of 431)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
BIWEntityHandler()0%110100%
Initialize(...)0%330100%
OnInputMouseDown(...)0%6200%
OnInputMouseUp(...)0%220100%
Dispose()0%220100%
Update()0%12300%
ReportTransform(...)0%21.527033.33%
GetLastTimeReport()0%2100%
GetSelectedEntityList()0%2100%
IsAnyEntitySelected()0%110100%
SetActiveMode(...)0%2100%
SetMultiSelectionActive(...)0%2100%
EnterEditMode(...)0%110100%
CheckErrorOnEntities()0%330100%
IsPointerInSelectedEntity()0%4.024090%
DeleteSelectedEntitiesInput()0%6200%
DuplicateSelectedEntitiesInput()0%12300%
ExitEditMode()0%6200%
ChangeEntitySelectionFromList(...)0%2.52050%
SelectFromList(...)0%4.374071.43%
DeselectEntity(...)0%7.297081.82%
DeselectEntities()0%440100%
EntityClicked(...)0%7.67076.92%
ReSelectEntities()0%330100%
ChangeEntitySelectStatus(...)0%2.062075%
CancelSelection()0%2.032080%
ChangeLockStateSelectedEntities()0%220100%
ShowAllEntities()0%330100%
ChangeShowStateSelectedEntities()0%440100%
Select(...)0%2.032080%
SelectEntity(...)0%6.016092.86%
GetAllVoxelsEntities()0%440100%
GetAllEntitiesFromCurrentScene()0%330100%
GetConvertedEntity(...)0%2.152066.67%
GetConvertedEntity(...)0%2.152066.67%
DuplicateSelectedEntities()0%440100%
DuplicateEntity(...)0%110100%
CreateEntityFromJSON(...)0%7.057090%
CreateEmptyEntity(...)0%440100%
SetupAllEntities()0%220100%
DestroyLastCreatedEntities()0%770100%
EntityListChanged()0%2.062075%
GetCurrentSceneEntityCount()0%110100%
GetEntitiesInCurrentScene()0%330100%
SetupEntityToEdit(...)0%7.647076.47%
ChangeEntityBoundsCheckerStatus(...)0%2.032080%
GetNewNameForEntity(...)0%110100%
GetNewNameForEntity(...)0%3.143075%
DeleteFloorEntities()0%440100%
DeleteEntity(...)0%110100%
DeleteEntity(...)0%110100%
DeleteEntity(...)0%9.079090.48%
DeleteSingleEntity(...)0%110100%
DeleteSelectedEntities()0%4.014092.31%
DeleteEntitiesOutsideSceneBoundaries()0%550100%
DestroyCollidersForAllEntities()0%220100%
RemoveConvertedEntity(...)0%110100%
NotifyEntityIsCreated(...)0%2.152066.67%
SetEntityName(...)0%110100%
SetEntityName(...)0%6.566075%
ChangeEntityVisibilityStatus(...)0%330100%
ChangeEntityLockStatus(...)0%4.594066.67%
GetConvertedUniqueKeyForEntity(...)0%110100%
GetConvertedUniqueKeyForEntity(...)0%110100%
AreAllEntitiesInsideBoundaries()0%330100%

File(s)

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

#LineLine coverage
 1using DCL;
 2using DCL.Components;
 3using DCL.Configuration;
 4using DCL.Controllers;
 5using DCL.Helpers;
 6using DCL.Interface;
 7using DCL.Models;
 8using Newtonsoft.Json;
 9using System;
 10using System.Collections;
 11using System.Collections.Generic;
 12using System.Diagnostics.CodeAnalysis;
 13using DCL.Builder;
 14using UnityEngine;
 15using Environment = DCL.Environment;
 16
 17public class BIWEntityHandler : BIWController, IBIWEntityHandler
 18{
 19    private const float DUPLICATE_OFFSET = 2f;
 20
 21    private IBIWOutlinerController outlinerController;
 22
 23    private IBIWModeController modeController;
 24    private IBIWActionController actionController;
 25    private IBIWCreatorController creatorController;
 26    private IBIWRaycastController raycastController;
 27
 28    private BuilderInWorldBridge bridge;
 29    private Material editMaterial;
 30
 31    private InputAction_Trigger hideSelectedEntitiesAction;
 32
 33    private InputAction_Trigger showAllEntitiesAction;
 34
 7035    private readonly Dictionary<string, BIWEntity> convertedEntities = new Dictionary<string, BIWEntity>();
 7036    private readonly List<BIWEntity> selectedEntities = new List<BIWEntity>();
 37
 38    private IBIWMode currentActiveMode;
 39    internal bool isMultiSelectionActive = false;
 40    internal bool isSecondayClickPressed = false;
 41
 42    private float lastTransformReportTime;
 43
 7044    private List<string> entityNameList = new List<string>();
 45
 46    private InputAction_Trigger.Triggered hideSelectedEntitiesDelegate;
 47    private InputAction_Trigger.Triggered showAllEntitiesDelegate;
 48
 49    private IBuilderEditorHUDController hudController;
 50
 51    public event Action<BIWEntity> OnEntityDeselected;
 52    public event Action OnEntitySelected;
 53    public event Action<List<BIWEntity>> OnDeleteSelectedEntities;
 54    public event Action<BIWEntity> OnEntityDeleted;
 55
 56    private BIWEntity lastClickedEntity;
 57    private float lastTimeEntityClicked;
 58
 59    public override void Initialize(IContext context)
 60    {
 7061        base.Initialize(context);
 7062        if ( context.editorContext.editorHUD != null)
 63        {
 7064            hudController = context.editorContext.editorHUD;
 7065            hudController.OnEntityDelete += DeleteSingleEntity;
 7066            hudController.OnDuplicateSelectedAction += DuplicateSelectedEntitiesInput;
 7067            hudController.OnDeleteSelectedAction += DeleteSelectedEntitiesInput;
 7068            hudController.OnEntityClick += ChangeEntitySelectionFromList;
 7069            hudController.OnEntityLock += ChangeEntityLockStatus;
 7070            hudController.OnEntityChangeVisibility += ChangeEntityVisibilityStatus;
 7071            hudController.OnEntityRename += SetEntityName;
 7072            hudController.OnEntitySmartItemComponentUpdate += UpdateSmartItemComponentInKernel;
 73        }
 74
 75
 7076        BIWInputWrapper.OnMouseDown += OnInputMouseDown;
 7077        BIWInputWrapper.OnMouseUp += OnInputMouseUp;
 78
 7079        DCL.Environment.i.world.sceneBoundsChecker.OnEntityBoundsCheckerStatusChanged += ChangeEntityBoundsCheckerStatus
 80
 7081        if ( context.sceneReferences.biwBridgeGameObject != null )
 482            bridge = context.sceneReferences.biwBridgeGameObject.GetComponent<BuilderInWorldBridge>();
 83
 7084        outlinerController = context.editorContext.outlinerController;
 85
 7086        modeController = context.editorContext.modeController;
 7087        actionController = context.editorContext.actionController;
 7088        creatorController = context.editorContext.creatorController;
 7089        raycastController = context.editorContext.raycastController;
 90
 7091        editMaterial = context.projectReferencesAsset.editMaterial;
 92
 7093        hideSelectedEntitiesAction = context.inputsReferencesAsset.hideSelectedEntitiesAction;
 7094        showAllEntitiesAction = context.inputsReferencesAsset.showAllEntitiesAction;
 95
 7096        hideSelectedEntitiesDelegate = (action) => ChangeShowStateSelectedEntities();
 7097        showAllEntitiesDelegate = (action) => ShowAllEntities();
 98
 7099        hideSelectedEntitiesAction.OnTriggered += hideSelectedEntitiesDelegate;
 70100        showAllEntitiesAction.OnTriggered += showAllEntitiesDelegate;
 101
 70102        actionController.OnRedo += ReSelectEntities;
 70103        actionController.OnUndo += ReSelectEntities;
 70104    }
 105
 106    internal void OnInputMouseDown(int buttonId, Vector3 mousePosition)
 107    {
 0108        if (buttonId == 1)
 0109            isSecondayClickPressed = true;
 0110    }
 111
 112    internal void OnInputMouseUp(int buttonId, Vector3 mousePosition)
 113    {
 5114        if (buttonId == 1)
 5115            isSecondayClickPressed = false;
 5116    }
 117
 118    public override void Dispose()
 119    {
 56120        DestroyCollidersForAllEntities();
 121
 56122        actionController.OnRedo -= ReSelectEntities;
 56123        actionController.OnUndo -= ReSelectEntities;
 124
 56125        hideSelectedEntitiesAction.OnTriggered -= hideSelectedEntitiesDelegate;
 56126        showAllEntitiesAction.OnTriggered -= showAllEntitiesDelegate;
 127
 56128        DCL.Environment.i.world.sceneBoundsChecker.OnEntityBoundsCheckerStatusChanged -= ChangeEntityBoundsCheckerStatus
 129
 56130        BIWInputWrapper.OnMouseDown -= OnInputMouseDown;
 56131        BIWInputWrapper.OnMouseUp -= OnInputMouseUp;
 132
 56133        if (hudController != null)
 134        {
 56135            hudController.OnEntityDelete -= DeleteSingleEntity;
 56136            hudController.OnDuplicateSelectedAction -= DuplicateSelectedEntitiesInput;
 56137            hudController.OnDeleteSelectedAction -= DeleteSelectedEntitiesInput;
 56138            hudController.OnEntityClick -= ChangeEntitySelectionFromList;
 56139            hudController.OnEntityLock -= ChangeEntityLockStatus;
 56140            hudController.OnEntityChangeVisibility -= ChangeEntityVisibilityStatus;
 56141            hudController.OnEntityChangeVisibility -= ChangeEntityVisibilityStatus;
 56142            hudController.OnEntityRename -= SetEntityName;
 56143            hudController.OnEntitySmartItemComponentUpdate -= UpdateSmartItemComponentInKernel;
 144        }
 56145    }
 146
 147    public override void Update()
 148    {
 0149        base.Update();
 150
 0151        if (selectedEntities.Count == 0)
 0152            return;
 0153        if ((DCLTime.realtimeSinceStartup - lastTransformReportTime) <= BIWSettings.ENTITY_POSITION_REPORTING_DELAY)
 0154            return;
 155
 0156        ReportTransform();
 0157    }
 158
 159    public void ReportTransform(bool forceReport = false)
 160    {
 4161        foreach (BIWEntity entity in selectedEntities)
 162        {
 0163            if (!entity.HasMovedSinceLastReport() &&
 164                !entity.HasScaledSinceLastReport() &&
 165                !entity.HasRotatedSinceLastReport() &&
 166                !forceReport)
 0167                return;
 168
 0169            if ( bridge != null )
 0170                bridge.EntityTransformReport(entity.rootEntity, sceneToEdit);
 0171            entity.PositionReported();
 0172            entity.ScaleReported();
 0173            entity.RotationReported();
 174        }
 175
 2176        lastTransformReportTime = DCLTime.realtimeSinceStartup;
 2177    }
 178
 0179    public float GetLastTimeReport() { return lastTransformReportTime; }
 180
 0181    public List<BIWEntity> GetSelectedEntityList() { return selectedEntities; }
 182
 1183    public bool IsAnyEntitySelected() { return selectedEntities.Count > 0; }
 184
 185    public void SetActiveMode(IBIWMode buildMode)
 186    {
 0187        currentActiveMode = buildMode;
 0188        DeselectEntities();
 0189    }
 190
 0191    public void SetMultiSelectionActive(bool isActive) { isMultiSelectionActive = isActive; }
 192
 193    public override void EnterEditMode(IParcelScene scene)
 194    {
 72195        base.EnterEditMode(scene);
 196
 72197        SetupAllEntities();
 72198        EntityListChanged();
 72199        CheckErrorOnEntities();
 72200    }
 201
 202    private void CheckErrorOnEntities()
 203    {
 240204        foreach (BIWEntity entity in convertedEntities.Values)
 205        {
 48206            entity.CheckErrors();
 48207            if (entity.hasMissingCatalogItemError)
 48208                creatorController.CreateErrorOnEntity(entity);
 209        }
 72210    }
 211
 212    public bool IsPointerInSelectedEntity()
 213    {
 2214        BIWEntity entityInPointer = raycastController.GetEntityOnPointer();
 2215        if (entityInPointer == null)
 1216            return false;
 217
 3218        foreach (BIWEntity entity in selectedEntities)
 219        {
 1220            if (entityInPointer == entity)
 1221                return true;
 222        }
 223
 0224        return false;
 1225    }
 226
 227    private void DeleteSelectedEntitiesInput()
 228    {
 0229        if (selectedEntities.Count > 0)
 0230            DeleteSelectedEntities();
 0231    }
 232
 233    private void DuplicateSelectedEntitiesInput()
 234    {
 0235        if (selectedEntities.Count <= 0 || isSecondayClickPressed)
 0236            return;
 237
 0238        DuplicateSelectedEntities();
 0239    }
 240
 241    public override void ExitEditMode()
 242    {
 0243        base.ExitEditMode();
 0244        DeselectEntities();
 245
 0246        foreach (BIWEntity entity in convertedEntities.Values)
 247        {
 0248            entity.Dispose();
 249        }
 250
 0251        convertedEntities.Clear();
 0252    }
 253
 254    internal void ChangeEntitySelectionFromList(BIWEntity entityToEdit)
 255    {
 1256        if (!selectedEntities.Contains(entityToEdit))
 1257            SelectFromList(entityToEdit);
 258        else
 0259            DeselectEntity(entityToEdit);
 0260    }
 261
 262    private void SelectFromList(BIWEntity entityToEdit)
 263    {
 1264        if (!isMultiSelectionActive)
 1265            DeselectEntities();
 1266        if (SelectEntity(entityToEdit))
 267        {
 1268            if (!isMultiSelectionActive)
 1269                outlinerController.OutlineEntity(entityToEdit);
 270            else
 0271                outlinerController.OutlineEntities(selectedEntities);
 272        }
 0273    }
 274
 275    public void DeselectEntity(BIWEntity entity)
 276    {
 12277        if (!selectedEntities.Contains(entity))
 0278            return;
 279
 12280        entity.Deselect();
 281
 12282        outlinerController.CancelEntityOutline(entity);
 12283        selectedEntities.Remove(entity);
 12284        hudController?.UpdateEntitiesSelection(selectedEntities.Count);
 12285        currentActiveMode?.EntityDeselected(entity);
 12286        if (selectedEntities.Count <= 0 &&
 287            hudController != null)
 12288            hudController.HideEntityInformation();
 289
 12290        OnEntityDeselected?.Invoke(entity);
 0291    }
 292
 293    public void DeselectEntities()
 294    {
 40295        if (selectedEntities.Count <= 0)
 31296            return;
 297
 9298        int amountToDeselect = selectedEntities.Count;
 36299        for (int i = 0; i < amountToDeselect; i++)
 300        {
 9301            DeselectEntity(selectedEntities[0]);
 302        }
 303
 9304        currentActiveMode?.OnDeselectedEntities();
 305
 9306        Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
 9307    }
 308
 309    public void EntityClicked(BIWEntity entityToSelect)
 310    {
 3311        if (entityToSelect != null)
 312        {
 3313            if (!isMultiSelectionActive)
 3314                DeselectEntities();
 315
 3316            if (!entityToSelect.isLocked)
 3317                ChangeEntitySelectStatus(entityToSelect);
 318
 3319            if (entityToSelect == lastClickedEntity && (lastTimeEntityClicked + BIWSettings.MOUSE_MS_DOUBLE_CLICK_THRESH
 1320                modeController.EntityDoubleClick(entityToSelect);
 321
 3322            lastClickedEntity = entityToSelect;
 3323            lastTimeEntityClicked = Time.realtimeSinceStartup;
 3324        }
 0325        else if (!isMultiSelectionActive)
 326        {
 0327            DeselectEntities();
 328        }
 0329    }
 330
 331    internal void ReSelectEntities()
 332    {
 13333        List<BIWEntity> entitiesToReselect = new List<BIWEntity>();
 28334        foreach (BIWEntity entity in selectedEntities)
 335        {
 1336            entitiesToReselect.Add(entity);
 337        }
 338
 13339        DeselectEntities();
 340
 28341        foreach (BIWEntity entity in entitiesToReselect)
 342        {
 1343            SelectEntity(entity);
 344        }
 13345    }
 346
 347    internal void ChangeEntitySelectStatus(BIWEntity entityCliked)
 348    {
 3349        if (entityCliked.isSelected)
 0350            DeselectEntity(entityCliked);
 351        else
 3352            SelectEntity(entityCliked);
 3353    }
 354
 355    public void CancelSelection()
 356    {
 1357        if (selectedEntities.Count == 0)
 0358            return;
 359
 1360        DestroyLastCreatedEntities();
 1361        DeselectEntities();
 1362    }
 363
 364    public void ChangeLockStateSelectedEntities()
 365    {
 4366        foreach (BIWEntity entity in selectedEntities)
 367        {
 1368            entity.ToggleLockStatus();
 369        }
 370
 1371        DeselectEntities();
 1372    }
 373
 374    public void ShowAllEntities()
 375    {
 4376        foreach (BIWEntity entity in convertedEntities.Values)
 377        {
 1378            if (!entity.isVisible)
 1379                entity.ToggleShowStatus();
 380        }
 1381    }
 382
 383    public void ChangeShowStateSelectedEntities()
 384    {
 1385        List<BIWEntity> entitiesToHide = new List<BIWEntity>(selectedEntities);
 386
 4387        foreach (BIWEntity entity in entitiesToHide)
 388        {
 1389            if (entity.isVisible && entity.isSelected)
 1390                DeselectEntity(entity);
 1391            entity.ToggleShowStatus();
 392        }
 1393    }
 394
 395    public void Select(IDCLEntity entity)
 396    {
 8397        BIWEntity entityEditable = GetConvertedEntity(entity);
 8398        if (entityEditable == null)
 0399            return;
 400
 8401        SelectEntity(entityEditable, true);
 8402    }
 403
 404    public bool SelectEntity(BIWEntity entityEditable, bool selectedFromCatalog = false)
 405    {
 27406        if (entityEditable.isLocked)
 1407            return false;
 408
 26409        if (entityEditable.isSelected)
 0410            return false;
 411
 26412        entityEditable.Select();
 413
 26414        selectedEntities.Add(entityEditable);
 415
 26416        currentActiveMode?.SelectedEntity(entityEditable);
 417
 26418        if ( context.editorContext.editorHUD != null)
 419        {
 26420            hudController.UpdateEntitiesSelection(selectedEntities.Count);
 26421            hudController.ShowEntityInformation(selectedFromCatalog);
 26422            hudController.EntityInformationSetEntity(entityEditable, sceneToEdit);
 423        }
 424
 26425        outlinerController.CancelAllOutlines();
 426
 26427        OnEntitySelected?.Invoke();
 428
 26429        return true;
 430    }
 431
 432    public List<BIWEntity> GetAllVoxelsEntities()
 433    {
 1434        List<BIWEntity> voxelEntities = new List<BIWEntity>();
 4435        foreach (BIWEntity entity in convertedEntities.Values)
 436        {
 1437            if (entity.rootEntity.scene == sceneToEdit && entity.isVoxel)
 1438                voxelEntities.Add(entity);
 439        }
 440
 1441        return voxelEntities;
 442    }
 443
 444    public List<BIWEntity> GetAllEntitiesFromCurrentScene()
 445    {
 56446        List<BIWEntity> entities = new List<BIWEntity>();
 246447        foreach (BIWEntity entity in convertedEntities.Values)
 448        {
 67449            if (entity.rootEntity.scene == sceneToEdit)
 67450                entities.Add(entity);
 451        }
 452
 56453        return entities;
 454    }
 455
 456    public BIWEntity GetConvertedEntity(string entityId)
 457    {
 6458        if (convertedEntities.ContainsKey(GetConvertedUniqueKeyForEntity(entityId)))
 6459            return convertedEntities[GetConvertedUniqueKeyForEntity(entityId)];
 460
 0461        return null;
 462    }
 463
 464    public BIWEntity GetConvertedEntity(IDCLEntity entity)
 465    {
 16466        if (convertedEntities.ContainsKey(GetConvertedUniqueKeyForEntity(entity)))
 16467            return convertedEntities[GetConvertedUniqueKeyForEntity(entity)];
 468
 0469        return null;
 470    }
 471
 472    public void DuplicateSelectedEntities()
 473    {
 2474        BIWCompleteAction buildAction = new BIWCompleteAction();
 2475        buildAction.actionType = IBIWCompleteAction.ActionType.CREATE;
 476
 2477        List<BIWEntityAction> entityActionList = new List<BIWEntityAction>();
 2478        List<BIWEntity> entitiesToDuplicate = new List<BIWEntity>(selectedEntities);
 2479        DeselectEntities();
 480
 8481        foreach (BIWEntity entityToDuplicate in entitiesToDuplicate)
 482        {
 2483            if (entityToDuplicate.isNFT)
 484                continue;
 485
 2486            var entityDuplicated = DuplicateEntity(entityToDuplicate);
 2487            BIWEntityAction biwEntityAction = new BIWEntityAction(entityDuplicated.rootEntity, entityDuplicated.rootEnti
 2488            entityActionList.Add(biwEntityAction);
 2489            SelectEntity(entityDuplicated);
 490        }
 491
 2492        currentActiveMode?.SetDuplicationOffset(DUPLICATE_OFFSET);
 493
 2494        buildAction.CreateActionType(entityActionList, IBIWCompleteAction.ActionType.CREATE);
 2495        actionController.AddAction(buildAction);
 2496    }
 497
 498    public BIWEntity DuplicateEntity(BIWEntity entityToDuplicate)
 499    {
 3500        IDCLEntity entity = SceneUtils.DuplicateEntity(sceneToEdit, entityToDuplicate.rootEntity);
 501        //Note: If the entity contains the name component or DCLLockedOnEdit, we don't want to copy them
 3502        entity.RemoveSharedComponent(typeof(DCLName), false);
 3503        entity.RemoveSharedComponent(typeof(DCLLockedOnEdit), false);
 504
 3505        BIWUtils.CopyGameObjectStatus(entityToDuplicate.rootEntity.gameObject, entity.gameObject, false, false);
 3506        BIWEntity convertedEntity = SetupEntityToEdit(entity);
 507
 3508        NotifyEntityIsCreated(entity);
 3509        EntityListChanged();
 3510        return convertedEntity;
 511    }
 512
 513    public IDCLEntity CreateEntityFromJSON(string entityJson)
 514    {
 3515        EntityData data = BIWUtils.ConvertJSONToEntityData(entityJson);
 516
 3517        IDCLEntity newEntity = sceneToEdit.CreateEntity(data.entityId);
 518
 519
 3520        if (data.transformComponent != null)
 521        {
 1522            DCLTransform.Model model = new DCLTransform.Model();
 1523            model.position = data.transformComponent.position;
 1524            model.rotation = Quaternion.Euler(data.transformComponent.rotation);
 1525            model.scale = data.transformComponent.scale;
 526
 1527            EntityComponentsUtils.AddTransformComponent(sceneToEdit, newEntity, model);
 528        }
 529
 6530        foreach (ProtocolV2.GenericComponent component in data.components)
 531        {
 0532            sceneToEdit.EntityComponentCreateOrUpdateWithModel(newEntity.entityId, (CLASS_ID_COMPONENT) component.compon
 533        }
 534
 10535        foreach (ProtocolV2.GenericComponent component in data.sharedComponents)
 536        {
 2537            sceneToEdit.SharedComponentAttach(newEntity.entityId, component.classId);
 538        }
 539
 3540        if (data.nftComponent != null)
 541        {
 1542            NFTShape.Model model = new NFTShape.Model();
 1543            model.color = data.nftComponent.color.ToColor();
 1544            model.src = data.nftComponent.src;
 1545            model.assetId = data.nftComponent.assetId;
 546
 1547            EntityComponentsUtils.AddNFTShapeComponent(sceneToEdit, newEntity, model, data.nftComponent.id);
 548        }
 549
 3550        var convertedEntity = SetupEntityToEdit(newEntity, true);
 551
 3552        if (convertedEntity.rootEntity.TryGetSharedComponent(CLASS_ID.GLTF_SHAPE, out var gltfComponent))
 0553            gltfComponent.CallWhenReady(convertedEntity.ShapeLoadFinish);
 554
 3555        if (convertedEntity.rootEntity.TryGetSharedComponent(CLASS_ID.NFT_SHAPE, out var nftComponent))
 1556            nftComponent.CallWhenReady(convertedEntity.ShapeLoadFinish);
 557
 558
 3559        creatorController.CreateLoadingObject(convertedEntity);
 3560        EntityListChanged();
 561
 3562        return newEntity;
 563    }
 564
 565    public BIWEntity CreateEmptyEntity(IParcelScene parcelScene, Vector3 entryPoint, Vector3 editionGOPosition, bool not
 566    {
 30567        IDCLEntity newEntity = parcelScene.CreateEntity(Guid.NewGuid().ToString());
 30568        DCLTransform.Model transformModel = new DCLTransform.Model();
 30569        transformModel.position = WorldStateUtils.ConvertUnityToScenePosition(entryPoint, parcelScene);
 570
 30571        Camera camera = context.sceneReferences.mainCamera;
 30572        Vector3 pointToLookAt = camera != null ? camera.transform.position : Vector3.zero;
 30573        pointToLookAt.y = editionGOPosition.y;
 30574        Quaternion lookOnLook = Quaternion.LookRotation(editionGOPosition - pointToLookAt);
 575
 30576        transformModel.rotation = lookOnLook;
 30577        transformModel.scale = newEntity.gameObject.transform.lossyScale;
 578
 30579        EntityComponentsUtils.AddTransformComponent(parcelScene, newEntity, transformModel);
 580
 30581        BIWEntity convertedEntity = SetupEntityToEdit(newEntity, true);
 30582        hudController?.UpdateSceneLimitInfo();
 583
 30584        if (notifyEntityList)
 11585            EntityListChanged();
 30586        return convertedEntity;
 587    }
 588
 589    private void SetupAllEntities()
 590    {
 240591        foreach (IDCLEntity entity in sceneToEdit.entities.Values)
 592        {
 48593            SetupEntityToEdit(entity);
 594        }
 72595    }
 596
 597    public void DestroyLastCreatedEntities()
 598    {
 2599        List<BIWEntity> entitiesToRemove = new List<BIWEntity>();
 8600        foreach (BIWEntity entity in selectedEntities)
 601        {
 2602            if (entity.isSelected && entity.isNew)
 1603                entitiesToRemove.Add(entity);
 604        }
 605
 2606        if (entitiesToRemove.Count == 0)
 1607            return;
 608
 1609        modeController.UndoEditionGOLastStep();
 610
 4611        foreach (BIWEntity entity in entitiesToRemove)
 612        {
 1613            DeleteEntity(entity, false);
 614        }
 615
 1616        hudController?.HideEntityInformation();
 1617    }
 618
 619    public void EntityListChanged()
 620    {
 117621        if ( context.editorContext.editorHUD == null)
 0622            return;
 117623        hudController.SetEntityList(GetEntitiesInCurrentScene());
 117624    }
 625
 2626    public int GetCurrentSceneEntityCount() { return GetEntitiesInCurrentScene().Count; }
 627
 628    List<BIWEntity> GetEntitiesInCurrentScene()
 629    {
 119630        List<BIWEntity> currentEntitiesInScene = new List<BIWEntity>();
 448631        foreach (BIWEntity entity in convertedEntities.Values)
 632        {
 105633            if (entity.rootEntity.scene == sceneToEdit)
 105634                currentEntitiesInScene.Add(entity);
 635        }
 636
 119637        return currentEntitiesInScene;
 638    }
 639
 640    BIWEntity SetupEntityToEdit(IDCLEntity entity, bool hasBeenCreated = false)
 641    {
 84642        string biwEntityId = GetConvertedUniqueKeyForEntity(entity);
 643
 84644        if (convertedEntities.ContainsKey(biwEntityId))
 1645            return convertedEntities[biwEntityId];
 646
 83647        BIWEntity entityToEdit = new BIWEntity();
 83648        entityToEdit.Initialize(entity, editMaterial);
 83649        convertedEntities.Add(entityToEdit.entityUniqueId, entityToEdit);
 83650        entity.OnRemoved += RemoveConvertedEntity;
 83651        entityToEdit.isNew = hasBeenCreated;
 652
 83653        string entityName = entityToEdit.GetDescriptiveName();
 83654        var catalogItem = entityToEdit.GetCatalogItemAssociated();
 655
 83656        if ((string.IsNullOrEmpty(entityName) || entityNameList.Contains(entityName)) && catalogItem != null)
 657        {
 0658            entityName = GetNewNameForEntity(catalogItem);
 0659            SetEntityName(entityToEdit, entityName);
 0660        }
 83661        else if (!string.IsNullOrEmpty(entityName) && !entityNameList.Contains(entityName))
 662        {
 0663            entityNameList.Add(entityName);
 664        }
 665
 83666        return entityToEdit;
 667    }
 668
 669    internal void ChangeEntityBoundsCheckerStatus(IDCLEntity entity, bool isInsideBoundaries)
 670    {
 1671        var convertedEntity = GetConvertedEntity(entity);
 1672        if (convertedEntity == null)
 0673            return;
 674
 1675        convertedEntity.SetEntityBoundariesError(isInsideBoundaries);
 1676    }
 677
 1678    public string GetNewNameForEntity(CatalogItem sceneObject) { return GetNewNameForEntity(sceneObject.name); }
 679
 680    public string GetNewNameForEntity(string name)
 681    {
 3682        int i = 1;
 3683        if (!entityNameList.Contains(name))
 1684            return name;
 685
 2686        string newName = name + " " + i;
 2687        while (entityNameList.Contains(newName))
 688        {
 0689            i++;
 0690            newName = name + " " + i;
 691        }
 692
 2693        return newName;
 694    }
 695
 696    public void DeleteFloorEntities()
 697    {
 4698        List<BIWEntity> entitiesToDelete = new List<BIWEntity>();
 699
 22700        foreach (BIWEntity entity in convertedEntities.Values)
 701        {
 7702            if (entity.isFloor)
 703            {
 4704                entitiesToDelete.Add(entity);
 705            }
 706        }
 707
 16708        foreach (BIWEntity entity in entitiesToDelete)
 4709            DeleteEntity(entity, false);
 4710    }
 711
 712    public void DeleteEntity(string entityId)
 713    {
 3714        BIWEntity entity = convertedEntities[GetConvertedUniqueKeyForEntity(entityId)];
 3715        DeleteEntity(entity, true);
 3716    }
 717
 8718    public void DeleteEntity(BIWEntity entityToDelete) { DeleteEntity(entityToDelete, true); }
 719
 720    public void DeleteEntity(BIWEntity entityToDelete, bool checkSelection)
 721    {
 13722        if (entityToDelete.isSelected && checkSelection)
 0723            DeselectEntity(entityToDelete);
 724
 13725        if (selectedEntities.Contains(entityToDelete))
 726        {
 1727            selectedEntities.Remove(entityToDelete);
 1728            hudController?.UpdateEntitiesSelection(selectedEntities.Count);
 729        }
 730
 13731        string entityName = entityToDelete.GetDescriptiveName();
 732
 13733        if (entityNameList.Contains(entityName))
 4734            entityNameList.Remove(entityName);
 735
 13736        RemoveConvertedEntity(entityToDelete.rootEntity);
 13737        entityToDelete.rootEntity.OnRemoved -= RemoveConvertedEntity;
 13738        entityToDelete.Delete();
 13739        string idToRemove = entityToDelete.rootEntity.entityId;
 13740        OnEntityDeleted?.Invoke(entityToDelete);
 13741        creatorController.RemoveLoadingObjectInmediate(entityToDelete.rootEntity.entityId);
 13742        if (sceneToEdit.entities.ContainsKey(idToRemove))
 13743            sceneToEdit.RemoveEntity(idToRemove, true);
 744
 13745        hudController?.RefreshCatalogAssetPack();
 13746        EntityListChanged();
 747
 13748        if ( bridge != null )
 0749            bridge.RemoveEntityOnKernel(idToRemove, sceneToEdit);
 13750    }
 751
 752    public void DeleteSingleEntity(BIWEntity entityToDelete)
 753    {
 1754        actionController.CreateActionEntityDeleted(entityToDelete);
 1755        DeleteEntity(entityToDelete, true);
 1756    }
 757
 758    public void DeleteSelectedEntities()
 759    {
 2760        List<BIWEntity> entitiesToRemove = new List<BIWEntity>();
 761
 8762        for (int i = 0; i < selectedEntities.Count; i++)
 763        {
 2764            entitiesToRemove.Add(selectedEntities[i]);
 765        }
 766
 2767        actionController.CreateActionEntityDeleted(entitiesToRemove);
 768
 2769        DeselectEntities();
 770
 8771        foreach (BIWEntity entity in entitiesToRemove)
 772        {
 2773            DeleteEntity(entity);
 774        }
 775
 2776        OnDeleteSelectedEntities?.Invoke(entitiesToRemove);
 0777    }
 778
 779    public void DeleteEntitiesOutsideSceneBoundaries()
 780    {
 1781        List<BIWEntity> entitiesToRemove = new List<BIWEntity>();
 6782        foreach (BIWEntity entity in convertedEntities.Values)
 783        {
 2784            if (entity.rootEntity.scene == sceneToEdit)
 785            {
 2786                if (!DCL.Environment.i.world.sceneBoundsChecker.IsEntityInsideSceneBoundaries(entity.rootEntity))
 787                {
 2788                    entitiesToRemove.Add(entity);
 789                }
 790            }
 791        }
 792
 6793        foreach (BIWEntity entity in entitiesToRemove)
 794        {
 2795            DeleteEntity(entity);
 796        }
 1797    }
 798
 799    private void DestroyCollidersForAllEntities()
 800    {
 230801        foreach (BIWEntity entity in convertedEntities.Values)
 802        {
 59803            entity.DestroyColliders();
 804        }
 56805    }
 806
 26807    private void RemoveConvertedEntity(IDCLEntity entity) { convertedEntities.Remove(GetConvertedUniqueKeyForEntity(enti
 808
 809    public void NotifyEntityIsCreated(IDCLEntity entity)
 810    {
 18811        if (bridge != null)
 0812            bridge.AddEntityOnKernel(entity, sceneToEdit);
 18813    }
 814
 815    [ExcludeFromCodeCoverage]
 816    public void UpdateSmartItemComponentInKernel(BIWEntity entityToUpdate)
 817    {
 818        if ( bridge != null )
 819            bridge.UpdateSmartItemComponent(entityToUpdate, sceneToEdit);
 820    }
 821
 4822    public void SetEntityName(BIWEntity entityToApply, string newName) { SetEntityName(entityToApply, newName, true); }
 823
 824    public void SetEntityName(BIWEntity entityToApply, string newName, bool sendUpdateToKernel = true)
 825    {
 17826        string currentName = entityToApply.GetDescriptiveName();
 827
 17828        if (currentName == newName)
 0829            return;
 830
 17831        if (entityNameList.Contains(newName))
 2832            newName = GetNewNameForEntity(newName);
 833
 17834        if (entityNameList.Contains(currentName))
 0835            entityNameList.Remove(currentName);
 836
 17837        entityToApply.SetDescriptiveName(newName);
 17838        entityNameList.Add(newName);
 839
 17840        if (sendUpdateToKernel && bridge != null)
 0841            bridge.ChangedEntityName(entityToApply, sceneToEdit);
 17842    }
 843
 844    internal void ChangeEntityVisibilityStatus(BIWEntity entityToApply)
 845    {
 1846        entityToApply.ToggleShowStatus();
 1847        if (!entityToApply.isVisible && selectedEntities.Contains(entityToApply))
 1848            DeselectEntity(entityToApply);
 1849    }
 850
 851    internal void ChangeEntityLockStatus(BIWEntity entityToApply)
 852    {
 1853        entityToApply.ToggleLockStatus();
 1854        if (entityToApply.isLocked && selectedEntities.Contains(entityToApply))
 0855            DeselectEntity(entityToApply);
 856
 1857        if (bridge != null)
 0858            bridge.ChangeEntityLockStatus(entityToApply, sceneToEdit);
 1859    }
 860
 15861    private string GetConvertedUniqueKeyForEntity(string entityID) { return sceneToEdit.sceneData.id + entityID; }
 862
 129863    private string GetConvertedUniqueKeyForEntity(IDCLEntity entity) { return entity.scene.sceneData.id + entity.entityI
 864
 865    public bool AreAllEntitiesInsideBoundaries()
 866    {
 5867        bool areAllIn = true;
 14868        foreach (BIWEntity entity in convertedEntities.Values)
 869        {
 3870            if (!DCL.Environment.i.world.sceneBoundsChecker.IsEntityInsideSceneBoundaries(entity.rootEntity))
 871            {
 2872                areAllIn = false;
 2873                break;
 874            }
 875        }
 876
 5877        return areAllIn;
 878    }
 879}

Methods/Properties

BIWEntityHandler()
Initialize(DCL.Builder.IContext)
OnInputMouseDown(System.Int32, UnityEngine.Vector3)
OnInputMouseUp(System.Int32, UnityEngine.Vector3)
Dispose()
Update()
ReportTransform(System.Boolean)
GetLastTimeReport()
GetSelectedEntityList()
IsAnyEntitySelected()
SetActiveMode(IBIWMode)
SetMultiSelectionActive(System.Boolean)
EnterEditMode(DCL.Controllers.IParcelScene)
CheckErrorOnEntities()
IsPointerInSelectedEntity()
DeleteSelectedEntitiesInput()
DuplicateSelectedEntitiesInput()
ExitEditMode()
ChangeEntitySelectionFromList(BIWEntity)
SelectFromList(BIWEntity)
DeselectEntity(BIWEntity)
DeselectEntities()
EntityClicked(BIWEntity)
ReSelectEntities()
ChangeEntitySelectStatus(BIWEntity)
CancelSelection()
ChangeLockStateSelectedEntities()
ShowAllEntities()
ChangeShowStateSelectedEntities()
Select(DCL.Models.IDCLEntity)
SelectEntity(BIWEntity, System.Boolean)
GetAllVoxelsEntities()
GetAllEntitiesFromCurrentScene()
GetConvertedEntity(System.String)
GetConvertedEntity(DCL.Models.IDCLEntity)
DuplicateSelectedEntities()
DuplicateEntity(BIWEntity)
CreateEntityFromJSON(System.String)
CreateEmptyEntity(DCL.Controllers.IParcelScene, UnityEngine.Vector3, UnityEngine.Vector3, System.Boolean)
SetupAllEntities()
DestroyLastCreatedEntities()
EntityListChanged()
GetCurrentSceneEntityCount()
GetEntitiesInCurrentScene()
SetupEntityToEdit(DCL.Models.IDCLEntity, System.Boolean)
ChangeEntityBoundsCheckerStatus(DCL.Models.IDCLEntity, System.Boolean)
GetNewNameForEntity(CatalogItem)
GetNewNameForEntity(System.String)
DeleteFloorEntities()
DeleteEntity(System.String)
DeleteEntity(BIWEntity)
DeleteEntity(BIWEntity, System.Boolean)
DeleteSingleEntity(BIWEntity)
DeleteSelectedEntities()
DeleteEntitiesOutsideSceneBoundaries()
DestroyCollidersForAllEntities()
RemoveConvertedEntity(DCL.Models.IDCLEntity)
NotifyEntityIsCreated(DCL.Models.IDCLEntity)
SetEntityName(BIWEntity, System.String)
SetEntityName(BIWEntity, System.String, System.Boolean)
ChangeEntityVisibilityStatus(BIWEntity)
ChangeEntityLockStatus(BIWEntity)
GetConvertedUniqueKeyForEntity(System.String)
GetConvertedUniqueKeyForEntity(DCL.Models.IDCLEntity)
AreAllEntitiesInsideBoundaries()