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