< Summary

Class:BIWGodMode
Assembly:BuilderInWorld
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Scripts/States/EditorMode/BIWGodMode.cs
Covered lines:283
Uncovered lines:92
Coverable lines:375
Total lines:764
Line coverage:75.4% (283 of 375)
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%15.555025%
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 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    {
 3547        base.Init(context);
 48
 3549        this.context = context;
 3550        lookAtTransform = new GameObject("BIWGodModeTransform").transform;
 3551        maxDistanceToSelectEntitiesValue = context.editorContext.godModeDynamicVariablesAsset.maxDistanceToSelectEntitie
 52
 3553        snapFactor = context.editorContext.godModeDynamicVariablesAsset.snapFactor;
 3554        snapRotationDegresFactor = context.editorContext.godModeDynamicVariablesAsset.snapRotationDegresFactor;
 3555        snapScaleFactor =  context.editorContext.godModeDynamicVariablesAsset.snapScaleFactor;
 3556        snapDistanceToActivateMovement =  context.editorContext.godModeDynamicVariablesAsset.snapDistanceToActivateMovem
 57
 3558        snapDragFactor = context.editorContext.godModeDynamicVariablesAsset.snapDragFactor;
 59
 3560        outlinerController = context.editorContext.outlinerController;
 3561        gizmoManager = context.editorContext.gizmosController;
 62
 3563        if ( context.editorContext.editorHUD != null)
 64        {
 3565            context.editorContext.editorHUD.OnTranslateSelectedAction += TranslateMode;
 3566            context.editorContext.editorHUD.OnRotateSelectedAction += RotateMode;
 3567            context.editorContext.editorHUD.OnScaleSelectedAction += ScaleMode;
 3568            context.editorContext.editorHUD.OnSelectedObjectPositionChange += UpdateSelectionPosition;
 3569            context.editorContext.editorHUD.OnSelectedObjectRotationChange += UpdateSelectionRotation;
 3570            context.editorContext.editorHUD.OnSelectedObjectScaleChange += UpdateSelectionScale;
 3571            context.editorContext.editorHUD.OnResetCameraAction += ResetCamera;
 72        }
 73
 3574        if (context.sceneReferences.cameraController.GetComponent<CameraController>().TryGetCameraStateByType<FreeCamera
 3575            freeCameraController = (FreeCameraMovement) cameraState;
 3576        mouseCatcher = context.sceneReferences.mouseCatcher.GetComponent<MouseCatcher>();
 77
 3578        BIWInputWrapper.OnMouseDown += OnInputMouseDown;
 3579        BIWInputWrapper.OnMouseUp += OnInputMouseUp;
 3580        BIWInputWrapper.OnMouseUpOnUI += OnInputMouseUpOnUi;
 3581        BIWInputWrapper.OnMouseDrag += OnInputMouseDrag;
 82
 3583        focusOnSelectedEntitiesInputAction = context.inputsReferencesAsset.focusOnSelectedEntitiesInputAction;
 3584        multiSelectionInputAction = context.inputsReferencesAsset.multiSelectionInputAction;
 85
 3586        focusOnSelectedEntitiesInputAction.OnTriggered += (o) => FocusOnSelectedEntitiesInput();
 87
 3588        multiSelectionInputAction.OnStarted += MultiSelectionInputStart;
 3589        multiSelectionInputAction.OnFinished += MultiSelectionInputEnd;
 90
 3591        gizmoManager.OnChangeTransformValue += EntitiesTransfromByGizmos;
 3592        gizmoManager.OnGizmoTransformObjectEnd += OnGizmosTransformEnd;
 3593        gizmoManager.OnGizmoTransformObjectStart += OnGizmosTransformStart;
 3594    }
 95
 96    public override void Dispose()
 97    {
 3598        base.Dispose();
 99
 35100        isPlacingNewObject = false;
 101
 35102        gizmoManager.OnGizmoTransformObjectEnd -= OnGizmosTransformEnd;
 35103        gizmoManager.OnGizmoTransformObjectStart -= OnGizmosTransformStart;
 104
 35105        multiSelectionInputAction.OnStarted -= MultiSelectionInputStart;
 35106        multiSelectionInputAction.OnFinished -= MultiSelectionInputEnd;
 107
 35108        BIWInputWrapper.OnMouseDown -= OnInputMouseDown;
 35109        BIWInputWrapper.OnMouseUp -= OnInputMouseUp;
 35110        BIWInputWrapper.OnMouseUpOnUI -= OnInputMouseUpOnUi;
 35111        BIWInputWrapper.OnMouseDrag -= OnInputMouseDrag;
 112
 35113        gizmoManager.OnChangeTransformValue -= EntitiesTransfromByGizmos;
 114
 35115        if (lookAtTransform.gameObject != null)
 35116            GameObject.Destroy(lookAtTransform.gameObject);
 117
 35118        if ( context.editorContext.editorHUD == null)
 0119            return;
 120
 35121        context.editorContext.editorHUD.OnSelectedObjectPositionChange -= UpdateSelectionPosition;
 35122        context.editorContext.editorHUD.OnSelectedObjectRotationChange -= UpdateSelectionRotation;
 35123        context.editorContext.editorHUD.OnSelectedObjectScaleChange -= UpdateSelectionScale;
 35124        context.editorContext.editorHUD.OnTranslateSelectedAction -= TranslateMode;
 35125        context.editorContext.editorHUD.OnRotateSelectedAction -= RotateMode;
 35126        context.editorContext.editorHUD.OnScaleSelectedAction -= ScaleMode;
 35127        context.editorContext.editorHUD.OnResetCameraAction -= ResetCamera;
 35128    }
 129
 130    public override void Update()
 131    {
 0132        base.Update();
 133
 0134        if (isPlacingNewObject)
 0135            SetEditObjectAtMouse();
 0136        else if (isSquareMultiSelectionInputActive && isMouseDragging)
 0137            CheckOutlineEntitiesInSquareSelection(Input.mousePosition);
 138
 0139    }
 140
 141    public override void OnGUI()
 142    {
 0143        base.OnGUI();
 0144        if (mouseMainBtnPressed && isSquareMultiSelectionInputActive)
 145        {
 0146            var rect = BIWUtils.GetScreenRect(lastMousePosition, Input.mousePosition);
 0147            BIWUtils.DrawScreenRect(rect, new Color(1f, 1f, 1f, 0.25f));
 0148            BIWUtils.DrawScreenRectBorder(rect, 1, Color.white);
 149        }
 0150    }
 151
 4152    private void MultiSelectionInputStart(DCLAction_Hold action) { ChangeSnapTemporaryActivated(); }
 153
 66154    private void MultiSelectionInputEnd(DCLAction_Hold action) { ChangeSnapTemporaryDeactivated(); }
 155
 156    internal void CheckOutlineEntitiesInSquareSelection(Vector3 mousePosition)
 157    {
 158        List<BIWEntity> allEntities = null;
 159
 1160        allEntities = entityHandler.GetAllEntitiesFromCurrentScene();
 161
 4162        foreach (BIWEntity entity in allEntities)
 163        {
 1164            if (!entity.rootEntity.meshRootGameObject || entity.rootEntity.meshesInfo.renderers.Length <= 0)
 165                continue;
 166
 1167            if (BIWUtils.IsWithinSelectionBounds(entity.rootEntity.meshesInfo.mergedBounds.center, lastMousePosition, mo
 1168                outlinerController.OutlineEntity(entity);
 169            else
 0170                outlinerController.CancelEntityOutline(entity);
 171        }
 1172    }
 173
 174    private void ChangeSnapTemporaryDeactivated()
 175    {
 33176        if (changeSnapTemporaryButtonPressed)
 2177            SetSnapActive(!isSnapActiveValue);
 178
 33179        changeSnapTemporaryButtonPressed = false;
 33180    }
 181
 182    private void ChangeSnapTemporaryActivated()
 183    {
 2184        if (selectedEntities.Count == 0)
 0185            return;
 186
 2187        changeSnapTemporaryButtonPressed = true;
 188
 2189        SetSnapActive(!isSnapActiveValue);
 2190    }
 191
 192    internal void EntitiesTransfromByGizmos(Vector3 transformValue)
 193    {
 1194        if (gizmoManager.GetSelectedGizmo() != BIWSettings.ROTATE_GIZMO_NAME)
 0195            return;
 196
 4197        foreach (BIWEntity entity in selectedEntities)
 198        {
 1199            entity.AddRotation(transformValue);
 200        }
 1201    }
 202
 203    public void UpdateSelectionPosition(Vector3 newPosition)
 204    {
 1205        if (selectedEntities.Count != 1)
 0206            return;
 207
 1208        TransformActionStarted(selectedEntities[0].rootEntity, BIWSettings.TRANSLATE_GIZMO_NAME);
 1209        editionGO.transform.position = WorldStateUtils.ConvertSceneToUnityPosition(newPosition, sceneToEdit);
 1210        gizmoManager.SetSelectedEntities(editionGO.transform, selectedEntities);
 1211        TransformActionEnd(selectedEntities[0].rootEntity, BIWSettings.TRANSLATE_GIZMO_NAME);
 1212        ActionFinish(IBIWCompleteAction.ActionType.MOVE);
 1213        entityHandler.ReportTransform(true);
 1214        saveController.TryToSave();
 1215    }
 216
 217    public void UpdateSelectionRotation(Vector3 rotation)
 218    {
 1219        if (selectedEntities.Count != 1)
 0220            return;
 221
 1222        TransformActionStarted(selectedEntities[0].rootEntity, BIWSettings.ROTATE_GIZMO_NAME);
 1223        selectedEntities[0].rootEntity.gameObject.transform.rotation = Quaternion.Euler(rotation);
 1224        TransformActionEnd(selectedEntities[0].rootEntity, BIWSettings.ROTATE_GIZMO_NAME);
 1225        ActionFinish(IBIWCompleteAction.ActionType.ROTATE);
 1226        entityHandler.ReportTransform(true);
 1227        saveController.TryToSave();
 1228    }
 229
 230    public void UpdateSelectionScale(Vector3 scale)
 231    {
 1232        if (selectedEntities.Count != 1)
 0233            return;
 234
 1235        var entityToUpdate = selectedEntities[0];
 236
 1237        TransformActionStarted(entityToUpdate.rootEntity, BIWSettings.SCALE_GIZMO_NAME);
 238        // Before change the scale, we unparent the entity to not to make it dependant on the editionGO and after that, 
 1239        entityToUpdate.rootEntity.gameObject.transform.SetParent(null);
 1240        entityToUpdate.rootEntity.gameObject.transform.localScale = scale;
 1241        editionGO.transform.localScale = Vector3.one;
 1242        entityToUpdate.rootEntity.gameObject.transform.SetParent(editionGO.transform);
 243
 1244        TransformActionEnd(entityToUpdate.rootEntity, BIWSettings.SCALE_GIZMO_NAME);
 1245        ActionFinish(IBIWCompleteAction.ActionType.SCALE);
 1246        entityHandler.ReportTransform(true);
 1247        saveController.TryToSave();
 1248    }
 249
 250    internal void DragEditionGameObject(Vector3 mousePosition)
 251    {
 1252        Vector3 currentPoint = raycastController.GetFloorPointAtMouse(mousePosition);
 1253        Vector3 initialEntityPosition = editionGO.transform.position;
 254
 1255        if (isSnapActiveValue)
 256        {
 0257            currentPoint = GetPositionRoundedToSnapFactor(currentPoint);
 0258            initialEntityPosition = GetPositionRoundedToSnapFactor(initialEntityPosition);
 259        }
 260
 1261        Vector3 move = currentPoint - dragStartedPoint;
 1262        Vector3 destination = initialEntityPosition + move;
 263
 1264        editionGO.transform.position = destination;
 1265        dragStartedPoint = currentPoint;
 1266    }
 267
 268    #region Mouse
 269
 270    public override void MouseClickDetected()
 271    {
 1272        if (isPlacingNewObject)
 273        {
 1274            entityHandler.DeselectEntities();
 1275            saveController.TryToSave();
 1276            return;
 277        }
 278
 0279        base.MouseClickDetected();
 0280    }
 281
 282    internal void OnInputMouseDrag(int buttonId, Vector3 mousePosition, float axisX, float axisY)
 283    {
 1284        if (Vector3.Distance(lastMousePosition, mousePosition) <= BIWSettings.MOUSE_THRESHOLD_FOR_DRAG && !isMouseDraggi
 0285            return;
 286
 1287        isMouseDragging = true;
 1288        if (buttonId != 0 ||
 289            selectedEntities.Count <= 0 ||
 290            BIWUtils.IsPointerOverMaskElement(BIWSettings.GIZMOS_LAYER) ||
 291            isSquareMultiSelectionInputActive)
 1292            return;
 293
 0294        if (!isDraggingStarted)
 0295            StarDraggingSelectedEntities();
 296
 0297        if (canDragSelectedEntities)
 0298            DragEditionGameObject(mousePosition);
 0299    }
 300
 301    internal Vector3 GetPositionRoundedToSnapFactor(Vector3 position)
 302    {
 0303        position = new Vector3(
 304            Mathf.Round(position.x / snapDragFactor) * snapDragFactor,
 305            position.y,
 306            Mathf.Round(position.z / snapDragFactor) * snapDragFactor);
 307
 0308        return position;
 309    }
 310
 311    internal void OnInputMouseUpOnUi(int buttonID, Vector3 position)
 312    {
 1313        if (buttonID == 1)
 314        {
 0315            mouseSecondaryBtnPressed = false;
 0316            freeCameraController.StopDetectingMovement();
 317        }
 318
 1319        if (buttonID != 0)
 0320            return;
 321
 1322        CheckEndBoundMultiselection(position);
 1323        isMouseDragging = false;
 1324    }
 325
 326    internal void OnInputMouseUp(int buttonID, Vector3 position)
 327    {
 1328        if (buttonID == 1)
 329        {
 0330            mouseSecondaryBtnPressed = false;
 0331            if (CanCancelAction(position))
 0332                entityHandler.CancelSelection();
 333
 0334            freeCameraController.StopDetectingMovement();
 335        }
 336
 1337        if (buttonID != 0)
 0338            return;
 339
 1340        EndDraggingSelectedEntities();
 341
 1342        CheckEndBoundMultiselection(position);
 343
 1344        outlinerController.SetOutlineCheckActive(true);
 345
 1346        isMouseDragging = false;
 1347    }
 348
 349    internal void OnInputMouseDown(int buttonID, Vector3 position)
 350    {
 1351        lastMousePosition = position;
 352
 1353        if (buttonID == 1)
 354        {
 0355            mouseSecondaryBtnPressed = true;
 0356            freeCameraController.StartDetectingMovement();
 357        }
 358
 1359        if (buttonID != 0)
 0360            return;
 361
 1362        dragStartedPoint = raycastController.GetFloorPointAtMouse(position);
 363
 1364        if (isSnapActiveValue)
 365        {
 0366            dragStartedPoint.x = Mathf.Round(dragStartedPoint.x);
 0367            dragStartedPoint.z = Mathf.Round(dragStartedPoint.z);
 368        }
 369
 1370        if (isPlacingNewObject)
 0371            return;
 372
 1373        var entity = raycastController.GetEntityOnPointer();
 1374        if ((entity == null
 375             || (entity != null && !entity.isSelected))
 376            && !BIWUtils.IsPointerOverMaskElement(BIWSettings.GIZMOS_LAYER))
 377        {
 1378            isSquareMultiSelectionInputActive = true;
 1379            outlinerController.SetOutlineCheckActive(false);
 380        }
 381
 1382        mouseMainBtnPressed = true;
 1383        freeCameraController.SetCameraCanMove(false);
 1384    }
 385
 386    #endregion
 387
 388    private void CheckEndBoundMultiselection(Vector3 position)
 389    {
 2390        if (isSquareMultiSelectionInputActive && mouseMainBtnPressed )
 391        {
 0392            if (Vector3.Distance(lastMousePosition, position) >= BIWSettings.MOUSE_THRESHOLD_FOR_DRAG)
 0393                EndBoundMultiSelection(Input.mousePosition);
 394
 0395            isSquareMultiSelectionInputActive = false;
 0396            mouseMainBtnPressed = false;
 397        }
 2398    }
 399
 0400    private bool CanCancelAction(Vector3 currentMousePosition) { return Vector3.Distance(lastMousePosition, currentMouse
 401
 402    internal void StarDraggingSelectedEntities()
 403    {
 2404        if (!entityHandler.IsPointerInSelectedEntity() ||
 405            gizmoManager.HasAxisHover())
 1406            return;
 407
 1408        if (gizmoManager.IsGizmoActive())
 409        {
 1410            gizmoManager.HideGizmo();
 1411            wasGizmosActive = true;
 412        }
 413
 1414        freeCameraController.SetCameraCanMove(false);
 1415        isDraggingStarted = true;
 416
 1417        canDragSelectedEntities = true;
 1418    }
 419
 420    internal void EndDraggingSelectedEntities()
 421    {
 2422        if (wasGizmosActive && !isPlacingNewObject)
 423        {
 0424            gizmoManager.ShowGizmo();
 0425            saveController.TryToSave();
 426        }
 427
 2428        wasGizmosActive = false;
 429
 2430        freeCameraController.SetCameraCanMove(true);
 2431        isDraggingStarted = false;
 432
 2433        canDragSelectedEntities = false;
 2434    }
 435
 436    internal void EndBoundMultiSelection(Vector3 mousePosition)
 437    {
 1438        freeCameraController.SetCameraCanMove(true);
 439        List<BIWEntity> allEntities = null;
 440
 1441        allEntities = entityHandler.GetAllEntitiesFromCurrentScene();
 442
 1443        List<BIWEntity> selectedInsideBoundsEntities = new List<BIWEntity>();
 1444        int alreadySelectedEntities = 0;
 445
 1446        if (!isMultiSelectionActive)
 1447            entityHandler.DeselectEntities();
 448
 4449        foreach (BIWEntity entity in allEntities)
 450        {
 1451            if (entity.rootEntity.meshRootGameObject && entity.rootEntity.meshesInfo.renderers.Length > 0)
 452            {
 1453                if (BIWUtils.IsWithinSelectionBounds(entity.rootEntity.meshesInfo.mergedBounds.center, lastMousePosition
 454                    && !entity.isLocked)
 455                {
 1456                    if (entity.isSelected)
 0457                        alreadySelectedEntities++;
 458
 1459                    entityHandler.SelectEntity(entity);
 1460                    selectedInsideBoundsEntities.Add(entity);
 461                }
 462            }
 463        }
 464
 1465        if (selectedInsideBoundsEntities.Count == alreadySelectedEntities && alreadySelectedEntities > 0)
 466        {
 0467            foreach (BIWEntity entity in selectedInsideBoundsEntities)
 468            {
 0469                entityHandler.DeselectEntity(entity);
 470            }
 471        }
 472
 1473        outlinerController.CancelAllOutlines();
 1474    }
 475
 476    public override void Activate(IParcelScene scene)
 477    {
 39478        base.Activate(scene);
 39479        sceneToEdit = scene;
 480
 39481        SetLookAtObject(scene);
 482
 39483        ConfigureCamera(scene);
 484
 39485        if (gizmoManager.GetSelectedGizmo() == DCL.Components.DCLGizmos.Gizmo.NONE)
 32486            gizmoManager.SetGizmoType(BIWSettings.TRANSLATE_GIZMO_NAME);
 39487        mouseCatcher.enabled = false;
 39488        Environment.i.world.sceneController.IsolateScene(sceneToEdit);
 39489        Utils.UnlockCursor();
 490
 39491        gizmoManager.HideGizmo();
 39492        editionGO.transform.SetParent(null);
 493
 39494        context.editorContext.editorHUD?.ActivateGodModeUI();
 39495    }
 496
 497    public void ConfigureCamera(IParcelScene parcelScene)
 498    {
 39499        freeCameraController.gameObject.SetActive(true);
 39500        SetLookAtObject(parcelScene);
 501
 39502        freeCameraController.LookAt(lookAtTransform);
 39503        freeCameraController.SetResetConfiguration(Camera.main.transform.position, lookAtTransform);
 39504    }
 505
 506    public override void OnDeleteEntity(BIWEntity entity)
 507    {
 0508        base.OnDeleteEntity(entity);
 509
 0510        if (selectedEntities.Count == 0)
 0511            gizmoManager.HideGizmo();
 0512    }
 513
 514    public override void OnDeselectedEntities()
 515    {
 0516        base.OnDeselectedEntities();
 0517        gizmoManager.SetSelectedEntities(editionGO.transform, new List<BIWEntity>());
 0518    }
 519
 520    public override void Deactivate()
 521    {
 5522        base.Deactivate();
 5523        mouseCatcher.enabled = true;
 5524        Utils.LockCursor();
 525
 5526        Environment.i.world.sceneController.ReIntegrateIsolatedScene();
 527
 5528        gizmoManager.HideGizmo();
 5529        RenderSettings.fog = true;
 5530    }
 531
 532    public override void StartMultiSelection()
 533    {
 1534        base.StartMultiSelection();
 535
 1536        snapGO.transform.SetParent(null);
 1537        freeMovementGO.transform.SetParent(null);
 1538    }
 539
 540    public override void SetDuplicationOffset(float offset)
 541    {
 0542        base.SetDuplicationOffset(offset);
 0543        editionGO.transform.position += Vector3.right * offset;
 0544    }
 545
 546    public override void CreatedEntity(BIWEntity createdEntity)
 547    {
 1548        base.CreatedEntity(createdEntity);
 549
 1550        if (!createdEntity.isFloor)
 551        {
 1552            isPlacingNewObject = true;
 1553            outlinerController.SetOutlineCheckActive(false);
 554
 1555            SetEditObjectAtMouse();
 556        }
 557
 1558        gizmoManager.HideGizmo();
 1559        if (createdEntity.isVoxel)
 0560            createdEntity.rootEntity.gameObject.tag = BIWSettings.VOXEL_TAG;
 1561    }
 562
 0563    public override Vector3 GetCreatedEntityPoint() { return raycastController.GetFloorPointAtMouse(Input.mousePosition)
 564
 565    public override void SelectedEntity(BIWEntity selectedEntity)
 566    {
 1567        base.SelectedEntity(selectedEntity);
 568
 1569        gizmoManager.SetSelectedEntities(editionGO.transform, selectedEntities);
 570
 1571        if (!isMultiSelectionActive && !selectedEntity.isNew)
 1572            TryLookAtEntity(selectedEntity.rootEntity);
 573
 1574        snapGO.transform.SetParent(null);
 575
 1576        UpdateActionsInteractable();
 1577    }
 578
 579    public override void EntityDeselected(BIWEntity entityDeselected)
 580    {
 1581        base.EntityDeselected(entityDeselected);
 1582        if (selectedEntities.Count <= 0)
 583        {
 0584            gizmoManager.HideGizmo();
 0585            UpdateActionsInteractable();
 586        }
 587
 1588        if (isPlacingNewObject)
 1589            outlinerController.SetOutlineCheckActive(true);
 1590        isPlacingNewObject = false;
 1591    }
 592
 593    public override void EntityDoubleClick(BIWEntity entity)
 594    {
 0595        base.EntityDoubleClick(entity);
 0596        if (!entity.isLocked)
 0597            LookAtEntity(entity.rootEntity);
 0598    }
 599
 600    private void UpdateActionsInteractable()
 601    {
 1602        bool areInteratable = selectedEntities.Count > 0;
 1603        if ( context.editorContext.editorHUD != null)
 1604            context.editorContext.editorHUD.SetActionsButtonsInteractable(areInteratable);
 1605    }
 606
 607    public override bool ShouldCancelUndoAction()
 608    {
 1609        if (isPlacingNewObject)
 610        {
 1611            entityHandler.DestroyLastCreatedEntities();
 1612            isPlacingNewObject = false;
 1613            return true;
 614        }
 615
 0616        return false;
 617    }
 618
 619    public override void SetSnapActive(bool isActive)
 620    {
 43621        base.SetSnapActive(isActive);
 622
 43623        if (isSnapActiveValue)
 624        {
 2625            gizmoManager.SetSnapFactor(snapFactor, snapRotationDegresFactor, snapScaleFactor);
 2626        }
 627        else
 628        {
 41629            gizmoManager.SetSnapFactor(0, 0, 0);
 630        }
 41631    }
 632
 633    public void FocusOnSelectedEntitiesInput()
 634    {
 0635        if (isModeActive)
 636        {
 0637            FocusEntities(selectedEntities);
 0638            InputDone();
 639        }
 0640    }
 641
 642    public void TryLookAtEntity(IDCLEntity entity)
 643    {
 1644        if (entity.meshRootGameObject == null
 645            || entity.meshesInfo == null
 646            || BIWUtils.IsBoundInsideCamera(entity.meshesInfo.mergedBounds))
 1647            return;
 648
 0649        LookAtEntity(entity);
 0650    }
 651
 652    public void LookAtEntity(IDCLEntity entity)
 653    {
 1654        Vector3 pointToLook = entity.gameObject.transform.position;
 1655        if (entity.meshesInfo != null && entity.meshesInfo.renderers.Length > 0)
 0656            pointToLook = CalculateEntityMidPoint(entity);
 657
 1658        freeCameraController.SmoothLookAt(pointToLook);
 1659    }
 660
 661    internal Vector3 CalculateEntityMidPoint(IDCLEntity entity)
 662    {
 1663        Vector3 midPointFromEntityMesh = Vector3.zero;
 4664        foreach (Renderer render in entity.renderers)
 665        {
 1666            if (render == null)
 667                continue;
 1668            midPointFromEntityMesh += render.bounds.center;
 669        }
 670
 1671        midPointFromEntityMesh /= entity.renderers.Length;
 1672        return midPointFromEntityMesh;
 673    }
 674
 675    #region Gizmos
 676
 12677    public void TranslateMode() { GizmosMode( BIWSettings.TRANSLATE_GIZMO_NAME); }
 678
 8679    public void RotateMode() { GizmosMode( BIWSettings.ROTATE_GIZMO_NAME); }
 680
 4681    public void ScaleMode() { GizmosMode( BIWSettings.SCALE_GIZMO_NAME); }
 682
 683    private void GizmosMode(string gizmos)
 684    {
 12685        if ((!isModeActive && isPlacingNewObject) || mouseSecondaryBtnPressed)
 0686            return;
 12687        if (gizmoManager.GetSelectedGizmo() != gizmos)
 688        {
 7689            context.editorContext.editorHUD?.SetGizmosActive(gizmos);
 7690            gizmoManager.SetGizmoType(gizmos);
 7691            if (selectedEntities.Count > 0 )
 0692                gizmoManager.ShowGizmo();
 693        }
 694        // Note: Free-Movement tool, This could be re-enabled in the future so let the code there
 695        // else
 696        // {
 697        //     gizmoManager.HideGizmo(true);
 698        //      context.editorContext.editorHUD?.SetGizmosActive(BIWSettings.EMPTY_GIZMO_NAME);
 699        // }
 12700    }
 701
 702    internal void OnGizmosTransformStart(string gizmoType)
 703    {
 2704        outlinerController.SetOutlineCheckActive(false);
 8705        foreach (BIWEntity entity in selectedEntities)
 706        {
 2707            TransformActionStarted(entity.rootEntity, gizmoType);
 708        }
 2709    }
 710
 711    internal void OnGizmosTransformEnd(string gizmoType)
 712    {
 1713        outlinerController.SetOutlineCheckActive(true);
 4714        foreach (BIWEntity entity in selectedEntities)
 715        {
 1716            TransformActionEnd(entity.rootEntity, gizmoType);
 717        }
 718
 719        switch (gizmoType)
 720        {
 721            case BIWSettings.TRANSLATE_GIZMO_NAME:
 722
 1723                ActionFinish(IBIWCompleteAction.ActionType.MOVE);
 1724                break;
 725            case BIWSettings.ROTATE_GIZMO_NAME:
 0726                ActionFinish(IBIWCompleteAction.ActionType.ROTATE);
 0727                break;
 728            case BIWSettings.SCALE_GIZMO_NAME:
 0729                ActionFinish(IBIWCompleteAction.ActionType.SCALE);
 730                break;
 731        }
 732
 1733        saveController.TryToSave();
 1734    }
 735
 736    #endregion
 737
 2738    public void FocusEntities(List<BIWEntity> entitiesToFocus) { freeCameraController.FocusOnEntities(entitiesToFocus); 
 739
 740    internal void SetLookAtObject(IParcelScene parcelScene)
 741    {
 78742        Vector3 middlePoint = BIWUtils.CalculateUnityMiddlePoint(parcelScene);
 78743        lookAtTransform.position = middlePoint;
 78744    }
 745
 746    internal void SetEditObjectAtMouse()
 747    {
 1748        if (raycastController.RayCastFloor(out Vector3 destination))
 749        {
 0750            if (isSnapActiveValue)
 751            {
 0752                destination.x = Mathf.Round(destination.x / snapDragFactor) * snapDragFactor;
 0753                destination.z = Mathf.Round(destination.z / snapDragFactor) * snapDragFactor;
 754            }
 755
 0756            editionGO.transform.position = destination;
 757
 0758            if (selectedEntities.Count > 0 && selectedEntities[0].isNFT)
 0759                editionGO.transform.position += Vector3.up * 2f;
 760        }
 1761    }
 762
 2763    internal void ResetCamera() { freeCameraController.ResetCameraPosition(); }
 764}

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()