| | 1 | | using DCL; |
| | 2 | | using DCL.Configuration; |
| | 3 | | using DCL.Controllers; |
| | 4 | | using DCL.Helpers; |
| | 5 | | using DCL.Models; |
| | 6 | | using System; |
| | 7 | | using System.Collections.Generic; |
| | 8 | | using DCL.Camera; |
| | 9 | | using UnityEngine; |
| | 10 | | using Environment = DCL.Environment; |
| | 11 | |
|
| | 12 | | public class BIWGodMode : BIWMode |
| | 13 | | { |
| 63 | 14 | | private float initialEagleCameraHeight = 10f; |
| 63 | 15 | | private float initialEagleCameraDistance = 10f; |
| | 16 | | private float initialEagleCameraLookAtHeight = 0f; |
| | 17 | |
|
| 63 | 18 | | private float snapDragFactor = 5f; |
| | 19 | | internal IFreeCameraMovement freeCameraController; |
| | 20 | |
|
| | 21 | | private CameraController cameraController; |
| | 22 | | private Transform lookAtTransform; |
| | 23 | | private MouseCatcher mouseCatcher; |
| | 24 | | private PlayerAvatarController avatarRenderer; |
| | 25 | | private IBIWGizmosController gizmoManager; |
| | 26 | | private IBIWOutlinerController outlinerController; |
| | 27 | |
|
| | 28 | | private InputAction_Trigger focusOnSelectedEntitiesInputAction; |
| | 29 | | private InputAction_Hold multiSelectionInputAction; |
| | 30 | |
|
| | 31 | | private IParcelScene sceneToEdit; |
| | 32 | |
|
| | 33 | | internal bool isPlacingNewObject = false; |
| | 34 | | internal bool mouseMainBtnPressed = false; |
| | 35 | | internal bool mouseSecondaryBtnPressed = false; |
| | 36 | | internal bool isSquareMultiSelectionInputActive = false; |
| | 37 | | internal bool isMouseDragging = false; |
| | 38 | | internal bool changeSnapTemporaryButtonPressed = false; |
| | 39 | |
|
| | 40 | | internal bool wasGizmosActive = false; |
| | 41 | | internal bool isDraggingStarted = false; |
| | 42 | | internal bool canDragSelectedEntities = false; |
| | 43 | |
|
| 63 | 44 | | private bool activateCamera = true; |
| | 45 | | private CameraMode.ModeId avatarCameraModeBeforeEditing; |
| | 46 | |
|
| | 47 | | internal Vector3 lastMousePosition; |
| | 48 | | internal Vector3 dragStartedPoint; |
| | 49 | |
|
| | 50 | | public const float RAYCAST_MAX_DISTANCE = 10000f; |
| | 51 | |
|
| | 52 | | public override void Init(BIWContext context) |
| | 53 | | { |
| 63 | 54 | | base.Init(context); |
| | 55 | |
|
| 63 | 56 | | lookAtTransform = new GameObject("BIWGodModeTransform").transform; |
| 63 | 57 | | maxDistanceToSelectEntitiesValue = context.godModeDynamicVariablesAsset.maxDistanceToSelectEntities; |
| | 58 | |
|
| 63 | 59 | | snapFactor = context.godModeDynamicVariablesAsset.snapFactor; |
| 63 | 60 | | snapRotationDegresFactor = context.godModeDynamicVariablesAsset.snapRotationDegresFactor; |
| 63 | 61 | | snapScaleFactor = context.godModeDynamicVariablesAsset.snapScaleFactor; |
| 63 | 62 | | snapDistanceToActivateMovement = context.godModeDynamicVariablesAsset.snapDistanceToActivateMovement; |
| | 63 | |
|
| 63 | 64 | | initialEagleCameraHeight = context.godModeDynamicVariablesAsset.initialEagleCameraHeight; |
| 63 | 65 | | initialEagleCameraDistance = context.godModeDynamicVariablesAsset.initialEagleCameraDistance; |
| 63 | 66 | | initialEagleCameraLookAtHeight = context.godModeDynamicVariablesAsset.initialEagleCameraLookAtHeight; |
| | 67 | |
|
| 63 | 68 | | snapDragFactor = context.godModeDynamicVariablesAsset.snapDragFactor; |
| | 69 | |
|
| 63 | 70 | | outlinerController = context.outlinerController; |
| 63 | 71 | | gizmoManager = context.gizmosController; |
| | 72 | |
|
| 63 | 73 | | if (HUDController.i.builderInWorldMainHud != null) |
| | 74 | | { |
| 25 | 75 | | HUDController.i.builderInWorldMainHud.OnTranslateSelectedAction += TranslateMode; |
| 25 | 76 | | HUDController.i.builderInWorldMainHud.OnRotateSelectedAction += RotateMode; |
| 25 | 77 | | HUDController.i.builderInWorldMainHud.OnScaleSelectedAction += ScaleMode; |
| 25 | 78 | | HUDController.i.builderInWorldMainHud.OnSelectedObjectPositionChange += UpdateSelectionPosition; |
| 25 | 79 | | HUDController.i.builderInWorldMainHud.OnSelectedObjectRotationChange += UpdateSelectionRotation; |
| 25 | 80 | | HUDController.i.builderInWorldMainHud.OnSelectedObjectScaleChange += UpdateSelectionScale; |
| 25 | 81 | | HUDController.i.builderInWorldMainHud.OnResetCameraAction += ResetCamera; |
| 25 | 82 | | HUDController.i.builderInWorldMainHud.OnPublishAction += TakeSceneScreenshotForPublish; |
| | 83 | | } |
| | 84 | |
|
| 63 | 85 | | if (context.sceneReferences.cameraController.TryGetCameraStateByType<FreeCameraMovement>(out CameraStateBase cam |
| 63 | 86 | | freeCameraController = (FreeCameraMovement) cameraState; |
| 63 | 87 | | mouseCatcher = context.sceneReferences.mouseCatcher; |
| 63 | 88 | | avatarRenderer = context.sceneReferences.playerAvatarController; |
| 63 | 89 | | cameraController = context.sceneReferences.cameraController; |
| | 90 | |
|
| 63 | 91 | | BIWInputWrapper.OnMouseDown += OnInputMouseDown; |
| 63 | 92 | | BIWInputWrapper.OnMouseUp += OnInputMouseUp; |
| 63 | 93 | | BIWInputWrapper.OnMouseUpOnUI += OnInputMouseUpOnUi; |
| 63 | 94 | | BIWInputWrapper.OnMouseDrag += OnInputMouseDrag; |
| | 95 | |
|
| 63 | 96 | | focusOnSelectedEntitiesInputAction = context.inputsReferencesAsset.focusOnSelectedEntitiesInputAction; |
| 63 | 97 | | multiSelectionInputAction = context.inputsReferencesAsset.multiSelectionInputAction; |
| | 98 | |
|
| 63 | 99 | | focusOnSelectedEntitiesInputAction.OnTriggered += (o) => FocusOnSelectedEntitiesInput(); |
| | 100 | |
|
| 70 | 101 | | multiSelectionInputAction.OnStarted += (o) => ChangeSnapTemporaryActivated(); |
| 697 | 102 | | multiSelectionInputAction.OnFinished += (o) => ChangeSnapTemporaryDeactivated(); |
| | 103 | |
|
| 63 | 104 | | gizmoManager.OnChangeTransformValue += EntitiesTransfromByGizmos; |
| 63 | 105 | | gizmoManager.OnGizmoTransformObjectEnd += OnGizmosTransformEnd; |
| 63 | 106 | | gizmoManager.OnGizmoTransformObjectStart += OnGizmosTransformStart; |
| 63 | 107 | | } |
| | 108 | |
|
| | 109 | | public override void Dispose() |
| | 110 | | { |
| 63 | 111 | | base.Dispose(); |
| | 112 | |
|
| 63 | 113 | | isPlacingNewObject = false; |
| | 114 | |
|
| 63 | 115 | | gizmoManager.OnGizmoTransformObjectEnd -= OnGizmosTransformEnd; |
| 63 | 116 | | gizmoManager.OnGizmoTransformObjectStart -= OnGizmosTransformStart; |
| | 117 | |
|
| 63 | 118 | | BIWInputWrapper.OnMouseDown -= OnInputMouseDown; |
| 63 | 119 | | BIWInputWrapper.OnMouseUp -= OnInputMouseUp; |
| 63 | 120 | | BIWInputWrapper.OnMouseUpOnUI -= OnInputMouseUpOnUi; |
| 63 | 121 | | BIWInputWrapper.OnMouseDrag -= OnInputMouseDrag; |
| | 122 | |
|
| 63 | 123 | | gizmoManager.OnChangeTransformValue -= EntitiesTransfromByGizmos; |
| | 124 | |
|
| 63 | 125 | | if (lookAtTransform.gameObject != null) |
| 63 | 126 | | GameObject.Destroy(lookAtTransform.gameObject); |
| | 127 | |
|
| 63 | 128 | | if (HUDController.i.builderInWorldMainHud == null) |
| 38 | 129 | | return; |
| | 130 | |
|
| 25 | 131 | | HUDController.i.builderInWorldMainHud.OnSelectedObjectPositionChange -= UpdateSelectionPosition; |
| 25 | 132 | | HUDController.i.builderInWorldMainHud.OnSelectedObjectRotationChange -= UpdateSelectionRotation; |
| 25 | 133 | | HUDController.i.builderInWorldMainHud.OnSelectedObjectScaleChange -= UpdateSelectionScale; |
| 25 | 134 | | HUDController.i.builderInWorldMainHud.OnTranslateSelectedAction -= TranslateMode; |
| 25 | 135 | | HUDController.i.builderInWorldMainHud.OnRotateSelectedAction -= RotateMode; |
| 25 | 136 | | HUDController.i.builderInWorldMainHud.OnScaleSelectedAction -= ScaleMode; |
| 25 | 137 | | HUDController.i.builderInWorldMainHud.OnResetCameraAction -= ResetCamera; |
| 25 | 138 | | HUDController.i.builderInWorldMainHud.OnPublishAction -= TakeSceneScreenshotForPublish; |
| 25 | 139 | | } |
| | 140 | |
|
| | 141 | | public override void Update() |
| | 142 | | { |
| 2 | 143 | | base.Update(); |
| 2 | 144 | | if (isPlacingNewObject) |
| | 145 | | { |
| 0 | 146 | | SetEditObjectAtMouse(); |
| 0 | 147 | | } |
| 2 | 148 | | else if (isSquareMultiSelectionInputActive && isMouseDragging) |
| | 149 | | { |
| 0 | 150 | | CheckOutlineEntitiesInSquareSelection(Input.mousePosition); |
| | 151 | | } |
| 2 | 152 | | } |
| | 153 | |
|
| | 154 | | public override void OnGUI() |
| | 155 | | { |
| 1 | 156 | | base.OnGUI(); |
| 1 | 157 | | if (mouseMainBtnPressed && isSquareMultiSelectionInputActive) |
| | 158 | | { |
| 0 | 159 | | var rect = BIWUtils.GetScreenRect(lastMousePosition, Input.mousePosition); |
| 0 | 160 | | BIWUtils.DrawScreenRect(rect, new Color(1f, 1f, 1f, 0.25f)); |
| 0 | 161 | | BIWUtils.DrawScreenRectBorder(rect, 1, Color.white); |
| | 162 | | } |
| 1 | 163 | | } |
| | 164 | |
|
| | 165 | | internal void CheckOutlineEntitiesInSquareSelection(Vector3 mousePosition) |
| | 166 | | { |
| | 167 | | List<BIWEntity> allEntities = null; |
| | 168 | |
|
| 1 | 169 | | allEntities = entityHandler.GetAllEntitiesFromCurrentScene(); |
| | 170 | |
|
| 4 | 171 | | foreach (BIWEntity entity in allEntities) |
| | 172 | | { |
| 1 | 173 | | if (!entity.rootEntity.meshRootGameObject || entity.rootEntity.meshesInfo.renderers.Length <= 0) |
| | 174 | | continue; |
| | 175 | |
|
| 1 | 176 | | if (BIWUtils.IsWithinSelectionBounds(entity.rootEntity.meshesInfo.mergedBounds.center, lastMousePosition, mo |
| 1 | 177 | | outlinerController.OutlineEntity(entity); |
| | 178 | | else |
| 0 | 179 | | outlinerController.CancelEntityOutline(entity); |
| | 180 | | } |
| 1 | 181 | | } |
| | 182 | |
|
| | 183 | | private void ChangeSnapTemporaryDeactivated() |
| | 184 | | { |
| 634 | 185 | | if (changeSnapTemporaryButtonPressed) |
| 3 | 186 | | SetSnapActive(!isSnapActiveValue); |
| | 187 | |
|
| 634 | 188 | | changeSnapTemporaryButtonPressed = false; |
| 634 | 189 | | } |
| | 190 | |
|
| | 191 | | private void ChangeSnapTemporaryActivated() |
| | 192 | | { |
| 7 | 193 | | if (selectedEntities.Count == 0) |
| 4 | 194 | | return; |
| | 195 | |
|
| 3 | 196 | | changeSnapTemporaryButtonPressed = true; |
| | 197 | |
|
| 3 | 198 | | SetSnapActive(!isSnapActiveValue); |
| 3 | 199 | | } |
| | 200 | |
|
| | 201 | | internal void EntitiesTransfromByGizmos(Vector3 transformValue) |
| | 202 | | { |
| 1 | 203 | | if (gizmoManager.GetSelectedGizmo() != BIWSettings.ROTATE_GIZMO_NAME) |
| 0 | 204 | | return; |
| | 205 | |
|
| 4 | 206 | | foreach (BIWEntity entity in selectedEntities) |
| | 207 | | { |
| 1 | 208 | | entity.AddRotation(transformValue); |
| | 209 | | } |
| 1 | 210 | | } |
| | 211 | |
|
| | 212 | | public void UpdateSelectionPosition(Vector3 newPosition) |
| | 213 | | { |
| 1 | 214 | | if (selectedEntities.Count != 1) |
| 0 | 215 | | return; |
| | 216 | |
|
| 1 | 217 | | TransformActionStarted(selectedEntities[0].rootEntity, BIWSettings.TRANSLATE_GIZMO_NAME); |
| 1 | 218 | | editionGO.transform.position = WorldStateUtils.ConvertSceneToUnityPosition(newPosition, sceneToEdit); |
| 1 | 219 | | gizmoManager.SetSelectedEntities(editionGO.transform, selectedEntities); |
| 1 | 220 | | TransformActionEnd(selectedEntities[0].rootEntity, BIWSettings.TRANSLATE_GIZMO_NAME); |
| 1 | 221 | | ActionFinish(BIWCompleteAction.ActionType.MOVE); |
| 1 | 222 | | entityHandler.ReportTransform(true); |
| 1 | 223 | | saveController.TryToSave(); |
| 1 | 224 | | } |
| | 225 | |
|
| | 226 | | public void UpdateSelectionRotation(Vector3 rotation) |
| | 227 | | { |
| 1 | 228 | | if (selectedEntities.Count != 1) |
| 0 | 229 | | return; |
| | 230 | |
|
| 1 | 231 | | TransformActionStarted(selectedEntities[0].rootEntity, BIWSettings.ROTATE_GIZMO_NAME); |
| 1 | 232 | | selectedEntities[0].rootEntity.gameObject.transform.rotation = Quaternion.Euler(rotation); |
| 1 | 233 | | TransformActionEnd(selectedEntities[0].rootEntity, BIWSettings.ROTATE_GIZMO_NAME); |
| 1 | 234 | | ActionFinish(BIWCompleteAction.ActionType.ROTATE); |
| 1 | 235 | | entityHandler.ReportTransform(true); |
| 1 | 236 | | saveController.TryToSave(); |
| 1 | 237 | | } |
| | 238 | |
|
| | 239 | | public void UpdateSelectionScale(Vector3 scale) |
| | 240 | | { |
| 1 | 241 | | if (selectedEntities.Count != 1) |
| 0 | 242 | | return; |
| | 243 | |
|
| 1 | 244 | | var entityToUpdate = selectedEntities[0]; |
| | 245 | |
|
| 1 | 246 | | TransformActionStarted(entityToUpdate.rootEntity, BIWSettings.SCALE_GIZMO_NAME); |
| | 247 | | // Before change the scale, we unparent the entity to not to make it dependant on the editionGO and after that, |
| 1 | 248 | | entityToUpdate.rootEntity.gameObject.transform.SetParent(null); |
| 1 | 249 | | entityToUpdate.rootEntity.gameObject.transform.localScale = scale; |
| 1 | 250 | | editionGO.transform.localScale = Vector3.one; |
| 1 | 251 | | entityToUpdate.rootEntity.gameObject.transform.SetParent(editionGO.transform); |
| | 252 | |
|
| 1 | 253 | | TransformActionEnd(entityToUpdate.rootEntity, BIWSettings.SCALE_GIZMO_NAME); |
| 1 | 254 | | ActionFinish(BIWCompleteAction.ActionType.SCALE); |
| 1 | 255 | | entityHandler.ReportTransform(true); |
| 1 | 256 | | saveController.TryToSave(); |
| 1 | 257 | | } |
| | 258 | |
|
| | 259 | | internal void DragEditionGameObject(Vector3 mousePosition) |
| | 260 | | { |
| 1 | 261 | | Vector3 currentPoint = raycastController.GetFloorPointAtMouse(mousePosition); |
| 1 | 262 | | Vector3 initialEntityPosition = editionGO.transform.position; |
| | 263 | |
|
| 1 | 264 | | if (isSnapActiveValue) |
| | 265 | | { |
| 0 | 266 | | currentPoint = GetPositionRoundedToSnapFactor(currentPoint); |
| 0 | 267 | | initialEntityPosition = GetPositionRoundedToSnapFactor(initialEntityPosition); |
| | 268 | | } |
| | 269 | |
|
| 1 | 270 | | Vector3 move = currentPoint - dragStartedPoint; |
| 1 | 271 | | Vector3 destination = initialEntityPosition + move; |
| | 272 | |
|
| 1 | 273 | | editionGO.transform.position = destination; |
| 1 | 274 | | dragStartedPoint = currentPoint; |
| 1 | 275 | | } |
| | 276 | |
|
| | 277 | | #region Mouse |
| | 278 | |
|
| | 279 | | public override void MouseClickDetected() |
| | 280 | | { |
| 1 | 281 | | if (isPlacingNewObject) |
| | 282 | | { |
| 1 | 283 | | entityHandler.DeselectEntities(); |
| 1 | 284 | | saveController.TryToSave(); |
| 1 | 285 | | return; |
| | 286 | | } |
| | 287 | |
|
| 0 | 288 | | base.MouseClickDetected(); |
| 0 | 289 | | } |
| | 290 | |
|
| | 291 | | internal void OnInputMouseDrag(int buttonId, Vector3 mousePosition, float axisX, float axisY) |
| | 292 | | { |
| 1 | 293 | | if (Vector3.Distance(lastMousePosition, mousePosition) <= BIWSettings.MOUSE_THRESHOLD_FOR_DRAG && !isMouseDraggi |
| 0 | 294 | | return; |
| | 295 | |
|
| 1 | 296 | | isMouseDragging = true; |
| 1 | 297 | | if (buttonId != 0 || |
| | 298 | | selectedEntities.Count <= 0 || |
| | 299 | | BIWUtils.IsPointerOverMaskElement(BIWSettings.GIZMOS_LAYER) || |
| | 300 | | isSquareMultiSelectionInputActive) |
| 1 | 301 | | return; |
| | 302 | |
|
| 0 | 303 | | if (!isDraggingStarted) |
| 0 | 304 | | StarDraggingSelectedEntities(); |
| | 305 | |
|
| 0 | 306 | | if (canDragSelectedEntities) |
| 0 | 307 | | DragEditionGameObject(mousePosition); |
| 0 | 308 | | } |
| | 309 | |
|
| | 310 | | internal Vector3 GetPositionRoundedToSnapFactor(Vector3 position) |
| | 311 | | { |
| 0 | 312 | | position = new Vector3( |
| | 313 | | Mathf.Round(position.x / snapDragFactor) * snapDragFactor, |
| | 314 | | position.y, |
| | 315 | | Mathf.Round(position.z / snapDragFactor) * snapDragFactor); |
| | 316 | |
|
| 0 | 317 | | return position; |
| | 318 | | } |
| | 319 | |
|
| | 320 | | internal void OnInputMouseUpOnUi(int buttonID, Vector3 position) |
| | 321 | | { |
| 1 | 322 | | if (buttonID == 1) |
| | 323 | | { |
| 0 | 324 | | mouseSecondaryBtnPressed = false; |
| 0 | 325 | | freeCameraController.StopDetectingMovement(); |
| | 326 | | } |
| | 327 | |
|
| 1 | 328 | | if (buttonID != 0) |
| 0 | 329 | | return; |
| | 330 | |
|
| 1 | 331 | | CheckEndBoundMultiselection(position); |
| 1 | 332 | | isMouseDragging = false; |
| 1 | 333 | | } |
| | 334 | |
|
| | 335 | | internal void OnInputMouseUp(int buttonID, Vector3 position) |
| | 336 | | { |
| 1 | 337 | | if (buttonID == 1) |
| | 338 | | { |
| 0 | 339 | | mouseSecondaryBtnPressed = false; |
| 0 | 340 | | if (CanCancelAction(position)) |
| 0 | 341 | | entityHandler.CancelSelection(); |
| | 342 | |
|
| 0 | 343 | | freeCameraController.StopDetectingMovement(); |
| | 344 | | } |
| | 345 | |
|
| 1 | 346 | | if (buttonID != 0) |
| 0 | 347 | | return; |
| | 348 | |
|
| 1 | 349 | | EndDraggingSelectedEntities(); |
| | 350 | |
|
| 1 | 351 | | CheckEndBoundMultiselection(position); |
| | 352 | |
|
| 1 | 353 | | outlinerController.SetOutlineCheckActive(true); |
| | 354 | |
|
| 1 | 355 | | isMouseDragging = false; |
| 1 | 356 | | } |
| | 357 | |
|
| | 358 | | internal void OnInputMouseDown(int buttonID, Vector3 position) |
| | 359 | | { |
| 1 | 360 | | lastMousePosition = position; |
| | 361 | |
|
| 1 | 362 | | if (buttonID == 1) |
| | 363 | | { |
| 0 | 364 | | mouseSecondaryBtnPressed = true; |
| 0 | 365 | | freeCameraController.StartDectectingMovement(); |
| | 366 | | } |
| | 367 | |
|
| 1 | 368 | | if (buttonID != 0) |
| 0 | 369 | | return; |
| | 370 | |
|
| 1 | 371 | | dragStartedPoint = raycastController.GetFloorPointAtMouse(position); |
| | 372 | |
|
| 1 | 373 | | if (isSnapActiveValue) |
| | 374 | | { |
| 0 | 375 | | dragStartedPoint.x = Mathf.Round(dragStartedPoint.x); |
| 0 | 376 | | dragStartedPoint.z = Mathf.Round(dragStartedPoint.z); |
| | 377 | | } |
| | 378 | |
|
| 1 | 379 | | if (isPlacingNewObject) |
| 0 | 380 | | return; |
| | 381 | |
|
| 1 | 382 | | var entity = raycastController.GetEntityOnPointer(); |
| 1 | 383 | | if ((entity == null |
| | 384 | | || (entity != null && !entity.isSelected)) |
| | 385 | | && !BIWUtils.IsPointerOverMaskElement(BIWSettings.GIZMOS_LAYER)) |
| | 386 | | { |
| 1 | 387 | | isSquareMultiSelectionInputActive = true; |
| 1 | 388 | | outlinerController.SetOutlineCheckActive(false); |
| | 389 | | } |
| | 390 | |
|
| 1 | 391 | | mouseMainBtnPressed = true; |
| 1 | 392 | | freeCameraController.SetCameraCanMove(false); |
| 1 | 393 | | } |
| | 394 | |
|
| | 395 | | #endregion |
| | 396 | |
|
| | 397 | | private void CheckEndBoundMultiselection(Vector3 position) |
| | 398 | | { |
| 2 | 399 | | if (isSquareMultiSelectionInputActive && mouseMainBtnPressed ) |
| | 400 | | { |
| 0 | 401 | | if (Vector3.Distance(lastMousePosition, position) >= BIWSettings.MOUSE_THRESHOLD_FOR_DRAG) |
| 0 | 402 | | EndBoundMultiSelection(Input.mousePosition); |
| | 403 | |
|
| 0 | 404 | | isSquareMultiSelectionInputActive = false; |
| 0 | 405 | | mouseMainBtnPressed = false; |
| | 406 | | } |
| 2 | 407 | | } |
| | 408 | |
|
| 0 | 409 | | private bool CanCancelAction(Vector3 currentMousePosition) { return Vector3.Distance(lastMousePosition, currentMouse |
| | 410 | |
|
| | 411 | | internal void StarDraggingSelectedEntities() |
| | 412 | | { |
| 2 | 413 | | if (!entityHandler.IsPointerInSelectedEntity() || |
| | 414 | | gizmoManager.HasAxisHover()) |
| 1 | 415 | | return; |
| | 416 | |
|
| 1 | 417 | | if (gizmoManager.IsGizmoActive()) |
| | 418 | | { |
| 1 | 419 | | gizmoManager.HideGizmo(); |
| 1 | 420 | | wasGizmosActive = true; |
| | 421 | | } |
| | 422 | |
|
| 1 | 423 | | freeCameraController.SetCameraCanMove(false); |
| 1 | 424 | | isDraggingStarted = true; |
| | 425 | |
|
| 1 | 426 | | canDragSelectedEntities = true; |
| 1 | 427 | | } |
| | 428 | |
|
| | 429 | | internal void EndDraggingSelectedEntities() |
| | 430 | | { |
| 2 | 431 | | if (wasGizmosActive && !isPlacingNewObject) |
| | 432 | | { |
| 0 | 433 | | gizmoManager.ShowGizmo(); |
| 0 | 434 | | saveController.TryToSave(); |
| | 435 | | } |
| | 436 | |
|
| 2 | 437 | | wasGizmosActive = false; |
| | 438 | |
|
| 2 | 439 | | freeCameraController.SetCameraCanMove(true); |
| 2 | 440 | | isDraggingStarted = false; |
| | 441 | |
|
| 2 | 442 | | canDragSelectedEntities = false; |
| 2 | 443 | | } |
| | 444 | |
|
| | 445 | | internal void EndBoundMultiSelection(Vector3 mousePosition) |
| | 446 | | { |
| 1 | 447 | | freeCameraController.SetCameraCanMove(true); |
| | 448 | | List<BIWEntity> allEntities = null; |
| | 449 | |
|
| 1 | 450 | | allEntities = entityHandler.GetAllEntitiesFromCurrentScene(); |
| | 451 | |
|
| 1 | 452 | | List<BIWEntity> selectedInsideBoundsEntities = new List<BIWEntity>(); |
| 1 | 453 | | int alreadySelectedEntities = 0; |
| | 454 | |
|
| 1 | 455 | | if (!isMultiSelectionActive) |
| 1 | 456 | | entityHandler.DeselectEntities(); |
| | 457 | |
|
| 4 | 458 | | foreach (BIWEntity entity in allEntities) |
| | 459 | | { |
| 1 | 460 | | if (entity.rootEntity.meshRootGameObject && entity.rootEntity.meshesInfo.renderers.Length > 0) |
| | 461 | | { |
| 1 | 462 | | if (BIWUtils.IsWithinSelectionBounds(entity.rootEntity.meshesInfo.mergedBounds.center, lastMousePosition |
| | 463 | | && !entity.isLocked) |
| | 464 | | { |
| 1 | 465 | | if (entity.isSelected) |
| 0 | 466 | | alreadySelectedEntities++; |
| | 467 | |
|
| 1 | 468 | | entityHandler.SelectEntity(entity); |
| 1 | 469 | | selectedInsideBoundsEntities.Add(entity); |
| | 470 | | } |
| | 471 | | } |
| | 472 | | } |
| | 473 | |
|
| 1 | 474 | | if (selectedInsideBoundsEntities.Count == alreadySelectedEntities && alreadySelectedEntities > 0) |
| | 475 | | { |
| 0 | 476 | | foreach (BIWEntity entity in selectedInsideBoundsEntities) |
| | 477 | | { |
| 0 | 478 | | entityHandler.DeselectEntity(entity); |
| | 479 | | } |
| | 480 | | } |
| | 481 | |
|
| 1 | 482 | | outlinerController.CancelAllOutlines(); |
| 1 | 483 | | } |
| | 484 | |
|
| | 485 | | public override void Activate(IParcelScene scene) |
| | 486 | | { |
| 50 | 487 | | base.Activate(scene); |
| 50 | 488 | | sceneToEdit = scene; |
| | 489 | |
|
| 50 | 490 | | if (activateCamera) |
| 50 | 491 | | ActivateCamera(scene); |
| | 492 | |
|
| 50 | 493 | | if (gizmoManager.GetSelectedGizmo() == DCL.Components.DCLGizmos.Gizmo.NONE) |
| 43 | 494 | | gizmoManager.SetGizmoType(BIWSettings.TRANSLATE_GIZMO_NAME); |
| 50 | 495 | | mouseCatcher.enabled = false; |
| 50 | 496 | | Environment.i.world.sceneController.IsolateScene(sceneToEdit); |
| 50 | 497 | | Utils.UnlockCursor(); |
| | 498 | |
|
| 50 | 499 | | gizmoManager.HideGizmo(); |
| 50 | 500 | | editionGO.transform.SetParent(null); |
| 50 | 501 | | avatarRenderer.SetAvatarVisibility(false); |
| | 502 | |
|
| 50 | 503 | | HUDController.i.builderInWorldMainHud?.ActivateGodModeUI(); |
| 8 | 504 | | } |
| | 505 | |
|
| | 506 | | public void ActivateCamera(IParcelScene parcelScene) |
| | 507 | | { |
| 51 | 508 | | freeCameraController.gameObject.SetActive(true); |
| 51 | 509 | | SetLookAtObject(parcelScene); |
| | 510 | |
|
| 51 | 511 | | Vector3 cameraPosition = GetInitialCameraPosition(parcelScene); |
| 51 | 512 | | freeCameraController.SetPosition(cameraPosition); |
| 51 | 513 | | freeCameraController.LookAt(lookAtTransform); |
| 51 | 514 | | freeCameraController.SetResetConfiguration(cameraPosition, lookAtTransform); |
| | 515 | |
|
| 51 | 516 | | if (cameraController.currentCameraState.cameraModeId != CameraMode.ModeId.BuildingToolGodMode) |
| 8 | 517 | | avatarCameraModeBeforeEditing = cameraController.currentCameraState.cameraModeId; |
| | 518 | |
|
| 51 | 519 | | cameraController.SetCameraMode(CameraMode.ModeId.BuildingToolGodMode); |
| 51 | 520 | | } |
| | 521 | |
|
| | 522 | | public override void OnDeleteEntity(BIWEntity entity) |
| | 523 | | { |
| 0 | 524 | | base.OnDeleteEntity(entity); |
| 0 | 525 | | saveController.TryToSave(); |
| | 526 | |
|
| 0 | 527 | | if (selectedEntities.Count == 0) |
| 0 | 528 | | gizmoManager.HideGizmo(); |
| 0 | 529 | | } |
| | 530 | |
|
| | 531 | | public override void OnDeselectedEntities() |
| | 532 | | { |
| 0 | 533 | | base.OnDeselectedEntities(); |
| 0 | 534 | | gizmoManager.SetSelectedEntities(editionGO.transform, new List<BIWEntity>()); |
| 0 | 535 | | } |
| | 536 | |
|
| | 537 | | public override void Deactivate() |
| | 538 | | { |
| 7 | 539 | | base.Deactivate(); |
| 7 | 540 | | mouseCatcher.enabled = true; |
| 7 | 541 | | Utils.LockCursor(); |
| 7 | 542 | | cameraController.SetCameraMode(avatarCameraModeBeforeEditing); |
| | 543 | |
|
| 7 | 544 | | Environment.i.world.sceneController.ReIntegrateIsolatedScene(); |
| | 545 | |
|
| 7 | 546 | | gizmoManager.HideGizmo(); |
| 7 | 547 | | RenderSettings.fog = true; |
| 7 | 548 | | avatarRenderer.SetAvatarVisibility(true); |
| 7 | 549 | | } |
| | 550 | |
|
| | 551 | | public override void StartMultiSelection() |
| | 552 | | { |
| 1 | 553 | | base.StartMultiSelection(); |
| | 554 | |
|
| 1 | 555 | | snapGO.transform.SetParent(null); |
| 1 | 556 | | freeMovementGO.transform.SetParent(null); |
| 1 | 557 | | } |
| | 558 | |
|
| | 559 | | public override void SetDuplicationOffset(float offset) |
| | 560 | | { |
| 0 | 561 | | base.SetDuplicationOffset(offset); |
| 0 | 562 | | editionGO.transform.position += Vector3.right * offset; |
| 0 | 563 | | } |
| | 564 | |
|
| | 565 | | public override void CreatedEntity(BIWEntity createdEntity) |
| | 566 | | { |
| 1 | 567 | | base.CreatedEntity(createdEntity); |
| | 568 | |
|
| 1 | 569 | | if (!createdEntity.isFloor) |
| | 570 | | { |
| 1 | 571 | | isPlacingNewObject = true; |
| 1 | 572 | | outlinerController.SetOutlineCheckActive(false); |
| | 573 | |
|
| 1 | 574 | | SetEditObjectAtMouse(); |
| | 575 | | } |
| | 576 | |
|
| 1 | 577 | | gizmoManager.HideGizmo(); |
| 1 | 578 | | if (createdEntity.isVoxel) |
| 0 | 579 | | createdEntity.rootEntity.gameObject.tag = BIWSettings.VOXEL_TAG; |
| 1 | 580 | | } |
| | 581 | |
|
| 0 | 582 | | public override Vector3 GetCreatedEntityPoint() { return raycastController.GetFloorPointAtMouse(Input.mousePosition) |
| | 583 | |
|
| | 584 | | public override void SelectedEntity(BIWEntity selectedEntity) |
| | 585 | | { |
| 1 | 586 | | base.SelectedEntity(selectedEntity); |
| | 587 | |
|
| 1 | 588 | | gizmoManager.SetSelectedEntities(editionGO.transform, selectedEntities); |
| | 589 | |
|
| 1 | 590 | | if (!isMultiSelectionActive && !selectedEntity.isNew) |
| 1 | 591 | | TryLookAtEntity(selectedEntity.rootEntity); |
| | 592 | |
|
| 1 | 593 | | snapGO.transform.SetParent(null); |
| | 594 | |
|
| 1 | 595 | | UpdateActionsInteractable(); |
| 1 | 596 | | } |
| | 597 | |
|
| | 598 | | public override void EntityDeselected(BIWEntity entityDeselected) |
| | 599 | | { |
| 1 | 600 | | base.EntityDeselected(entityDeselected); |
| 1 | 601 | | if (selectedEntities.Count <= 0) |
| | 602 | | { |
| 0 | 603 | | gizmoManager.HideGizmo(); |
| 0 | 604 | | UpdateActionsInteractable(); |
| | 605 | | } |
| | 606 | |
|
| 1 | 607 | | if (isPlacingNewObject) |
| 1 | 608 | | outlinerController.SetOutlineCheckActive(true); |
| 1 | 609 | | isPlacingNewObject = false; |
| 1 | 610 | | } |
| | 611 | |
|
| | 612 | | public override void EntityDoubleClick(BIWEntity entity) |
| | 613 | | { |
| 0 | 614 | | base.EntityDoubleClick(entity); |
| 0 | 615 | | if (!entity.isLocked) |
| 0 | 616 | | LookAtEntity(entity.rootEntity); |
| 0 | 617 | | } |
| | 618 | |
|
| | 619 | | private void UpdateActionsInteractable() |
| | 620 | | { |
| 1 | 621 | | bool areInteratable = selectedEntities.Count > 0; |
| 1 | 622 | | if (HUDController.i.builderInWorldMainHud != null) |
| 0 | 623 | | HUDController.i.builderInWorldMainHud.SetActionsButtonsInteractable(areInteratable); |
| 1 | 624 | | } |
| | 625 | |
|
| | 626 | | public override bool ShouldCancelUndoAction() |
| | 627 | | { |
| 1 | 628 | | if (isPlacingNewObject) |
| | 629 | | { |
| 1 | 630 | | entityHandler.DestroyLastCreatedEntities(); |
| 1 | 631 | | isPlacingNewObject = false; |
| 1 | 632 | | return true; |
| | 633 | | } |
| | 634 | |
|
| 0 | 635 | | return false; |
| | 636 | | } |
| | 637 | |
|
| | 638 | | public override void SetSnapActive(bool isActive) |
| | 639 | | { |
| 56 | 640 | | base.SetSnapActive(isActive); |
| | 641 | |
|
| 56 | 642 | | if (isSnapActiveValue) |
| | 643 | | { |
| 3 | 644 | | gizmoManager.SetSnapFactor(snapFactor, snapRotationDegresFactor, snapScaleFactor); |
| 3 | 645 | | } |
| | 646 | | else |
| | 647 | | { |
| 53 | 648 | | gizmoManager.SetSnapFactor(0, 0, 0); |
| | 649 | | } |
| 53 | 650 | | } |
| | 651 | |
|
| | 652 | | public void FocusOnSelectedEntitiesInput() |
| | 653 | | { |
| 0 | 654 | | if (isModeActive) |
| | 655 | | { |
| 0 | 656 | | FocusEntities(selectedEntities); |
| 0 | 657 | | InputDone(); |
| | 658 | | } |
| 0 | 659 | | } |
| | 660 | |
|
| | 661 | | public void TryLookAtEntity(IDCLEntity entity) |
| | 662 | | { |
| 1 | 663 | | if (entity.meshRootGameObject == null |
| | 664 | | || entity.meshesInfo == null |
| | 665 | | || BIWUtils.IsBoundInsideCamera(entity.meshesInfo.mergedBounds)) |
| 1 | 666 | | return; |
| | 667 | |
|
| 0 | 668 | | LookAtEntity(entity); |
| 0 | 669 | | } |
| | 670 | |
|
| | 671 | | public void LookAtEntity(IDCLEntity entity) |
| | 672 | | { |
| 1 | 673 | | Vector3 pointToLook = entity.gameObject.transform.position; |
| 1 | 674 | | if (entity.meshesInfo != null && entity.meshesInfo.renderers.Length > 0) |
| 0 | 675 | | pointToLook = CalculateEntityMidPoint(entity); |
| | 676 | |
|
| 1 | 677 | | freeCameraController.SmoothLookAt(pointToLook); |
| 1 | 678 | | } |
| | 679 | |
|
| | 680 | | internal Vector3 CalculateEntityMidPoint(IDCLEntity entity) |
| | 681 | | { |
| 1 | 682 | | Vector3 midPointFromEntityMesh = Vector3.zero; |
| 4 | 683 | | foreach (Renderer render in entity.renderers) |
| | 684 | | { |
| 1 | 685 | | if (render == null) |
| | 686 | | continue; |
| 1 | 687 | | midPointFromEntityMesh += render.bounds.center; |
| | 688 | | } |
| | 689 | |
|
| 1 | 690 | | midPointFromEntityMesh /= entity.renderers.Length; |
| 1 | 691 | | return midPointFromEntityMesh; |
| | 692 | | } |
| | 693 | |
|
| | 694 | | #region Gizmos |
| | 695 | |
|
| 12 | 696 | | public void TranslateMode() { GizmosMode( BIWSettings.TRANSLATE_GIZMO_NAME); } |
| | 697 | |
|
| 8 | 698 | | public void RotateMode() { GizmosMode( BIWSettings.ROTATE_GIZMO_NAME); } |
| | 699 | |
|
| 4 | 700 | | public void ScaleMode() { GizmosMode( BIWSettings.SCALE_GIZMO_NAME); } |
| | 701 | |
|
| | 702 | | private void GizmosMode(string gizmos) |
| | 703 | | { |
| 12 | 704 | | if ((!isModeActive && isPlacingNewObject) || mouseSecondaryBtnPressed) |
| 0 | 705 | | return; |
| 12 | 706 | | if (gizmoManager.GetSelectedGizmo() != gizmos) |
| | 707 | | { |
| 7 | 708 | | HUDController.i.builderInWorldMainHud?.SetGizmosActive(gizmos); |
| 7 | 709 | | gizmoManager.SetGizmoType(gizmos); |
| 7 | 710 | | if (selectedEntities.Count > 0 ) |
| 0 | 711 | | gizmoManager.ShowGizmo(); |
| | 712 | | } |
| | 713 | | //TODO: Free-Movement tool, This could be re-enabled in the future so let the code there |
| | 714 | | // else |
| | 715 | | // { |
| | 716 | | // gizmoManager.HideGizmo(true); |
| | 717 | | // HUDController.i.builderInWorldMainHud?.SetGizmosActive(BIWSettings.EMPTY_GIZMO_NAME); |
| | 718 | | // } |
| 12 | 719 | | } |
| | 720 | |
|
| | 721 | | internal void OnGizmosTransformStart(string gizmoType) |
| | 722 | | { |
| 2 | 723 | | outlinerController.SetOutlineCheckActive(false); |
| 8 | 724 | | foreach (BIWEntity entity in selectedEntities) |
| | 725 | | { |
| 2 | 726 | | TransformActionStarted(entity.rootEntity, gizmoType); |
| | 727 | | } |
| 2 | 728 | | } |
| | 729 | |
|
| | 730 | | internal void OnGizmosTransformEnd(string gizmoType) |
| | 731 | | { |
| 1 | 732 | | outlinerController.SetOutlineCheckActive(true); |
| 4 | 733 | | foreach (BIWEntity entity in selectedEntities) |
| | 734 | | { |
| 1 | 735 | | TransformActionEnd(entity.rootEntity, gizmoType); |
| | 736 | | } |
| | 737 | |
|
| | 738 | | switch (gizmoType) |
| | 739 | | { |
| | 740 | | case BIWSettings.TRANSLATE_GIZMO_NAME: |
| | 741 | |
|
| 1 | 742 | | ActionFinish(BIWCompleteAction.ActionType.MOVE); |
| 1 | 743 | | break; |
| | 744 | | case BIWSettings.ROTATE_GIZMO_NAME: |
| 0 | 745 | | ActionFinish(BIWCompleteAction.ActionType.ROTATE); |
| 0 | 746 | | break; |
| | 747 | | case BIWSettings.SCALE_GIZMO_NAME: |
| 0 | 748 | | ActionFinish(BIWCompleteAction.ActionType.SCALE); |
| | 749 | | break; |
| | 750 | | } |
| | 751 | |
|
| 1 | 752 | | saveController.TryToSave(); |
| 1 | 753 | | } |
| | 754 | |
|
| | 755 | | #endregion |
| | 756 | |
|
| 2 | 757 | | public void FocusEntities(List<BIWEntity> entitiesToFocus) { freeCameraController.FocusOnEntities(entitiesToFocus); |
| | 758 | |
|
| | 759 | | internal Vector3 GetInitialCameraPosition(IParcelScene parcelScene) |
| | 760 | | { |
| 51 | 761 | | Vector3 middlePoint = BIWUtils.CalculateUnityMiddlePoint(parcelScene); |
| 51 | 762 | | Vector3 direction = (parcelScene.GetSceneTransform().position - middlePoint).normalized; |
| | 763 | |
|
| 51 | 764 | | return parcelScene.GetSceneTransform().position |
| | 765 | | + direction * initialEagleCameraDistance |
| | 766 | | + Vector3.up * initialEagleCameraHeight; |
| | 767 | | } |
| | 768 | |
|
| | 769 | | internal void SetLookAtObject(IParcelScene parcelScene) |
| | 770 | | { |
| 51 | 771 | | Vector3 middlePoint = BIWUtils.CalculateUnityMiddlePoint(parcelScene); |
| 51 | 772 | | lookAtTransform.position = middlePoint + Vector3.up * initialEagleCameraLookAtHeight; |
| 51 | 773 | | } |
| | 774 | |
|
| | 775 | | internal void SetEditObjectAtMouse() |
| | 776 | | { |
| 1 | 777 | | if (raycastController.RayCastFloor(out Vector3 destination)) |
| | 778 | | { |
| 1 | 779 | | if (isSnapActiveValue) |
| | 780 | | { |
| 0 | 781 | | destination.x = Mathf.Round(destination.x / snapDragFactor) * snapDragFactor; |
| 0 | 782 | | destination.z = Mathf.Round(destination.z / snapDragFactor) * snapDragFactor; |
| | 783 | | } |
| | 784 | |
|
| 1 | 785 | | editionGO.transform.position = destination; |
| | 786 | |
|
| 1 | 787 | | if (selectedEntities.Count > 0 && selectedEntities[0].isNFT) |
| 0 | 788 | | editionGO.transform.position += Vector3.up * 2f; |
| | 789 | | } |
| 1 | 790 | | } |
| | 791 | |
|
| 2 | 792 | | internal void ResetCamera() { freeCameraController.ResetCameraPosition(); } |
| | 793 | |
|
| | 794 | | internal void TakeSceneScreenshotForPublish() |
| | 795 | | { |
| 1 | 796 | | entityHandler.DeselectEntities(); |
| | 797 | |
|
| 1 | 798 | | freeCameraController.TakeSceneScreenshot((sceneSnapshot) => |
| | 799 | | { |
| 0 | 800 | | HUDController.i.builderInWorldMainHud?.SetBuilderProjectScreenshot(sceneSnapshot); |
| 0 | 801 | | }); |
| 1 | 802 | | } |
| | 803 | |
|
| | 804 | | public void TakeSceneScreenshotForExit() |
| | 805 | | { |
| 2 | 806 | | entityHandler.DeselectEntities(); |
| | 807 | |
|
| 2 | 808 | | freeCameraController.TakeSceneScreenshotFromResetPosition((sceneSnapshot) => |
| | 809 | | { |
| 0 | 810 | | HUDController.i.builderInWorldMainHud?.SetBuilderProjectScreenshot(sceneSnapshot); |
| 0 | 811 | | }); |
| 2 | 812 | | } |
| | 813 | |
|
| | 814 | | public void OpenNewProjectDetails() |
| | 815 | | { |
| 1 | 816 | | entityHandler.DeselectEntities(); |
| | 817 | |
|
| 1 | 818 | | freeCameraController.TakeSceneScreenshot((sceneSnapshot) => |
| | 819 | | { |
| 0 | 820 | | HUDController.i.builderInWorldMainHud?.NewProjectStart(sceneSnapshot); |
| 0 | 821 | | }); |
| 1 | 822 | | } |
| | 823 | | } |