< Summary

Class:BIWGodMode
Assembly:BuilderInWorld
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Scripts/States/EditorMode/BIWGodMode.cs
Covered lines:285
Uncovered lines:98
Coverable lines:383
Total lines:777
Line coverage:74.4% (285 of 383)
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%
EntitiesTransformByGizmos(...)0%3.033085.71%
UpdateSelectionPosition(...)0%22090%
UpdateSelectionRotation(...)0%2.012088.89%
UpdateSelectionScale(...)0%22092.31%
DragEditionGameObject(...)0%6200%
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%220100%
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.Collections.Generic;
 7using DCL.Builder;
 8using DCL.Camera;
 9using CameraController = DCL.Camera.CameraController;
 10using Environment = DCL.Environment;
 11using UnityEngine;
 12
 13public class BIWGodMode : BIWMode
 14{
 3415    private float snapDragFactor = 5f;
 16    internal IFreeCameraMovement freeCameraController;
 17
 18    private Transform lookAtTransform;
 19    private MouseCatcher mouseCatcher;
 20    private PlayerAvatarController avatarRenderer;
 21    private IBIWGizmosController gizmoManager;
 22    private IBIWOutlinerController outlinerController;
 23
 24    private InputAction_Trigger focusOnSelectedEntitiesInputAction;
 25    private InputAction_Hold multiSelectionInputAction;
 26
 27    private IParcelScene sceneToEdit;
 28
 29    internal bool isPlacingNewObject = false;
 30    internal bool mouseMainBtnPressed = false;
 31    internal bool mouseSecondaryBtnPressed = false;
 32    internal bool isSquareMultiSelectionInputActive = false;
 33    internal bool isMouseDragging = false;
 34    internal bool changeSnapTemporaryButtonPressed = false;
 35
 36    internal bool wasGizmosActive = false;
 37    internal bool isDraggingStarted = false;
 38    internal bool canDragSelectedEntities = false;
 39
 40    internal Vector3 lastMousePosition;
 41    internal Vector3 dragStartedPoint;
 42
 43    public const float RAYCAST_MAX_DISTANCE = 10000f;
 44
 45    public override void Init(IContext context)
 46    {
 3447        base.Init(context);
 48
 3449        this.context = context;
 3450        lookAtTransform = new GameObject("BIWGodModeTransform").transform;
 3451        maxDistanceToSelectEntitiesValue = context.editorContext.godModeDynamicVariablesAsset.maxDistanceToSelectEntitie
 52
 3453        snapFactor = context.editorContext.godModeDynamicVariablesAsset.snapFactor;
 3454        snapRotationDegresFactor = context.editorContext.godModeDynamicVariablesAsset.snapRotationDegresFactor;
 3455        snapScaleFactor =  context.editorContext.godModeDynamicVariablesAsset.snapScaleFactor;
 3456        snapDistanceToActivateMovement =  context.editorContext.godModeDynamicVariablesAsset.snapDistanceToActivateMovem
 57
 3458        snapDragFactor = context.editorContext.godModeDynamicVariablesAsset.snapDragFactor;
 59
 3460        outlinerController = context.editorContext.outlinerController;
 3461        gizmoManager = context.editorContext.gizmosController;
 62
 3463        if ( context.editorContext.editorHUD != null)
 64        {
 3465            context.editorContext.editorHUD.OnTranslateSelectedAction += TranslateMode;
 3466            context.editorContext.editorHUD.OnRotateSelectedAction += RotateMode;
 3467            context.editorContext.editorHUD.OnScaleSelectedAction += ScaleMode;
 3468            context.editorContext.editorHUD.OnSelectedObjectPositionChange += UpdateSelectionPosition;
 3469            context.editorContext.editorHUD.OnSelectedObjectRotationChange += UpdateSelectionRotation;
 3470            context.editorContext.editorHUD.OnSelectedObjectScaleChange += UpdateSelectionScale;
 3471            context.editorContext.editorHUD.OnResetCameraAction += ResetCamera;
 72        }
 73
 3474        if (context.sceneReferences.cameraController.GetComponent<CameraController>().TryGetCameraStateByType<FreeCamera
 3475            freeCameraController = (FreeCameraMovement) cameraState;
 76
 3477        mouseCatcher = context.sceneReferences.mouseCatcher.GetComponent<MouseCatcher>();
 3478        avatarRenderer = context.sceneReferences.playerAvatarController.GetComponent<PlayerAvatarController>();
 79
 3480        BIWInputWrapper.OnMouseDown += OnInputMouseDown;
 3481        BIWInputWrapper.OnMouseUp += OnInputMouseUp;
 3482        BIWInputWrapper.OnMouseUpOnUI += OnInputMouseUpOnUi;
 3483        BIWInputWrapper.OnMouseDrag += OnInputMouseDrag;
 84
 3485        focusOnSelectedEntitiesInputAction = context.inputsReferencesAsset.focusOnSelectedEntitiesInputAction;
 3486        multiSelectionInputAction = context.inputsReferencesAsset.multiSelectionInputAction;
 87
 3488        focusOnSelectedEntitiesInputAction.OnTriggered += (o) => FocusOnSelectedEntitiesInput();
 89
 3490        multiSelectionInputAction.OnStarted += MultiSelectionInputStart;
 3491        multiSelectionInputAction.OnFinished += MultiSelectionInputEnd;
 92
 3493        gizmoManager.OnChangeTransformValue += EntitiesTransformByGizmos;
 3494        gizmoManager.OnGizmoTransformObjectEnd += OnGizmosTransformEnd;
 3495        gizmoManager.OnGizmoTransformObjectStart += OnGizmosTransformStart;
 3496    }
 97
 98    public override void Dispose()
 99    {
 34100        base.Dispose();
 101
 34102        isPlacingNewObject = false;
 103
 34104        gizmoManager.OnGizmoTransformObjectEnd -= OnGizmosTransformEnd;
 34105        gizmoManager.OnGizmoTransformObjectStart -= OnGizmosTransformStart;
 106
 34107        multiSelectionInputAction.OnStarted -= MultiSelectionInputStart;
 34108        multiSelectionInputAction.OnFinished -= MultiSelectionInputEnd;
 109
 34110        BIWInputWrapper.OnMouseDown -= OnInputMouseDown;
 34111        BIWInputWrapper.OnMouseUp -= OnInputMouseUp;
 34112        BIWInputWrapper.OnMouseUpOnUI -= OnInputMouseUpOnUi;
 34113        BIWInputWrapper.OnMouseDrag -= OnInputMouseDrag;
 114
 34115        gizmoManager.OnChangeTransformValue -= EntitiesTransformByGizmos;
 116
 34117        if (lookAtTransform.gameObject != null)
 34118            Object.Destroy(lookAtTransform.gameObject);
 119
 34120        if ( context.editorContext.editorHUD == null)
 0121            return;
 122
 34123        context.editorContext.editorHUD.OnSelectedObjectPositionChange -= UpdateSelectionPosition;
 34124        context.editorContext.editorHUD.OnSelectedObjectRotationChange -= UpdateSelectionRotation;
 34125        context.editorContext.editorHUD.OnSelectedObjectScaleChange -= UpdateSelectionScale;
 34126        context.editorContext.editorHUD.OnTranslateSelectedAction -= TranslateMode;
 34127        context.editorContext.editorHUD.OnRotateSelectedAction -= RotateMode;
 34128        context.editorContext.editorHUD.OnScaleSelectedAction -= ScaleMode;
 34129        context.editorContext.editorHUD.OnResetCameraAction -= ResetCamera;
 34130    }
 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);
 0140    }
 141
 142    public override void OnGUI()
 143    {
 0144        base.OnGUI();
 0145        if (mouseMainBtnPressed && isSquareMultiSelectionInputActive)
 146        {
 0147            var rect = BIWUtils.GetScreenRect(lastMousePosition, Input.mousePosition);
 0148            BIWUtils.DrawScreenRect(rect, new Color(1f, 1f, 1f, 0.25f));
 0149            BIWUtils.DrawScreenRectBorder(rect, 1, Color.white);
 150        }
 0151    }
 152
 153    private void MultiSelectionInputStart(DCLAction_Hold action)
 154    {
 2155        ChangeSnapTemporaryActivated();
 2156    }
 157
 158    private void MultiSelectionInputEnd(DCLAction_Hold action)
 159    {
 32160        ChangeSnapTemporaryDeactivated();
 32161    }
 162
 163    internal void CheckOutlineEntitiesInSquareSelection(Vector3 mousePosition)
 164    {
 165        List<BIWEntity> allEntities = null;
 166
 1167        allEntities = entityHandler.GetAllEntitiesFromCurrentScene();
 168
 4169        foreach (BIWEntity entity in allEntities)
 170        {
 1171            if (!entity.rootEntity.meshRootGameObject || entity.rootEntity.meshesInfo.renderers.Length <= 0)
 172                continue;
 173
 1174            if (BIWUtils.IsWithinSelectionBounds(entity.rootEntity.meshesInfo.mergedBounds.center, lastMousePosition, mo
 1175                outlinerController.OutlineEntity(entity);
 176            else
 0177                outlinerController.CancelEntityOutline(entity);
 178        }
 1179    }
 180
 181    private void ChangeSnapTemporaryDeactivated()
 182    {
 32183        if (changeSnapTemporaryButtonPressed)
 2184            SetSnapActive(!isSnapActiveValue);
 185
 32186        changeSnapTemporaryButtonPressed = false;
 32187    }
 188
 189    private void ChangeSnapTemporaryActivated()
 190    {
 2191        if (selectedEntities.Count == 0)
 0192            return;
 193
 2194        changeSnapTemporaryButtonPressed = true;
 195
 2196        SetSnapActive(!isSnapActiveValue);
 2197    }
 198
 199    internal void EntitiesTransformByGizmos(Vector3 transformValue)
 200    {
 1201        if (gizmoManager.GetSelectedGizmo() != BIWSettings.ROTATE_GIZMO_NAME)
 0202            return;
 203
 4204        foreach (BIWEntity entity in selectedEntities)
 205        {
 1206            entity.AddRotation(transformValue);
 207        }
 1208    }
 209
 210    public void UpdateSelectionPosition(Vector3 newPosition)
 211    {
 1212        if (selectedEntities.Count != 1)
 0213            return;
 214
 1215        TransformActionStarted(selectedEntities[0].rootEntity, BIWSettings.TRANSLATE_GIZMO_NAME);
 1216        editionGO.transform.position = WorldStateUtils.ConvertSceneToUnityPosition(newPosition, sceneToEdit);
 1217        gizmoManager.SetSelectedEntities(editionGO.transform, selectedEntities);
 1218        TransformActionEnd(selectedEntities[0].rootEntity, BIWSettings.TRANSLATE_GIZMO_NAME);
 1219        ActionFinish(IBIWCompleteAction.ActionType.MOVE);
 1220        entityHandler.ReportTransform(true);
 1221        saveController.TryToSave();
 1222    }
 223
 224    public void UpdateSelectionRotation(Vector3 rotation)
 225    {
 1226        if (selectedEntities.Count != 1)
 0227            return;
 228
 1229        TransformActionStarted(selectedEntities[0].rootEntity, BIWSettings.ROTATE_GIZMO_NAME);
 1230        selectedEntities[0].rootEntity.gameObject.transform.rotation = Quaternion.Euler(rotation);
 1231        TransformActionEnd(selectedEntities[0].rootEntity, BIWSettings.ROTATE_GIZMO_NAME);
 1232        ActionFinish(IBIWCompleteAction.ActionType.ROTATE);
 1233        entityHandler.ReportTransform(true);
 1234        saveController.TryToSave();
 1235    }
 236
 237    public void UpdateSelectionScale(Vector3 scale)
 238    {
 1239        if (selectedEntities.Count != 1)
 0240            return;
 241
 1242        var entityToUpdate = selectedEntities[0];
 243
 1244        TransformActionStarted(entityToUpdate.rootEntity, BIWSettings.SCALE_GIZMO_NAME);
 245        // Before change the scale, we unparent the entity to not to make it dependant on the editionGO and after that, 
 1246        entityToUpdate.rootEntity.gameObject.transform.SetParent(null);
 1247        entityToUpdate.rootEntity.gameObject.transform.localScale = scale;
 1248        editionGO.transform.localScale = Vector3.one;
 1249        entityToUpdate.rootEntity.gameObject.transform.SetParent(editionGO.transform);
 250
 1251        TransformActionEnd(entityToUpdate.rootEntity, BIWSettings.SCALE_GIZMO_NAME);
 1252        ActionFinish(IBIWCompleteAction.ActionType.SCALE);
 1253        entityHandler.ReportTransform(true);
 1254        saveController.TryToSave();
 1255    }
 256
 257    internal void DragEditionGameObject(Vector3 mousePosition)
 258    {
 0259        Vector3 currentPoint = raycastController.GetFloorPointAtMouse(mousePosition);
 0260        Vector3 initialEntityPosition = editionGO.transform.position;
 261
 0262        if (isSnapActiveValue)
 263        {
 0264            currentPoint = GetPositionRoundedToSnapFactor(currentPoint);
 0265            initialEntityPosition = GetPositionRoundedToSnapFactor(initialEntityPosition);
 266        }
 267
 0268        Vector3 move = currentPoint - dragStartedPoint;
 0269        Vector3 destination = initialEntityPosition + move;
 270
 0271        editionGO.transform.position = destination;
 0272        dragStartedPoint = currentPoint;
 0273    }
 274
 275    #region Mouse
 276
 277    public override void MouseClickDetected()
 278    {
 1279        if (isPlacingNewObject)
 280        {
 1281            entityHandler.DeselectEntities();
 1282            saveController.TryToSave();
 1283            return;
 284        }
 285
 0286        base.MouseClickDetected();
 0287    }
 288
 289    internal void OnInputMouseDrag(int buttonId, Vector3 mousePosition, float axisX, float axisY)
 290    {
 1291        if (Vector3.Distance(lastMousePosition, mousePosition) <= BIWSettings.MOUSE_THRESHOLD_FOR_DRAG && !isMouseDraggi
 0292            return;
 293
 1294        isMouseDragging = true;
 1295        if (buttonId != 0 ||
 296            selectedEntities.Count <= 0 ||
 297            BIWUtils.IsPointerOverMaskElement(BIWSettings.GIZMOS_LAYER) ||
 298            isSquareMultiSelectionInputActive)
 1299            return;
 300
 0301        if (!isDraggingStarted)
 0302            StarDraggingSelectedEntities();
 303
 0304        if (canDragSelectedEntities)
 0305            DragEditionGameObject(mousePosition);
 0306    }
 307
 308    internal Vector3 GetPositionRoundedToSnapFactor(Vector3 position)
 309    {
 0310        position = new Vector3(
 311            Mathf.Round(position.x / snapDragFactor) * snapDragFactor,
 312            position.y,
 313            Mathf.Round(position.z / snapDragFactor) * snapDragFactor);
 314
 0315        return position;
 316    }
 317
 318    internal void OnInputMouseUpOnUi(int buttonID, Vector3 position)
 319    {
 1320        if (buttonID == 1)
 321        {
 0322            mouseSecondaryBtnPressed = false;
 0323            freeCameraController.StopDetectingMovement();
 324        }
 325
 1326        if (buttonID != 0)
 0327            return;
 328
 1329        CheckEndBoundMultiselection(position);
 1330        isMouseDragging = false;
 1331    }
 332
 333    internal void OnInputMouseUp(int buttonID, Vector3 position)
 334    {
 1335        if (buttonID == 1)
 336        {
 0337            mouseSecondaryBtnPressed = false;
 0338            if (CanCancelAction(position))
 0339                entityHandler.CancelSelection();
 340
 0341            freeCameraController.StopDetectingMovement();
 342        }
 343
 1344        if (buttonID != 0)
 0345            return;
 346
 1347        EndDraggingSelectedEntities();
 348
 1349        CheckEndBoundMultiselection(position);
 350
 1351        outlinerController.SetOutlineCheckActive(true);
 352
 1353        isMouseDragging = false;
 1354    }
 355
 356    internal void OnInputMouseDown(int buttonID, Vector3 position)
 357    {
 1358        lastMousePosition = position;
 359
 1360        if (buttonID == 1)
 361        {
 0362            mouseSecondaryBtnPressed = true;
 0363            freeCameraController.StartDetectingMovement();
 364        }
 365
 1366        if (buttonID != 0)
 0367            return;
 368
 1369        dragStartedPoint = raycastController.GetFloorPointAtMouse(position);
 370
 1371        if (isSnapActiveValue)
 372        {
 0373            dragStartedPoint.x = Mathf.Round(dragStartedPoint.x);
 0374            dragStartedPoint.z = Mathf.Round(dragStartedPoint.z);
 375        }
 376
 1377        if (isPlacingNewObject)
 0378            return;
 379
 1380        var entity = raycastController.GetEntityOnPointer();
 1381        if ((entity == null
 382             || (entity != null && !entity.isSelected))
 383            && !BIWUtils.IsPointerOverMaskElement(BIWSettings.GIZMOS_LAYER))
 384        {
 1385            isSquareMultiSelectionInputActive = true;
 1386            outlinerController.SetOutlineCheckActive(false);
 387        }
 388
 1389        mouseMainBtnPressed = true;
 1390        freeCameraController.SetCameraCanMove(false);
 1391    }
 392
 393    #endregion
 394
 395    private void CheckEndBoundMultiselection(Vector3 position)
 396    {
 2397        if (isSquareMultiSelectionInputActive && mouseMainBtnPressed )
 398        {
 0399            if (Vector3.Distance(lastMousePosition, position) >= BIWSettings.MOUSE_THRESHOLD_FOR_DRAG)
 0400                EndBoundMultiSelection(Input.mousePosition);
 401
 0402            isSquareMultiSelectionInputActive = false;
 0403            mouseMainBtnPressed = false;
 404        }
 2405    }
 406
 0407    private bool CanCancelAction(Vector3 currentMousePosition) { return Vector3.Distance(lastMousePosition, currentMouse
 408
 409    internal void StarDraggingSelectedEntities()
 410    {
 2411        if (!entityHandler.IsPointerInSelectedEntity() ||
 412            gizmoManager.HasAxisHover())
 1413            return;
 414
 1415        if (gizmoManager.IsGizmoActive())
 416        {
 1417            gizmoManager.HideGizmo();
 1418            wasGizmosActive = true;
 419        }
 420
 1421        freeCameraController.SetCameraCanMove(false);
 1422        isDraggingStarted = true;
 423
 1424        canDragSelectedEntities = true;
 1425    }
 426
 427    internal void EndDraggingSelectedEntities()
 428    {
 2429        if (wasGizmosActive && !isPlacingNewObject)
 430        {
 0431            gizmoManager.ShowGizmo();
 0432            saveController.TryToSave();
 433        }
 434
 2435        wasGizmosActive = false;
 436
 2437        freeCameraController.SetCameraCanMove(true);
 2438        isDraggingStarted = false;
 439
 2440        canDragSelectedEntities = false;
 2441    }
 442
 443    internal void EndBoundMultiSelection(Vector3 mousePosition)
 444    {
 1445        freeCameraController.SetCameraCanMove(true);
 446        List<BIWEntity> allEntities = null;
 447
 1448        allEntities = entityHandler.GetAllEntitiesFromCurrentScene();
 449
 1450        List<BIWEntity> selectedInsideBoundsEntities = new List<BIWEntity>();
 1451        int alreadySelectedEntities = 0;
 452
 1453        if (!isMultiSelectionActive)
 1454            entityHandler.DeselectEntities();
 455
 4456        foreach (BIWEntity entity in allEntities)
 457        {
 1458            if (entity.rootEntity.meshRootGameObject && entity.rootEntity.meshesInfo.renderers.Length > 0)
 459            {
 1460                if (BIWUtils.IsWithinSelectionBounds(entity.rootEntity.meshesInfo.mergedBounds.center, lastMousePosition
 461                    && !entity.isLocked)
 462                {
 1463                    if (entity.isSelected)
 0464                        alreadySelectedEntities++;
 465
 1466                    entityHandler.SelectEntity(entity);
 1467                    selectedInsideBoundsEntities.Add(entity);
 468                }
 469            }
 470        }
 471
 1472        if (selectedInsideBoundsEntities.Count == alreadySelectedEntities && alreadySelectedEntities > 0)
 473        {
 0474            foreach (BIWEntity entity in selectedInsideBoundsEntities)
 475            {
 0476                entityHandler.DeselectEntity(entity);
 477            }
 478        }
 479
 1480        outlinerController.CancelAllOutlines();
 1481    }
 482
 483    public override void Activate(IParcelScene scene)
 484    {
 38485        base.Activate(scene);
 38486        sceneToEdit = scene;
 487
 38488        SetLookAtObject(scene);
 489
 38490        ConfigureCamera(scene);
 491
 38492        if (gizmoManager.GetSelectedGizmo() == DCL.Components.DCLGizmos.Gizmo.NONE)
 31493            gizmoManager.SetGizmoType(BIWSettings.TRANSLATE_GIZMO_NAME);
 38494        mouseCatcher.enabled = false;
 38495        Environment.i.world.sceneController.IsolateScene(sceneToEdit);
 38496        Utils.UnlockCursor();
 497
 38498        gizmoManager.HideGizmo();
 38499        editionGO.transform.SetParent(null);
 38500        avatarRenderer.SetAvatarVisibility(false);
 501
 38502        context.editorContext.editorHUD?.ActivateGodModeUI();
 38503    }
 504
 505    public void ConfigureCamera(IParcelScene parcelScene)
 506    {
 38507        freeCameraController.gameObject.SetActive(true);
 38508        SetLookAtObject(parcelScene);
 509
 38510        freeCameraController.LookAt(lookAtTransform);
 511
 38512        Camera camera = context.sceneReferences.mainCamera;
 38513        Vector3 cameraPosition = camera != null ? camera.transform.position : Vector3.zero;
 38514        freeCameraController.SetResetConfiguration(cameraPosition, lookAtTransform);
 38515    }
 516
 517    public override void OnDeleteEntity(BIWEntity entity)
 518    {
 0519        base.OnDeleteEntity(entity);
 0520        saveController.TryToSave();
 521
 0522        if (selectedEntities.Count == 0)
 0523            gizmoManager.HideGizmo();
 0524    }
 525
 526    public override void OnDeselectedEntities()
 527    {
 0528        base.OnDeselectedEntities();
 0529        gizmoManager.SetSelectedEntities(editionGO.transform, new List<BIWEntity>());
 0530    }
 531
 532    public override void Deactivate()
 533    {
 5534        base.Deactivate();
 5535        mouseCatcher.enabled = true;
 5536        Utils.LockCursor();
 537
 5538        Environment.i.world.sceneController.ReIntegrateIsolatedScene();
 539
 5540        gizmoManager.HideGizmo();
 5541        RenderSettings.fog = true;
 5542        avatarRenderer.SetAvatarVisibility(true);
 5543    }
 544
 545    public override void StartMultiSelection()
 546    {
 1547        base.StartMultiSelection();
 548
 1549        snapGO.transform.SetParent(null);
 1550        freeMovementGO.transform.SetParent(null);
 1551    }
 552
 553    public override void SetDuplicationOffset(float offset)
 554    {
 0555        base.SetDuplicationOffset(offset);
 0556        editionGO.transform.position += Vector3.right * offset;
 0557    }
 558
 559    public override void CreatedEntity(BIWEntity createdEntity)
 560    {
 1561        base.CreatedEntity(createdEntity);
 562
 1563        if (!createdEntity.isFloor)
 564        {
 1565            isPlacingNewObject = true;
 1566            outlinerController.SetOutlineCheckActive(false);
 567
 1568            SetEditObjectAtMouse();
 569        }
 570
 1571        gizmoManager.HideGizmo();
 1572        if (createdEntity.isVoxel)
 0573            createdEntity.rootEntity.gameObject.tag = BIWSettings.VOXEL_TAG;
 1574    }
 575
 0576    public override Vector3 GetCreatedEntityPoint() { return raycastController.GetFloorPointAtMouse(Input.mousePosition)
 577
 578    public override void SelectedEntity(BIWEntity selectedEntity)
 579    {
 1580        base.SelectedEntity(selectedEntity);
 581
 1582        gizmoManager.SetSelectedEntities(editionGO.transform, selectedEntities);
 583
 1584        if (!isMultiSelectionActive && !selectedEntity.isNew)
 1585            TryLookAtEntity(selectedEntity.rootEntity);
 586
 1587        snapGO.transform.SetParent(null);
 588
 1589        UpdateActionsInteractable();
 1590    }
 591
 592    public override void EntityDeselected(BIWEntity entityDeselected)
 593    {
 1594        base.EntityDeselected(entityDeselected);
 1595        if (selectedEntities.Count <= 0)
 596        {
 0597            gizmoManager.HideGizmo();
 0598            UpdateActionsInteractable();
 599        }
 600
 1601        if (isPlacingNewObject)
 1602            outlinerController.SetOutlineCheckActive(true);
 1603        isPlacingNewObject = false;
 1604    }
 605
 606    public override void EntityDoubleClick(BIWEntity entity)
 607    {
 0608        base.EntityDoubleClick(entity);
 0609        if (!entity.isLocked)
 0610            LookAtEntity(entity.rootEntity);
 0611    }
 612
 613    private void UpdateActionsInteractable()
 614    {
 1615        bool areInteratable = selectedEntities.Count > 0;
 1616        if ( context.editorContext.editorHUD != null)
 1617            context.editorContext.editorHUD.SetActionsButtonsInteractable(areInteratable);
 1618    }
 619
 620    public override bool ShouldCancelUndoAction()
 621    {
 1622        if (isPlacingNewObject)
 623        {
 1624            entityHandler.DestroyLastCreatedEntities();
 1625            isPlacingNewObject = false;
 1626            return true;
 627        }
 628
 0629        return false;
 630    }
 631
 632    public override void SetSnapActive(bool isActive)
 633    {
 42634        base.SetSnapActive(isActive);
 635
 42636        if (isSnapActiveValue)
 637        {
 2638            gizmoManager.SetSnapFactor(snapFactor, snapRotationDegresFactor, snapScaleFactor);
 2639        }
 640        else
 641        {
 40642            gizmoManager.SetSnapFactor(0, 0, 0);
 643        }
 40644    }
 645
 646    public void FocusOnSelectedEntitiesInput()
 647    {
 0648        if (isModeActive)
 649        {
 0650            FocusEntities(selectedEntities);
 0651            InputDone();
 652        }
 0653    }
 654
 655    public void TryLookAtEntity(IDCLEntity entity)
 656    {
 1657        if (entity.meshRootGameObject == null
 658            || entity.meshesInfo == null
 659            || BIWUtils.IsBoundInsideCamera(entity.meshesInfo.mergedBounds))
 1660            return;
 661
 0662        LookAtEntity(entity);
 0663    }
 664
 665    public void LookAtEntity(IDCLEntity entity)
 666    {
 1667        Vector3 pointToLook = entity.gameObject.transform.position;
 1668        if (entity.meshesInfo != null && entity.meshesInfo.renderers.Length > 0)
 0669            pointToLook = CalculateEntityMidPoint(entity);
 670
 1671        freeCameraController.SmoothLookAt(pointToLook);
 1672    }
 673
 674    internal Vector3 CalculateEntityMidPoint(IDCLEntity entity)
 675    {
 1676        Vector3 midPointFromEntityMesh = Vector3.zero;
 4677        foreach (Renderer render in entity.renderers)
 678        {
 1679            if (render == null)
 680                continue;
 1681            midPointFromEntityMesh += render.bounds.center;
 682        }
 683
 1684        midPointFromEntityMesh /= entity.renderers.Length;
 1685        return midPointFromEntityMesh;
 686    }
 687
 688    #region Gizmos
 689
 12690    public void TranslateMode() { GizmosMode( BIWSettings.TRANSLATE_GIZMO_NAME); }
 691
 8692    public void RotateMode() { GizmosMode( BIWSettings.ROTATE_GIZMO_NAME); }
 693
 4694    public void ScaleMode() { GizmosMode( BIWSettings.SCALE_GIZMO_NAME); }
 695
 696    private void GizmosMode(string gizmos)
 697    {
 12698        if ((!isModeActive && isPlacingNewObject) || mouseSecondaryBtnPressed)
 0699            return;
 12700        if (gizmoManager.GetSelectedGizmo() != gizmos)
 701        {
 7702            context.editorContext.editorHUD?.SetGizmosActive(gizmos);
 7703            gizmoManager.SetGizmoType(gizmos);
 7704            if (selectedEntities.Count > 0 )
 0705                gizmoManager.ShowGizmo();
 706        }
 707        //TODO: Free-Movement tool, This could be re-enabled in the future so let the code there
 708        // else
 709        // {
 710        //     gizmoManager.HideGizmo(true);
 711        //      context.editorContext.editorHUD?.SetGizmosActive(BIWSettings.EMPTY_GIZMO_NAME);
 712        // }
 12713    }
 714
 715    internal void OnGizmosTransformStart(string gizmoType)
 716    {
 2717        outlinerController.SetOutlineCheckActive(false);
 8718        foreach (BIWEntity entity in selectedEntities)
 719        {
 2720            TransformActionStarted(entity.rootEntity, gizmoType);
 721        }
 2722    }
 723
 724    internal void OnGizmosTransformEnd(string gizmoType)
 725    {
 1726        outlinerController.SetOutlineCheckActive(true);
 4727        foreach (BIWEntity entity in selectedEntities)
 728        {
 1729            TransformActionEnd(entity.rootEntity, gizmoType);
 730        }
 731
 732        switch (gizmoType)
 733        {
 734            case BIWSettings.TRANSLATE_GIZMO_NAME:
 735
 1736                ActionFinish(IBIWCompleteAction.ActionType.MOVE);
 1737                break;
 738            case BIWSettings.ROTATE_GIZMO_NAME:
 0739                ActionFinish(IBIWCompleteAction.ActionType.ROTATE);
 0740                break;
 741            case BIWSettings.SCALE_GIZMO_NAME:
 0742                ActionFinish(IBIWCompleteAction.ActionType.SCALE);
 743                break;
 744        }
 745
 1746        saveController.TryToSave();
 1747    }
 748
 749    #endregion
 750
 2751    public void FocusEntities(List<BIWEntity> entitiesToFocus) { freeCameraController.FocusOnEntities(entitiesToFocus); 
 752
 753    internal void SetLookAtObject(IParcelScene parcelScene)
 754    {
 76755        Vector3 middlePoint = BIWUtils.CalculateUnityMiddlePoint(parcelScene);
 76756        lookAtTransform.position = middlePoint;
 76757    }
 758
 759    internal void SetEditObjectAtMouse()
 760    {
 1761        if (raycastController.RayCastFloor(out Vector3 destination))
 762        {
 1763            if (isSnapActiveValue)
 764            {
 0765                destination.x = Mathf.Round(destination.x / snapDragFactor) * snapDragFactor;
 0766                destination.z = Mathf.Round(destination.z / snapDragFactor) * snapDragFactor;
 767            }
 768
 1769            editionGO.transform.position = destination;
 770
 1771            if (selectedEntities.Count > 0 && selectedEntities[0].isNFT)
 0772                editionGO.transform.position += Vector3.up * 2f;
 773        }
 1774    }
 775
 2776    internal void ResetCamera() { freeCameraController.ResetCameraPosition(); }
 777}

Methods/Properties

BIWGodMode()
Init(DCL.Builder.IContext)
Dispose()
Update()
OnGUI()
MultiSelectionInputStart(DCLAction_Hold)
MultiSelectionInputEnd(DCLAction_Hold)
CheckOutlineEntitiesInSquareSelection(UnityEngine.Vector3)
ChangeSnapTemporaryDeactivated()
ChangeSnapTemporaryActivated()
EntitiesTransformByGizmos(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()