< Summary

Class:BIWGodMode
Assembly:BuilderInWorld
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Scripts/States/EditorMode/BIWGodMode.cs
Covered lines:291
Uncovered lines:90
Coverable lines:381
Total lines:775
Line coverage:76.3% (291 of 381)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
BIWGodMode()0%110100%
Init(...)0%330100%
Dispose()0%33095.65%
Update()0%20400%
OnGUI()0%12300%
MultiSelectionInputStart(...)0%110100%
MultiSelectionInputEnd(...)0%110100%
CheckOutlineEntitiesInSquareSelection(...)0%5.035088.89%
ChangeSnapTemporaryDeactivated()0%220100%
ChangeSnapTemporaryActivated()0%2.032080%
EntitiesTransfromByGizmos(...)0%3.033085.71%
UpdateSelectionPosition(...)0%22090%
UpdateSelectionRotation(...)0%2.012088.89%
UpdateSelectionScale(...)0%22092.31%
DragEditionGameObject(...)0%2.032080%
MouseClickDetected()0%2.152066.67%
OnInputMouseDrag(...)0%26.59040%
GetPositionRoundedToSnapFactor(...)0%2100%
OnInputMouseUpOnUi(...)0%3.473062.5%
OnInputMouseUp(...)0%5.164058.33%
OnInputMouseDown(...)0%11.559068.42%
CheckEndBoundMultiselection(...)0%8.744033.33%
CanCancelAction(...)0%6200%
StarDraggingSelectedEntities()0%440100%
EndDraggingSelectedEntities()0%3.143075%
EndBoundMultiSelection(...)0%12.4211077.27%
Activate(...)0%330100%
ConfigureCamera(...)0%110100%
OnDeleteEntity(...)0%6200%
OnDeselectedEntities()0%2100%
Deactivate()0%110100%
StartMultiSelection()0%110100%
SetDuplicationOffset(...)0%2100%
CreatedEntity(...)0%3.013088.89%
GetCreatedEntityPoint()0%2100%
SelectedEntity(...)0%330100%
EntityDeselected(...)0%3.143075%
EntityDoubleClick(...)0%6200%
UpdateActionsInteractable()0%220100%
ShouldCancelUndoAction()0%2.032080%
SetSnapActive(...)0%220100%
FocusOnSelectedEntitiesInput()0%6200%
TryLookAtEntity(...)0%64050%
LookAtEntity(...)0%3.073080%
CalculateEntityMidPoint(...)0%330100%
TranslateMode()0%110100%
RotateMode()0%110100%
ScaleMode()0%110100%
GizmosMode(...)0%7.777075%
OnGizmosTransformStart(...)0%220100%
OnGizmosTransformEnd(...)0%6.566075%
FocusEntities(...)0%110100%
SetLookAtObject(...)0%110100%
SetEditObjectAtMouse()0%6.325062.5%
ResetCamera()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Scripts/States/EditorMode/BIWGodMode.cs

#LineLine coverage
 1using DCL;
 2using DCL.Configuration;
 3using DCL.Controllers;
 4using DCL.Helpers;
 5using DCL.Models;
 6using System;
 7using System.Collections.Generic;
 8using DCL.Builder;
 9using DCL.Camera;
 10using UnityEngine;
 11using CameraController = DCL.Camera.CameraController;
 12using Environment = DCL.Environment;
 13
 14public class BIWGodMode : BIWMode
 15{
 3516    private float snapDragFactor = 5f;
 17    internal IFreeCameraMovement freeCameraController;
 18
 19    private Transform lookAtTransform;
 20    private MouseCatcher mouseCatcher;
 21    private PlayerAvatarController avatarRenderer;
 22    private IBIWGizmosController gizmoManager;
 23    private IBIWOutlinerController outlinerController;
 24
 25    private InputAction_Trigger focusOnSelectedEntitiesInputAction;
 26    private InputAction_Hold multiSelectionInputAction;
 27
 28    private IParcelScene sceneToEdit;
 29
 30    internal bool isPlacingNewObject = false;
 31    internal bool mouseMainBtnPressed = false;
 32    internal bool mouseSecondaryBtnPressed = false;
 33    internal bool isSquareMultiSelectionInputActive = false;
 34    internal bool isMouseDragging = false;
 35    internal bool changeSnapTemporaryButtonPressed = false;
 36
 37    internal bool wasGizmosActive = false;
 38    internal bool isDraggingStarted = false;
 39    internal bool canDragSelectedEntities = false;
 40
 41    internal Vector3 lastMousePosition;
 42    internal Vector3 dragStartedPoint;
 43
 44    public const float RAYCAST_MAX_DISTANCE = 10000f;
 45
 46    public override void Init(IContext context)
 47    {
 3548        base.Init(context);
 49
 3550        this.context = context;
 3551        lookAtTransform = new GameObject("BIWGodModeTransform").transform;
 3552        maxDistanceToSelectEntitiesValue = context.editorContext.godModeDynamicVariablesAsset.maxDistanceToSelectEntitie
 53
 3554        snapFactor = context.editorContext.godModeDynamicVariablesAsset.snapFactor;
 3555        snapRotationDegresFactor = context.editorContext.godModeDynamicVariablesAsset.snapRotationDegresFactor;
 3556        snapScaleFactor =  context.editorContext.godModeDynamicVariablesAsset.snapScaleFactor;
 3557        snapDistanceToActivateMovement =  context.editorContext.godModeDynamicVariablesAsset.snapDistanceToActivateMovem
 58
 3559        snapDragFactor = context.editorContext.godModeDynamicVariablesAsset.snapDragFactor;
 60
 3561        outlinerController = context.editorContext.outlinerController;
 3562        gizmoManager = context.editorContext.gizmosController;
 63
 3564        if ( context.editorContext.editorHUD != null)
 65        {
 3566            context.editorContext.editorHUD.OnTranslateSelectedAction += TranslateMode;
 3567            context.editorContext.editorHUD.OnRotateSelectedAction += RotateMode;
 3568            context.editorContext.editorHUD.OnScaleSelectedAction += ScaleMode;
 3569            context.editorContext.editorHUD.OnSelectedObjectPositionChange += UpdateSelectionPosition;
 3570            context.editorContext.editorHUD.OnSelectedObjectRotationChange += UpdateSelectionRotation;
 3571            context.editorContext.editorHUD.OnSelectedObjectScaleChange += UpdateSelectionScale;
 3572            context.editorContext.editorHUD.OnResetCameraAction += ResetCamera;
 73        }
 74
 3575        if (context.sceneReferences.cameraController.GetComponent<CameraController>().TryGetCameraStateByType<FreeCamera
 3576            freeCameraController = (FreeCameraMovement) cameraState;
 3577        mouseCatcher = context.sceneReferences.mouseCatcher.GetComponent<MouseCatcher>();
 3578        avatarRenderer = context.sceneReferences.playerAvatarController.GetComponent<PlayerAvatarController>();
 79
 3580        BIWInputWrapper.OnMouseDown += OnInputMouseDown;
 3581        BIWInputWrapper.OnMouseUp += OnInputMouseUp;
 3582        BIWInputWrapper.OnMouseUpOnUI += OnInputMouseUpOnUi;
 3583        BIWInputWrapper.OnMouseDrag += OnInputMouseDrag;
 84
 3585        focusOnSelectedEntitiesInputAction = context.inputsReferencesAsset.focusOnSelectedEntitiesInputAction;
 3586        multiSelectionInputAction = context.inputsReferencesAsset.multiSelectionInputAction;
 87
 3588        focusOnSelectedEntitiesInputAction.OnTriggered += (o) => FocusOnSelectedEntitiesInput();
 89
 3590        multiSelectionInputAction.OnStarted += MultiSelectionInputStart;
 3591        multiSelectionInputAction.OnFinished += MultiSelectionInputEnd;
 92
 3593        gizmoManager.OnChangeTransformValue += EntitiesTransfromByGizmos;
 3594        gizmoManager.OnGizmoTransformObjectEnd += OnGizmosTransformEnd;
 3595        gizmoManager.OnGizmoTransformObjectStart += OnGizmosTransformStart;
 3596    }
 97
 98    public override void Dispose()
 99    {
 35100        base.Dispose();
 101
 35102        isPlacingNewObject = false;
 103
 35104        gizmoManager.OnGizmoTransformObjectEnd -= OnGizmosTransformEnd;
 35105        gizmoManager.OnGizmoTransformObjectStart -= OnGizmosTransformStart;
 106
 35107        multiSelectionInputAction.OnStarted -= MultiSelectionInputStart;
 35108        multiSelectionInputAction.OnFinished -= MultiSelectionInputEnd;
 109
 35110        BIWInputWrapper.OnMouseDown -= OnInputMouseDown;
 35111        BIWInputWrapper.OnMouseUp -= OnInputMouseUp;
 35112        BIWInputWrapper.OnMouseUpOnUI -= OnInputMouseUpOnUi;
 35113        BIWInputWrapper.OnMouseDrag -= OnInputMouseDrag;
 114
 35115        gizmoManager.OnChangeTransformValue -= EntitiesTransfromByGizmos;
 116
 35117        if (lookAtTransform.gameObject != null)
 35118            GameObject.Destroy(lookAtTransform.gameObject);
 119
 35120        if ( context.editorContext.editorHUD == null)
 0121            return;
 122
 35123        context.editorContext.editorHUD.OnSelectedObjectPositionChange -= UpdateSelectionPosition;
 35124        context.editorContext.editorHUD.OnSelectedObjectRotationChange -= UpdateSelectionRotation;
 35125        context.editorContext.editorHUD.OnSelectedObjectScaleChange -= UpdateSelectionScale;
 35126        context.editorContext.editorHUD.OnTranslateSelectedAction -= TranslateMode;
 35127        context.editorContext.editorHUD.OnRotateSelectedAction -= RotateMode;
 35128        context.editorContext.editorHUD.OnScaleSelectedAction -= ScaleMode;
 35129        context.editorContext.editorHUD.OnResetCameraAction -= ResetCamera;
 35130    }
 131
 132    public override void Update()
 133    {
 0134        base.Update();
 135
 0136        if (isPlacingNewObject)
 0137            SetEditObjectAtMouse();
 0138        else if (isSquareMultiSelectionInputActive && isMouseDragging)
 0139            CheckOutlineEntitiesInSquareSelection(Input.mousePosition);
 140
 0141    }
 142
 143    public override void OnGUI()
 144    {
 0145        base.OnGUI();
 0146        if (mouseMainBtnPressed && isSquareMultiSelectionInputActive)
 147        {
 0148            var rect = BIWUtils.GetScreenRect(lastMousePosition, Input.mousePosition);
 0149            BIWUtils.DrawScreenRect(rect, new Color(1f, 1f, 1f, 0.25f));
 0150            BIWUtils.DrawScreenRectBorder(rect, 1, Color.white);
 151        }
 0152    }
 153
 154    private void MultiSelectionInputStart(DCLAction_Hold action)
 155    {
 2156        ChangeSnapTemporaryActivated();
 2157    }
 158
 159    private void MultiSelectionInputEnd(DCLAction_Hold action)
 160    {
 33161        ChangeSnapTemporaryDeactivated();
 33162    }
 163
 164    internal void CheckOutlineEntitiesInSquareSelection(Vector3 mousePosition)
 165    {
 166        List<BIWEntity> allEntities = null;
 167
 1168        allEntities = entityHandler.GetAllEntitiesFromCurrentScene();
 169
 4170        foreach (BIWEntity entity in allEntities)
 171        {
 1172            if (!entity.rootEntity.meshRootGameObject || entity.rootEntity.meshesInfo.renderers.Length <= 0)
 173                continue;
 174
 1175            if (BIWUtils.IsWithinSelectionBounds(entity.rootEntity.meshesInfo.mergedBounds.center, lastMousePosition, mo
 1176                outlinerController.OutlineEntity(entity);
 177            else
 0178                outlinerController.CancelEntityOutline(entity);
 179        }
 1180    }
 181
 182    private void ChangeSnapTemporaryDeactivated()
 183    {
 33184        if (changeSnapTemporaryButtonPressed)
 2185            SetSnapActive(!isSnapActiveValue);
 186
 33187        changeSnapTemporaryButtonPressed = false;
 33188    }
 189
 190    private void ChangeSnapTemporaryActivated()
 191    {
 2192        if (selectedEntities.Count == 0)
 0193            return;
 194
 2195        changeSnapTemporaryButtonPressed = true;
 196
 2197        SetSnapActive(!isSnapActiveValue);
 2198    }
 199
 200    internal void EntitiesTransfromByGizmos(Vector3 transformValue)
 201    {
 1202        if (gizmoManager.GetSelectedGizmo() != BIWSettings.ROTATE_GIZMO_NAME)
 0203            return;
 204
 4205        foreach (BIWEntity entity in selectedEntities)
 206        {
 1207            entity.AddRotation(transformValue);
 208        }
 1209    }
 210
 211    public void UpdateSelectionPosition(Vector3 newPosition)
 212    {
 1213        if (selectedEntities.Count != 1)
 0214            return;
 215
 1216        TransformActionStarted(selectedEntities[0].rootEntity, BIWSettings.TRANSLATE_GIZMO_NAME);
 1217        editionGO.transform.position = WorldStateUtils.ConvertSceneToUnityPosition(newPosition, sceneToEdit);
 1218        gizmoManager.SetSelectedEntities(editionGO.transform, selectedEntities);
 1219        TransformActionEnd(selectedEntities[0].rootEntity, BIWSettings.TRANSLATE_GIZMO_NAME);
 1220        ActionFinish(IBIWCompleteAction.ActionType.MOVE);
 1221        entityHandler.ReportTransform(true);
 1222        saveController.TryToSave();
 1223    }
 224
 225    public void UpdateSelectionRotation(Vector3 rotation)
 226    {
 1227        if (selectedEntities.Count != 1)
 0228            return;
 229
 1230        TransformActionStarted(selectedEntities[0].rootEntity, BIWSettings.ROTATE_GIZMO_NAME);
 1231        selectedEntities[0].rootEntity.gameObject.transform.rotation = Quaternion.Euler(rotation);
 1232        TransformActionEnd(selectedEntities[0].rootEntity, BIWSettings.ROTATE_GIZMO_NAME);
 1233        ActionFinish(IBIWCompleteAction.ActionType.ROTATE);
 1234        entityHandler.ReportTransform(true);
 1235        saveController.TryToSave();
 1236    }
 237
 238    public void UpdateSelectionScale(Vector3 scale)
 239    {
 1240        if (selectedEntities.Count != 1)
 0241            return;
 242
 1243        var entityToUpdate = selectedEntities[0];
 244
 1245        TransformActionStarted(entityToUpdate.rootEntity, BIWSettings.SCALE_GIZMO_NAME);
 246        // Before change the scale, we unparent the entity to not to make it dependant on the editionGO and after that, 
 1247        entityToUpdate.rootEntity.gameObject.transform.SetParent(null);
 1248        entityToUpdate.rootEntity.gameObject.transform.localScale = scale;
 1249        editionGO.transform.localScale = Vector3.one;
 1250        entityToUpdate.rootEntity.gameObject.transform.SetParent(editionGO.transform);
 251
 1252        TransformActionEnd(entityToUpdate.rootEntity, BIWSettings.SCALE_GIZMO_NAME);
 1253        ActionFinish(IBIWCompleteAction.ActionType.SCALE);
 1254        entityHandler.ReportTransform(true);
 1255        saveController.TryToSave();
 1256    }
 257
 258    internal void DragEditionGameObject(Vector3 mousePosition)
 259    {
 1260        Vector3 currentPoint = raycastController.GetFloorPointAtMouse(mousePosition);
 1261        Vector3 initialEntityPosition = editionGO.transform.position;
 262
 1263        if (isSnapActiveValue)
 264        {
 0265            currentPoint = GetPositionRoundedToSnapFactor(currentPoint);
 0266            initialEntityPosition = GetPositionRoundedToSnapFactor(initialEntityPosition);
 267        }
 268
 1269        Vector3 move = currentPoint - dragStartedPoint;
 1270        Vector3 destination = initialEntityPosition + move;
 271
 1272        editionGO.transform.position = destination;
 1273        dragStartedPoint = currentPoint;
 1274    }
 275
 276    #region Mouse
 277
 278    public override void MouseClickDetected()
 279    {
 1280        if (isPlacingNewObject)
 281        {
 1282            entityHandler.DeselectEntities();
 1283            saveController.TryToSave();
 1284            return;
 285        }
 286
 0287        base.MouseClickDetected();
 0288    }
 289
 290    internal void OnInputMouseDrag(int buttonId, Vector3 mousePosition, float axisX, float axisY)
 291    {
 1292        if (Vector3.Distance(lastMousePosition, mousePosition) <= BIWSettings.MOUSE_THRESHOLD_FOR_DRAG && !isMouseDraggi
 0293            return;
 294
 1295        isMouseDragging = true;
 1296        if (buttonId != 0 ||
 297            selectedEntities.Count <= 0 ||
 298            BIWUtils.IsPointerOverMaskElement(BIWSettings.GIZMOS_LAYER) ||
 299            isSquareMultiSelectionInputActive)
 1300            return;
 301
 0302        if (!isDraggingStarted)
 0303            StarDraggingSelectedEntities();
 304
 0305        if (canDragSelectedEntities)
 0306            DragEditionGameObject(mousePosition);
 0307    }
 308
 309    internal Vector3 GetPositionRoundedToSnapFactor(Vector3 position)
 310    {
 0311        position = new Vector3(
 312            Mathf.Round(position.x / snapDragFactor) * snapDragFactor,
 313            position.y,
 314            Mathf.Round(position.z / snapDragFactor) * snapDragFactor);
 315
 0316        return position;
 317    }
 318
 319    internal void OnInputMouseUpOnUi(int buttonID, Vector3 position)
 320    {
 1321        if (buttonID == 1)
 322        {
 0323            mouseSecondaryBtnPressed = false;
 0324            freeCameraController.StopDetectingMovement();
 325        }
 326
 1327        if (buttonID != 0)
 0328            return;
 329
 1330        CheckEndBoundMultiselection(position);
 1331        isMouseDragging = false;
 1332    }
 333
 334    internal void OnInputMouseUp(int buttonID, Vector3 position)
 335    {
 1336        if (buttonID == 1)
 337        {
 0338            mouseSecondaryBtnPressed = false;
 0339            if (CanCancelAction(position))
 0340                entityHandler.CancelSelection();
 341
 0342            freeCameraController.StopDetectingMovement();
 343        }
 344
 1345        if (buttonID != 0)
 0346            return;
 347
 1348        EndDraggingSelectedEntities();
 349
 1350        CheckEndBoundMultiselection(position);
 351
 1352        outlinerController.SetOutlineCheckActive(true);
 353
 1354        isMouseDragging = false;
 1355    }
 356
 357    internal void OnInputMouseDown(int buttonID, Vector3 position)
 358    {
 1359        lastMousePosition = position;
 360
 1361        if (buttonID == 1)
 362        {
 0363            mouseSecondaryBtnPressed = true;
 0364            freeCameraController.StartDectectingMovement();
 365        }
 366
 1367        if (buttonID != 0)
 0368            return;
 369
 1370        dragStartedPoint = raycastController.GetFloorPointAtMouse(position);
 371
 1372        if (isSnapActiveValue)
 373        {
 0374            dragStartedPoint.x = Mathf.Round(dragStartedPoint.x);
 0375            dragStartedPoint.z = Mathf.Round(dragStartedPoint.z);
 376        }
 377
 1378        if (isPlacingNewObject)
 0379            return;
 380
 1381        var entity = raycastController.GetEntityOnPointer();
 1382        if ((entity == null
 383             || (entity != null && !entity.isSelected))
 384            && !BIWUtils.IsPointerOverMaskElement(BIWSettings.GIZMOS_LAYER))
 385        {
 1386            isSquareMultiSelectionInputActive = true;
 1387            outlinerController.SetOutlineCheckActive(false);
 388        }
 389
 1390        mouseMainBtnPressed = true;
 1391        freeCameraController.SetCameraCanMove(false);
 1392    }
 393
 394    #endregion
 395
 396    private void CheckEndBoundMultiselection(Vector3 position)
 397    {
 2398        if (isSquareMultiSelectionInputActive && mouseMainBtnPressed )
 399        {
 0400            if (Vector3.Distance(lastMousePosition, position) >= BIWSettings.MOUSE_THRESHOLD_FOR_DRAG)
 0401                EndBoundMultiSelection(Input.mousePosition);
 402
 0403            isSquareMultiSelectionInputActive = false;
 0404            mouseMainBtnPressed = false;
 405        }
 2406    }
 407
 0408    private bool CanCancelAction(Vector3 currentMousePosition) { return Vector3.Distance(lastMousePosition, currentMouse
 409
 410    internal void StarDraggingSelectedEntities()
 411    {
 2412        if (!entityHandler.IsPointerInSelectedEntity() ||
 413            gizmoManager.HasAxisHover())
 1414            return;
 415
 1416        if (gizmoManager.IsGizmoActive())
 417        {
 1418            gizmoManager.HideGizmo();
 1419            wasGizmosActive = true;
 420        }
 421
 1422        freeCameraController.SetCameraCanMove(false);
 1423        isDraggingStarted = true;
 424
 1425        canDragSelectedEntities = true;
 1426    }
 427
 428    internal void EndDraggingSelectedEntities()
 429    {
 2430        if (wasGizmosActive && !isPlacingNewObject)
 431        {
 0432            gizmoManager.ShowGizmo();
 0433            saveController.TryToSave();
 434        }
 435
 2436        wasGizmosActive = false;
 437
 2438        freeCameraController.SetCameraCanMove(true);
 2439        isDraggingStarted = false;
 440
 2441        canDragSelectedEntities = false;
 2442    }
 443
 444    internal void EndBoundMultiSelection(Vector3 mousePosition)
 445    {
 1446        freeCameraController.SetCameraCanMove(true);
 447        List<BIWEntity> allEntities = null;
 448
 1449        allEntities = entityHandler.GetAllEntitiesFromCurrentScene();
 450
 1451        List<BIWEntity> selectedInsideBoundsEntities = new List<BIWEntity>();
 1452        int alreadySelectedEntities = 0;
 453
 1454        if (!isMultiSelectionActive)
 1455            entityHandler.DeselectEntities();
 456
 4457        foreach (BIWEntity entity in allEntities)
 458        {
 1459            if (entity.rootEntity.meshRootGameObject && entity.rootEntity.meshesInfo.renderers.Length > 0)
 460            {
 1461                if (BIWUtils.IsWithinSelectionBounds(entity.rootEntity.meshesInfo.mergedBounds.center, lastMousePosition
 462                    && !entity.isLocked)
 463                {
 1464                    if (entity.isSelected)
 0465                        alreadySelectedEntities++;
 466
 1467                    entityHandler.SelectEntity(entity);
 1468                    selectedInsideBoundsEntities.Add(entity);
 469                }
 470            }
 471        }
 472
 1473        if (selectedInsideBoundsEntities.Count == alreadySelectedEntities && alreadySelectedEntities > 0)
 474        {
 0475            foreach (BIWEntity entity in selectedInsideBoundsEntities)
 476            {
 0477                entityHandler.DeselectEntity(entity);
 478            }
 479        }
 480
 1481        outlinerController.CancelAllOutlines();
 1482    }
 483
 484    public override void Activate(IParcelScene scene)
 485    {
 39486        base.Activate(scene);
 39487        sceneToEdit = scene;
 488
 39489        SetLookAtObject(scene);
 490
 39491        ConfigureCamera(scene);
 492
 39493        if (gizmoManager.GetSelectedGizmo() == DCL.Components.DCLGizmos.Gizmo.NONE)
 32494            gizmoManager.SetGizmoType(BIWSettings.TRANSLATE_GIZMO_NAME);
 39495        mouseCatcher.enabled = false;
 39496        Environment.i.world.sceneController.IsolateScene(sceneToEdit);
 39497        Utils.UnlockCursor();
 498
 39499        gizmoManager.HideGizmo();
 39500        editionGO.transform.SetParent(null);
 39501        avatarRenderer.SetAvatarVisibility(false);
 502
 39503        context.editorContext.editorHUD?.ActivateGodModeUI();
 39504    }
 505
 506    public void ConfigureCamera(IParcelScene parcelScene)
 507    {
 39508        freeCameraController.gameObject.SetActive(true);
 39509        SetLookAtObject(parcelScene);
 510
 39511        freeCameraController.LookAt(lookAtTransform);
 39512        freeCameraController.SetResetConfiguration(Camera.main.transform.position, lookAtTransform);
 39513    }
 514
 515    public override void OnDeleteEntity(BIWEntity entity)
 516    {
 0517        base.OnDeleteEntity(entity);
 0518        saveController.TryToSave();
 519
 0520        if (selectedEntities.Count == 0)
 0521            gizmoManager.HideGizmo();
 0522    }
 523
 524    public override void OnDeselectedEntities()
 525    {
 0526        base.OnDeselectedEntities();
 0527        gizmoManager.SetSelectedEntities(editionGO.transform, new List<BIWEntity>());
 0528    }
 529
 530    public override void Deactivate()
 531    {
 5532        base.Deactivate();
 5533        mouseCatcher.enabled = true;
 5534        Utils.LockCursor();
 535
 5536        Environment.i.world.sceneController.ReIntegrateIsolatedScene();
 537
 5538        gizmoManager.HideGizmo();
 5539        RenderSettings.fog = true;
 5540        avatarRenderer.SetAvatarVisibility(true);
 5541    }
 542
 543    public override void StartMultiSelection()
 544    {
 1545        base.StartMultiSelection();
 546
 1547        snapGO.transform.SetParent(null);
 1548        freeMovementGO.transform.SetParent(null);
 1549    }
 550
 551    public override void SetDuplicationOffset(float offset)
 552    {
 0553        base.SetDuplicationOffset(offset);
 0554        editionGO.transform.position += Vector3.right * offset;
 0555    }
 556
 557    public override void CreatedEntity(BIWEntity createdEntity)
 558    {
 1559        base.CreatedEntity(createdEntity);
 560
 1561        if (!createdEntity.isFloor)
 562        {
 1563            isPlacingNewObject = true;
 1564            outlinerController.SetOutlineCheckActive(false);
 565
 1566            SetEditObjectAtMouse();
 567        }
 568
 1569        gizmoManager.HideGizmo();
 1570        if (createdEntity.isVoxel)
 0571            createdEntity.rootEntity.gameObject.tag = BIWSettings.VOXEL_TAG;
 1572    }
 573
 0574    public override Vector3 GetCreatedEntityPoint() { return raycastController.GetFloorPointAtMouse(Input.mousePosition)
 575
 576    public override void SelectedEntity(BIWEntity selectedEntity)
 577    {
 1578        base.SelectedEntity(selectedEntity);
 579
 1580        gizmoManager.SetSelectedEntities(editionGO.transform, selectedEntities);
 581
 1582        if (!isMultiSelectionActive && !selectedEntity.isNew)
 1583            TryLookAtEntity(selectedEntity.rootEntity);
 584
 1585        snapGO.transform.SetParent(null);
 586
 1587        UpdateActionsInteractable();
 1588    }
 589
 590    public override void EntityDeselected(BIWEntity entityDeselected)
 591    {
 1592        base.EntityDeselected(entityDeselected);
 1593        if (selectedEntities.Count <= 0)
 594        {
 0595            gizmoManager.HideGizmo();
 0596            UpdateActionsInteractable();
 597        }
 598
 1599        if (isPlacingNewObject)
 1600            outlinerController.SetOutlineCheckActive(true);
 1601        isPlacingNewObject = false;
 1602    }
 603
 604    public override void EntityDoubleClick(BIWEntity entity)
 605    {
 0606        base.EntityDoubleClick(entity);
 0607        if (!entity.isLocked)
 0608            LookAtEntity(entity.rootEntity);
 0609    }
 610
 611    private void UpdateActionsInteractable()
 612    {
 1613        bool areInteratable = selectedEntities.Count > 0;
 1614        if ( context.editorContext.editorHUD != null)
 1615            context.editorContext.editorHUD.SetActionsButtonsInteractable(areInteratable);
 1616    }
 617
 618    public override bool ShouldCancelUndoAction()
 619    {
 1620        if (isPlacingNewObject)
 621        {
 1622            entityHandler.DestroyLastCreatedEntities();
 1623            isPlacingNewObject = false;
 1624            return true;
 625        }
 626
 0627        return false;
 628    }
 629
 630    public override void SetSnapActive(bool isActive)
 631    {
 43632        base.SetSnapActive(isActive);
 633
 43634        if (isSnapActiveValue)
 635        {
 2636            gizmoManager.SetSnapFactor(snapFactor, snapRotationDegresFactor, snapScaleFactor);
 2637        }
 638        else
 639        {
 41640            gizmoManager.SetSnapFactor(0, 0, 0);
 641        }
 41642    }
 643
 644    public void FocusOnSelectedEntitiesInput()
 645    {
 0646        if (isModeActive)
 647        {
 0648            FocusEntities(selectedEntities);
 0649            InputDone();
 650        }
 0651    }
 652
 653    public void TryLookAtEntity(IDCLEntity entity)
 654    {
 1655        if (entity.meshRootGameObject == null
 656            || entity.meshesInfo == null
 657            || BIWUtils.IsBoundInsideCamera(entity.meshesInfo.mergedBounds))
 1658            return;
 659
 0660        LookAtEntity(entity);
 0661    }
 662
 663    public void LookAtEntity(IDCLEntity entity)
 664    {
 1665        Vector3 pointToLook = entity.gameObject.transform.position;
 1666        if (entity.meshesInfo != null && entity.meshesInfo.renderers.Length > 0)
 0667            pointToLook = CalculateEntityMidPoint(entity);
 668
 1669        freeCameraController.SmoothLookAt(pointToLook);
 1670    }
 671
 672    internal Vector3 CalculateEntityMidPoint(IDCLEntity entity)
 673    {
 1674        Vector3 midPointFromEntityMesh = Vector3.zero;
 4675        foreach (Renderer render in entity.renderers)
 676        {
 1677            if (render == null)
 678                continue;
 1679            midPointFromEntityMesh += render.bounds.center;
 680        }
 681
 1682        midPointFromEntityMesh /= entity.renderers.Length;
 1683        return midPointFromEntityMesh;
 684    }
 685
 686    #region Gizmos
 687
 12688    public void TranslateMode() { GizmosMode( BIWSettings.TRANSLATE_GIZMO_NAME); }
 689
 8690    public void RotateMode() { GizmosMode( BIWSettings.ROTATE_GIZMO_NAME); }
 691
 4692    public void ScaleMode() { GizmosMode( BIWSettings.SCALE_GIZMO_NAME); }
 693
 694    private void GizmosMode(string gizmos)
 695    {
 12696        if ((!isModeActive && isPlacingNewObject) || mouseSecondaryBtnPressed)
 0697            return;
 12698        if (gizmoManager.GetSelectedGizmo() != gizmos)
 699        {
 7700            context.editorContext.editorHUD?.SetGizmosActive(gizmos);
 7701            gizmoManager.SetGizmoType(gizmos);
 7702            if (selectedEntities.Count > 0 )
 0703                gizmoManager.ShowGizmo();
 704        }
 705        //TODO: Free-Movement tool, This could be re-enabled in the future so let the code there
 706        // else
 707        // {
 708        //     gizmoManager.HideGizmo(true);
 709        //      context.editorContext.editorHUD?.SetGizmosActive(BIWSettings.EMPTY_GIZMO_NAME);
 710        // }
 12711    }
 712
 713    internal void OnGizmosTransformStart(string gizmoType)
 714    {
 2715        outlinerController.SetOutlineCheckActive(false);
 8716        foreach (BIWEntity entity in selectedEntities)
 717        {
 2718            TransformActionStarted(entity.rootEntity, gizmoType);
 719        }
 2720    }
 721
 722    internal void OnGizmosTransformEnd(string gizmoType)
 723    {
 1724        outlinerController.SetOutlineCheckActive(true);
 4725        foreach (BIWEntity entity in selectedEntities)
 726        {
 1727            TransformActionEnd(entity.rootEntity, gizmoType);
 728        }
 729
 730        switch (gizmoType)
 731        {
 732            case BIWSettings.TRANSLATE_GIZMO_NAME:
 733
 1734                ActionFinish(IBIWCompleteAction.ActionType.MOVE);
 1735                break;
 736            case BIWSettings.ROTATE_GIZMO_NAME:
 0737                ActionFinish(IBIWCompleteAction.ActionType.ROTATE);
 0738                break;
 739            case BIWSettings.SCALE_GIZMO_NAME:
 0740                ActionFinish(IBIWCompleteAction.ActionType.SCALE);
 741                break;
 742        }
 743
 1744        saveController.TryToSave();
 1745    }
 746
 747    #endregion
 748
 2749    public void FocusEntities(List<BIWEntity> entitiesToFocus) { freeCameraController.FocusOnEntities(entitiesToFocus); 
 750
 751    internal void SetLookAtObject(IParcelScene parcelScene)
 752    {
 78753        Vector3 middlePoint = BIWUtils.CalculateUnityMiddlePoint(parcelScene);
 78754        lookAtTransform.position = middlePoint;
 78755    }
 756
 757    internal void SetEditObjectAtMouse()
 758    {
 1759        if (raycastController.RayCastFloor(out Vector3 destination))
 760        {
 1761            if (isSnapActiveValue)
 762            {
 0763                destination.x = Mathf.Round(destination.x / snapDragFactor) * snapDragFactor;
 0764                destination.z = Mathf.Round(destination.z / snapDragFactor) * snapDragFactor;
 765            }
 766
 1767            editionGO.transform.position = destination;
 768
 1769            if (selectedEntities.Count > 0 && selectedEntities[0].isNFT)
 0770                editionGO.transform.position += Vector3.up * 2f;
 771        }
 1772    }
 773
 2774    internal void ResetCamera() { freeCameraController.ResetCameraPosition(); }
 775}

Methods/Properties

BIWGodMode()
Init(DCL.Builder.IContext)
Dispose()
Update()
OnGUI()
MultiSelectionInputStart(DCLAction_Hold)
MultiSelectionInputEnd(DCLAction_Hold)
CheckOutlineEntitiesInSquareSelection(UnityEngine.Vector3)
ChangeSnapTemporaryDeactivated()
ChangeSnapTemporaryActivated()
EntitiesTransfromByGizmos(UnityEngine.Vector3)
UpdateSelectionPosition(UnityEngine.Vector3)
UpdateSelectionRotation(UnityEngine.Vector3)
UpdateSelectionScale(UnityEngine.Vector3)
DragEditionGameObject(UnityEngine.Vector3)
MouseClickDetected()
OnInputMouseDrag(System.Int32, UnityEngine.Vector3, System.Single, System.Single)
GetPositionRoundedToSnapFactor(UnityEngine.Vector3)
OnInputMouseUpOnUi(System.Int32, UnityEngine.Vector3)
OnInputMouseUp(System.Int32, UnityEngine.Vector3)
OnInputMouseDown(System.Int32, UnityEngine.Vector3)
CheckEndBoundMultiselection(UnityEngine.Vector3)
CanCancelAction(UnityEngine.Vector3)
StarDraggingSelectedEntities()
EndDraggingSelectedEntities()
EndBoundMultiSelection(UnityEngine.Vector3)
Activate(DCL.Controllers.IParcelScene)
ConfigureCamera(DCL.Controllers.IParcelScene)
OnDeleteEntity(BIWEntity)
OnDeselectedEntities()
Deactivate()
StartMultiSelection()
SetDuplicationOffset(System.Single)
CreatedEntity(BIWEntity)
GetCreatedEntityPoint()
SelectedEntity(BIWEntity)
EntityDeselected(BIWEntity)
EntityDoubleClick(BIWEntity)
UpdateActionsInteractable()
ShouldCancelUndoAction()
SetSnapActive(System.Boolean)
FocusOnSelectedEntitiesInput()
TryLookAtEntity(DCL.Models.IDCLEntity)
LookAtEntity(DCL.Models.IDCLEntity)
CalculateEntityMidPoint(DCL.Models.IDCLEntity)
TranslateMode()
RotateMode()
ScaleMode()
GizmosMode(System.String)
OnGizmosTransformStart(System.String)
OnGizmosTransformEnd(System.String)
FocusEntities(System.Collections.Generic.List[BIWEntity])
SetLookAtObject(DCL.Controllers.IParcelScene)
SetEditObjectAtMouse()
ResetCamera()