| | 1 | | using System; |
| | 2 | | using Builder.Gizmos; |
| | 3 | | using DCL; |
| | 4 | | using DCL.Components; |
| | 5 | | using DCL.Configuration; |
| | 6 | | using DCL.Controllers; |
| | 7 | | using DCL.Helpers; |
| | 8 | | using DCL.Interface; |
| | 9 | | using DCL.Models; |
| | 10 | | using System.Collections; |
| | 11 | | using System.Collections.Generic; |
| | 12 | | using DCL.Camera; |
| | 13 | | using UnityEngine; |
| | 14 | | using UnityEngine.Rendering; |
| | 15 | | using Environment = DCL.Environment; |
| | 16 | | using Object = UnityEngine.Object; |
| | 17 | |
|
| | 18 | | namespace Builder |
| | 19 | | { |
| | 20 | | public class DCLBuilderBridge : MonoBehaviour |
| | 21 | | { |
| | 22 | | public DCLBuilderRaycast builderRaycast; |
| | 23 | |
|
| | 24 | | static bool LOG_MESSAGES = false; |
| | 25 | |
|
| | 26 | | public delegate void SetGridResolutionDelegate(float position, float rotation, float scale); |
| | 27 | |
|
| | 28 | | public static System.Action<float> OnZoomFromUI; |
| | 29 | | public static System.Action<string> OnSelectGizmo; |
| | 30 | | public static System.Action OnResetObject; |
| | 31 | | public static System.Action<DCLBuilderEntity> OnEntityAdded; |
| | 32 | | public static System.Action<DCLBuilderEntity> OnEntityRemoved; |
| | 33 | | public static System.Action<bool> OnPreviewModeChanged; |
| | 34 | | public static System.Action OnResetBuilderScene; |
| | 35 | | public static System.Action<Vector3> OnSetCameraPosition; |
| | 36 | | public static System.Action<float, float> OnSetCameraRotation; |
| | 37 | | public static System.Action OnResetCameraZoom; |
| | 38 | | public static System.Action<KeyCode> OnSetKeyDown; |
| | 39 | | public static event SetGridResolutionDelegate OnSetGridResolution; |
| | 40 | | public static System.Action<ParcelScene> OnSceneChanged; |
| | 41 | | public static System.Action<string[]> OnBuilderSelectEntity; |
| | 42 | |
|
| | 43 | | private MouseCatcher mouseCatcher; |
| | 44 | | private ParcelScene currentScene; |
| | 45 | | private CameraController cameraController; |
| | 46 | | private CursorController cursorController; |
| | 47 | | private Vector3 defaultCharacterPosition; |
| | 48 | |
|
| | 49 | | private bool isPreviewMode = false; |
| 1 | 50 | | private List<string> outOfBoundariesEntitiesId = new List<string>(); |
| | 51 | | private int lastEntitiesOutOfBoundariesCount = 0; |
| | 52 | | private List<EditableEntity> selectedEntities; |
| | 53 | | private bool entitiesMoved = false; |
| | 54 | |
|
| | 55 | | private bool isGameObjectActive = false; |
| | 56 | |
|
| | 57 | | private Coroutine screenshotCoroutine = null; |
| | 58 | |
|
| 1 | 59 | | private DCLBuilderWebInterface builderWebInterface = new DCLBuilderWebInterface(); |
| | 60 | |
|
| | 61 | | [System.Serializable] |
| | 62 | | private class MousePayload |
| | 63 | | { |
| 0 | 64 | | public string id = string.Empty; |
| | 65 | | public float x = 0; |
| | 66 | | public float y = 0; |
| | 67 | | } |
| | 68 | |
|
| | 69 | | [System.Serializable] |
| | 70 | | private class SetGridResolutionPayload |
| | 71 | | { |
| | 72 | | public float position = 0; |
| | 73 | | public float rotation = 0; |
| | 74 | | public float scale = 0; |
| | 75 | | } |
| | 76 | |
|
| | 77 | | [System.Serializable] |
| | 78 | | private class SelectedEntitiesPayload |
| | 79 | | { |
| | 80 | | public string[] entities = null; |
| | 81 | | }; |
| | 82 | |
|
| | 83 | | #region "Messages from Explorer" |
| | 84 | |
|
| | 85 | | public void PreloadFile(string url) |
| | 86 | | { |
| 0 | 87 | | if (LOG_MESSAGES) |
| 0 | 88 | | Debug.Log($"RECEIVE: PreloadFile {url}"); |
| 0 | 89 | | if (currentScene != null) |
| | 90 | | { |
| 0 | 91 | | string[] split = url.Split('\t'); |
| 0 | 92 | | string hash = split[0]; |
| 0 | 93 | | string file = split[1]; |
| | 94 | |
|
| 0 | 95 | | if (!currentScene.contentProvider.fileToHash.ContainsKey(file.ToLower())) |
| | 96 | | { |
| 0 | 97 | | currentScene.contentProvider.fileToHash.Add(file.ToLower(), hash); |
| | 98 | | } |
| | 99 | |
|
| 0 | 100 | | if (file.EndsWith(".glb") || file.EndsWith(".gltf")) |
| | 101 | | { |
| 0 | 102 | | AssetPromise_PrefetchGLTF gltfPromise = new AssetPromise_PrefetchGLTF(currentScene.contentProvider, |
| 0 | 103 | | AssetPromiseKeeper_GLTF.i.Keep(gltfPromise); |
| | 104 | | } |
| | 105 | | } |
| 0 | 106 | | } |
| | 107 | |
|
| | 108 | | public void GetMousePosition(string newJson) |
| | 109 | | { |
| 0 | 110 | | if (LOG_MESSAGES) |
| 0 | 111 | | Debug.Log($"RECEIVE: GetMousePosition {newJson}"); |
| 0 | 112 | | MousePayload m = Utils.SafeFromJson<MousePayload>(newJson); |
| | 113 | |
|
| 0 | 114 | | Vector3 mousePosition = new Vector3(m.x, Screen.height - m.y, 0); |
| | 115 | | Vector3 hitPoint; |
| | 116 | |
|
| 0 | 117 | | if (builderRaycast.RaycastToGround(mousePosition, out hitPoint)) |
| | 118 | | { |
| 0 | 119 | | if (LOG_MESSAGES) |
| 0 | 120 | | Debug.Log($"SEND: ReportMousePosition {m.id} {hitPoint}"); |
| 0 | 121 | | WebInterface.ReportMousePosition(hitPoint, m.id); |
| | 122 | | } |
| 0 | 123 | | } |
| | 124 | |
|
| | 125 | | public void SelectGizmo(string gizmoType) |
| | 126 | | { |
| 0 | 127 | | if (LOG_MESSAGES) |
| 0 | 128 | | Debug.Log($"RECEIVE: SelectGizmo {gizmoType}"); |
| 0 | 129 | | OnSelectGizmo?.Invoke(gizmoType); |
| 0 | 130 | | } |
| | 131 | |
|
| | 132 | | public void ResetObject() |
| | 133 | | { |
| 0 | 134 | | if (LOG_MESSAGES) |
| 0 | 135 | | Debug.Log($"RECEIVE: ResetObject"); |
| 0 | 136 | | OnResetObject?.Invoke(); |
| 0 | 137 | | } |
| | 138 | |
|
| | 139 | | public void ZoomDelta(string delta) |
| | 140 | | { |
| 0 | 141 | | if (LOG_MESSAGES) |
| 0 | 142 | | Debug.Log($"RECEIVE: ZoomDelta {delta}"); |
| 0 | 143 | | float d = 0; |
| 0 | 144 | | if (float.TryParse(delta, out d)) |
| | 145 | | { |
| 0 | 146 | | OnZoomFromUI?.Invoke(d); |
| | 147 | | } |
| 0 | 148 | | } |
| | 149 | |
|
| | 150 | | public void SetPlayMode(string on) |
| | 151 | | { |
| 0 | 152 | | if (LOG_MESSAGES) |
| 0 | 153 | | Debug.Log($"RECEIVE: SetPlayMode {on}"); |
| 0 | 154 | | bool isPreview = false; |
| 0 | 155 | | if (bool.TryParse(on, out isPreview)) |
| | 156 | | { |
| 0 | 157 | | SetPlayMode(isPreview); |
| | 158 | | } |
| 0 | 159 | | } |
| | 160 | |
|
| | 161 | | public void TakeScreenshot(string id) |
| | 162 | | { |
| 0 | 163 | | if (LOG_MESSAGES) |
| 0 | 164 | | Debug.Log($"RECEIVE: TakeScreenshot {id}"); |
| 0 | 165 | | if (screenshotCoroutine != null) |
| | 166 | | { |
| 0 | 167 | | StopCoroutine(screenshotCoroutine); |
| | 168 | | } |
| | 169 | |
|
| 0 | 170 | | screenshotCoroutine = StartCoroutine(TakeScreenshotRoutine(id)); |
| 0 | 171 | | } |
| | 172 | |
|
| | 173 | | public void ResetBuilderScene() |
| | 174 | | { |
| 1 | 175 | | if (LOG_MESSAGES) |
| 0 | 176 | | Debug.Log($"RECEIVE: ResetBuilderScene"); |
| 1 | 177 | | OnResetBuilderScene?.Invoke(); |
| 1 | 178 | | DCLCharacterController.i?.gameObject.SetActive(false); |
| 1 | 179 | | outOfBoundariesEntitiesId.Clear(); |
| | 180 | |
|
| 1 | 181 | | if (currentScene) |
| | 182 | | { |
| 0 | 183 | | currentScene.OnEntityAdded -= OnEntityIsAdded; |
| 0 | 184 | | currentScene.OnEntityRemoved -= OnEntityIsRemoved; |
| | 185 | | } |
| | 186 | |
|
| 1 | 187 | | SetCurrentScene(); |
| 1 | 188 | | HideHUDs(); |
| 1 | 189 | | } |
| | 190 | |
|
| | 191 | | public void SetBuilderCameraPosition(string position) |
| | 192 | | { |
| 0 | 193 | | if (LOG_MESSAGES) |
| 0 | 194 | | Debug.Log($"RECEIVE: SetBuilderCameraPosition {position}"); |
| 0 | 195 | | if (!string.IsNullOrEmpty(position)) |
| | 196 | | { |
| 0 | 197 | | string[] splitPositionStr = position.Split(','); |
| 0 | 198 | | if (splitPositionStr.Length == 3) |
| | 199 | | { |
| 0 | 200 | | float x, y, z = 0; |
| 0 | 201 | | float.TryParse(splitPositionStr[0], out x); |
| 0 | 202 | | float.TryParse(splitPositionStr[1], out y); |
| 0 | 203 | | float.TryParse(splitPositionStr[2], out z); |
| | 204 | |
|
| 0 | 205 | | if (isPreviewMode) |
| | 206 | | { |
| 0 | 207 | | DCLCharacterController.i?.SetPosition(new Vector3(x, y, z)); |
| 0 | 208 | | } |
| | 209 | | else |
| | 210 | | { |
| 0 | 211 | | OnSetCameraPosition?.Invoke(new Vector3(x, y, z)); |
| | 212 | | } |
| | 213 | | } |
| | 214 | | } |
| 0 | 215 | | } |
| | 216 | |
|
| | 217 | | public void SetBuilderCameraRotation(string yawpitchRotation) |
| | 218 | | { |
| 0 | 219 | | if (LOG_MESSAGES) |
| 0 | 220 | | Debug.Log($"RECEIVE: SetBuilderCameraRotation {yawpitchRotation}"); |
| 0 | 221 | | if (!string.IsNullOrEmpty(yawpitchRotation)) |
| | 222 | | { |
| 0 | 223 | | string[] splitRotationStr = yawpitchRotation.Split(','); |
| 0 | 224 | | if (splitRotationStr.Length == 2) |
| | 225 | | { |
| 0 | 226 | | float yaw, pitch = 0; |
| 0 | 227 | | float.TryParse(splitRotationStr[0], out yaw); |
| 0 | 228 | | float.TryParse(splitRotationStr[1], out pitch); |
| | 229 | |
|
| 0 | 230 | | if (isPreviewMode) |
| | 231 | | { |
| 0 | 232 | | if (DCLCharacterController.i != null) |
| | 233 | | { |
| 0 | 234 | | DCLCharacterController.i.transform.rotation = Quaternion.Euler(0f, yaw * Mathf.Rad2Deg, 0f); |
| | 235 | | } |
| | 236 | |
|
| 0 | 237 | | if (cameraController) |
| | 238 | | { |
| 0 | 239 | | var cameraRotation = new CameraController.SetRotationPayload() |
| | 240 | | { |
| | 241 | | x = pitch * Mathf.Rad2Deg, |
| | 242 | | y = 0, |
| | 243 | | z = 0 |
| | 244 | | }; |
| 0 | 245 | | cameraController.SetRotation(JsonUtility.ToJson(cameraRotation)); |
| | 246 | | } |
| 0 | 247 | | } |
| | 248 | | else |
| | 249 | | { |
| 0 | 250 | | OnSetCameraRotation?.Invoke(yaw * Mathf.Rad2Deg, pitch * Mathf.Rad2Deg); |
| | 251 | | } |
| | 252 | | } |
| | 253 | | } |
| 0 | 254 | | } |
| | 255 | |
|
| | 256 | | public void ResetBuilderCameraZoom() |
| | 257 | | { |
| 0 | 258 | | if (LOG_MESSAGES) |
| 0 | 259 | | Debug.Log($"RECEIVE: ResetBuilderCameraZoom"); |
| 0 | 260 | | OnResetCameraZoom?.Invoke(); |
| 0 | 261 | | } |
| | 262 | |
|
| | 263 | | public void SetGridResolution(string payloadJson) |
| | 264 | | { |
| 0 | 265 | | if (LOG_MESSAGES) |
| 0 | 266 | | Debug.Log($"RECEIVE: SetGridResolution {payloadJson}"); |
| | 267 | | try |
| | 268 | | { |
| 0 | 269 | | SetGridResolutionPayload payload = JsonUtility.FromJson<SetGridResolutionPayload>(payloadJson); |
| 0 | 270 | | OnSetGridResolution?.Invoke(payload.position, payload.rotation, payload.scale); |
| 0 | 271 | | } |
| 0 | 272 | | catch (System.ArgumentException e) |
| | 273 | | { |
| 0 | 274 | | Debug.LogError("Error parsing bBuilder's SetGridResolution Json = " + payloadJson + " " + e.ToString()); |
| 0 | 275 | | } |
| 0 | 276 | | } |
| | 277 | |
|
| | 278 | | public void OnBuilderKeyDown(string key) |
| | 279 | | { |
| | 280 | | KeyCode keyCode; |
| 0 | 281 | | if (System.Enum.TryParse(key, false, out keyCode)) |
| | 282 | | { |
| 0 | 283 | | OnSetKeyDown?.Invoke(keyCode); |
| | 284 | | } |
| 0 | 285 | | } |
| | 286 | |
|
| | 287 | | public void UnloadBuilderScene(string sceneKey) |
| | 288 | | { |
| 0 | 289 | | if (LOG_MESSAGES) |
| 0 | 290 | | Debug.Log($"RECEIVE: UnloadBuilderScene {sceneKey}"); |
| 0 | 291 | | Environment.i.world.sceneController.UnloadScene(sceneKey); |
| 0 | 292 | | } |
| | 293 | |
|
| | 294 | | public void SetSelectedEntities(string msj) |
| | 295 | | { |
| 0 | 296 | | if (LOG_MESSAGES) |
| 0 | 297 | | Debug.Log($"RECEIVE: SelectEntity {msj}"); |
| 0 | 298 | | SelectedEntitiesPayload payload = JsonUtility.FromJson<SelectedEntitiesPayload>(msj); |
| 0 | 299 | | OnBuilderSelectEntity?.Invoke(payload.entities); |
| 0 | 300 | | } |
| | 301 | |
|
| | 302 | | public void GetCameraTargetBuilder(string id) |
| | 303 | | { |
| 0 | 304 | | if (LOG_MESSAGES) |
| 0 | 305 | | Debug.Log($"RECEIVE: GetCameraTargetBuilder {id}"); |
| | 306 | | Vector3 targetPosition; |
| 0 | 307 | | Camera builderCamera = builderRaycast.builderCamera; |
| 0 | 308 | | if (builderRaycast.RaycastToGround(builderCamera.ScreenPointToRay(new Vector3(Screen.width * 0.5f, Screen.he |
| | 309 | | out targetPosition)) |
| | 310 | | { |
| 0 | 311 | | builderWebInterface.SendCameraTargetPosition(targetPosition, id); |
| | 312 | | } |
| 0 | 313 | | } |
| | 314 | |
|
| | 315 | | public void SetBuilderConfiguration(string payloadJson) |
| | 316 | | { |
| 0 | 317 | | if (LOG_MESSAGES) |
| 0 | 318 | | Debug.Log($"RECEIVE: SetBuilderConfiguration {payloadJson}"); |
| 0 | 319 | | DCLBuilderConfig.SetConfig(payloadJson); |
| | 320 | |
|
| 0 | 321 | | if (!currentScene) |
| 0 | 322 | | return; |
| | 323 | |
|
| 0 | 324 | | if (DCLBuilderConfig.config.environment.disableFloor) |
| | 325 | | { |
| 0 | 326 | | currentScene.RemoveDebugPlane(); |
| 0 | 327 | | } |
| | 328 | | else |
| | 329 | | { |
| 0 | 330 | | currentScene.InitializeDebugPlane(); |
| | 331 | | } |
| 0 | 332 | | } |
| | 333 | |
|
| | 334 | | #endregion |
| | 335 | |
|
| | 336 | | private static ParcelScene GetLoadedScene() |
| | 337 | | { |
| 2 | 338 | | ParcelScene loadedScene = null; |
| 2 | 339 | | IWorldState worldState = Environment.i.world.state; |
| | 340 | |
|
| 2 | 341 | | if (worldState != null && worldState.loadedScenes.Count > 0) |
| | 342 | | { |
| 2 | 343 | | using (var iterator = worldState.loadedScenes.GetEnumerator()) |
| | 344 | | { |
| 2 | 345 | | iterator.MoveNext(); |
| 2 | 346 | | loadedScene = iterator.Current.Value as ParcelScene; |
| 2 | 347 | | } |
| | 348 | | } |
| | 349 | |
|
| 2 | 350 | | return loadedScene; |
| | 351 | | } |
| | 352 | |
|
| | 353 | | private void Awake() |
| | 354 | | { |
| | 355 | | // NOTE: we need to set the quality settings before renderer pipeline is copy and modified |
| 1 | 356 | | SetupQualitySettings(); |
| 1 | 357 | | SetupRendererPipeline(); |
| | 358 | |
|
| 1 | 359 | | cameraController = Object.FindObjectOfType<CameraController>(); |
| 1 | 360 | | cursorController = Object.FindObjectOfType<CursorController>(); |
| 1 | 361 | | mouseCatcher = InitialSceneReferences.i?.mouseCatcher; |
| 1 | 362 | | var playerAvatarController = Object.FindObjectOfType<PlayerAvatarController>(); |
| | 363 | |
|
| 1 | 364 | | if (mouseCatcher != null) |
| | 365 | | { |
| 0 | 366 | | mouseCatcher.enabled = false; |
| | 367 | | } |
| | 368 | |
|
| 1 | 369 | | if (DCLCharacterController.i) |
| | 370 | | { |
| 1 | 371 | | defaultCharacterPosition = DCLCharacterController.i.transform.position; |
| 1 | 372 | | DCLCharacterController.i.initialPositionAlreadySet = true; |
| 1 | 373 | | DCLCharacterController.i.characterAlwaysEnabled = false; |
| 1 | 374 | | DCLCharacterController.i.gameObject.SetActive(false); |
| | 375 | | } |
| | 376 | |
|
| 1 | 377 | | if (cameraController) |
| | 378 | | { |
| 1 | 379 | | cameraController.gameObject.SetActive(false); |
| | 380 | | } |
| | 381 | |
|
| 1 | 382 | | if (cursorController) |
| | 383 | | { |
| 1 | 384 | | cursorController.gameObject.SetActive(false); |
| | 385 | | } |
| | 386 | |
|
| | 387 | | // NOTE: no third person camera in builder yet, so avoid rendering being locked waiting for avatar. |
| 1 | 388 | | if (playerAvatarController) |
| | 389 | | { |
| 1 | 390 | | CommonScriptableObjects.rendererState.RemoveLock(playerAvatarController); |
| | 391 | | } |
| | 392 | |
|
| 1 | 393 | | Environment.i.platform.debugController.HideFPSPanel(); |
| 1 | 394 | | SetCaptureKeyboardInputEnabled(false); |
| 1 | 395 | | } |
| | 396 | |
|
| | 397 | | private void Start() |
| | 398 | | { |
| 1 | 399 | | SetCurrentScene(); |
| 1 | 400 | | builderWebInterface.SendBuilderSceneStart(currentScene.sceneData.id); |
| 1 | 401 | | } |
| | 402 | |
|
| | 403 | | private void Update() |
| | 404 | | { |
| 11 | 405 | | if (lastEntitiesOutOfBoundariesCount != outOfBoundariesEntitiesId.Count) |
| | 406 | | { |
| 0 | 407 | | lastEntitiesOutOfBoundariesCount = outOfBoundariesEntitiesId.Count; |
| 0 | 408 | | SendOutOfBoundariesEntities(); |
| | 409 | | } |
| 11 | 410 | | } |
| | 411 | |
|
| | 412 | | private void OnEntityIsAdded(IDCLEntity entity) |
| | 413 | | { |
| 1 | 414 | | if (isPreviewMode) |
| 0 | 415 | | return; |
| | 416 | |
|
| 1 | 417 | | var builderEntity = AddBuilderEntityComponent(entity); |
| 1 | 418 | | OnEntityAdded?.Invoke(builderEntity); |
| | 419 | |
|
| 1 | 420 | | entity.OnShapeUpdated += OnEntityShapeUpdated; |
| | 421 | |
|
| 1 | 422 | | builderWebInterface.SendEntityStartLoad(entity); |
| 1 | 423 | | } |
| | 424 | |
|
| | 425 | | private void OnEntityIsRemoved(IDCLEntity entity) |
| | 426 | | { |
| 1 | 427 | | var builderEntity = entity.gameObject.GetComponent<DCLBuilderEntity>(); |
| | 428 | |
|
| 1 | 429 | | if (builderEntity != null) |
| | 430 | | { |
| 1 | 431 | | OnEntityRemoved?.Invoke(builderEntity); |
| | 432 | | } |
| 0 | 433 | | } |
| | 434 | |
|
| | 435 | | private void OnEntityShapeUpdated(IDCLEntity entity) |
| | 436 | | { |
| 1 | 437 | | entity.OnShapeUpdated -= OnEntityShapeUpdated; |
| | 438 | |
|
| 1 | 439 | | builderWebInterface.SendEntityFinishLoad(entity); |
| 1 | 440 | | } |
| | 441 | |
|
| | 442 | | private void OnEnable() |
| | 443 | | { |
| 1 | 444 | | if (!isGameObjectActive) |
| | 445 | | { |
| 1 | 446 | | DCLBuilderObjectDragger.OnDraggingObjectEnd += OnObjectDragEnd; |
| 1 | 447 | | DCLBuilderObjectDragger.OnDraggingObject += OnObjectDrag; |
| 1 | 448 | | DCLBuilderObjectSelector.OnMarkObjectSelected += OnObjectSelected; |
| 1 | 449 | | DCLBuilderObjectSelector.OnNoObjectSelected += OnNoObjectSelected; |
| 1 | 450 | | DCLBuilderObjectSelector.OnSelectedObjectListChanged += OnSelectionChanged; |
| 1 | 451 | | DCLBuilderGizmoManager.OnGizmoTransformObjectEnd += OnGizmoTransformObjectEnded; |
| 1 | 452 | | DCLBuilderGizmoManager.OnGizmoTransformObject += OnGizmoTransformObject; |
| 1 | 453 | | DCLBuilderEntity.OnEntityShapeUpdated += ProcessEntityBoundaries; |
| 1 | 454 | | DCLBuilderEntity.OnEntityTransformUpdated += ProcessEntityBoundaries; |
| 1 | 455 | | CommonScriptableObjects.rendererState.OnChange += OnRenderingStateChanged; |
| | 456 | | } |
| | 457 | |
|
| 1 | 458 | | isGameObjectActive = true; |
| 1 | 459 | | } |
| | 460 | |
|
| | 461 | | private void OnDisable() |
| | 462 | | { |
| 1 | 463 | | isGameObjectActive = false; |
| 1 | 464 | | DCLBuilderObjectDragger.OnDraggingObjectEnd -= OnObjectDragEnd; |
| 1 | 465 | | DCLBuilderObjectDragger.OnDraggingObject -= OnObjectDrag; |
| 1 | 466 | | DCLBuilderObjectSelector.OnMarkObjectSelected -= OnObjectSelected; |
| 1 | 467 | | DCLBuilderObjectSelector.OnNoObjectSelected -= OnNoObjectSelected; |
| 1 | 468 | | DCLBuilderObjectSelector.OnSelectedObjectListChanged -= OnSelectionChanged; |
| 1 | 469 | | DCLBuilderGizmoManager.OnGizmoTransformObjectEnd -= OnGizmoTransformObjectEnded; |
| 1 | 470 | | DCLBuilderGizmoManager.OnGizmoTransformObject -= OnGizmoTransformObject; |
| 1 | 471 | | DCLBuilderEntity.OnEntityShapeUpdated -= ProcessEntityBoundaries; |
| 1 | 472 | | DCLBuilderEntity.OnEntityTransformUpdated -= ProcessEntityBoundaries; |
| 1 | 473 | | CommonScriptableObjects.rendererState.OnChange -= OnRenderingStateChanged; |
| 1 | 474 | | } |
| | 475 | |
|
| | 476 | | private void OnObjectDragEnd() |
| | 477 | | { |
| 0 | 478 | | if (selectedEntities != null && entitiesMoved) |
| | 479 | | { |
| 0 | 480 | | NotifyGizmosTransformEvent(selectedEntities, DCLGizmos.Gizmo.NONE); |
| | 481 | | } |
| | 482 | |
|
| 0 | 483 | | entitiesMoved = false; |
| 0 | 484 | | } |
| | 485 | |
|
| | 486 | | private void OnObjectDrag() |
| | 487 | | { |
| 0 | 488 | | EvaluateSelectedEntitiesPosition(); |
| 0 | 489 | | entitiesMoved = true; |
| 0 | 490 | | } |
| | 491 | |
|
| | 492 | | private void OnGizmoTransformObjectEnded(string gizmoType) |
| | 493 | | { |
| 0 | 494 | | if (selectedEntities != null && entitiesMoved) |
| | 495 | | { |
| 0 | 496 | | NotifyGizmosTransformEvent(selectedEntities, gizmoType); |
| | 497 | | } |
| | 498 | |
|
| 0 | 499 | | entitiesMoved = false; |
| 0 | 500 | | } |
| | 501 | |
|
| | 502 | | private void OnGizmoTransformObject(string gizmoType) |
| | 503 | | { |
| 0 | 504 | | EvaluateSelectedEntitiesPosition(); |
| 0 | 505 | | entitiesMoved = true; |
| 0 | 506 | | } |
| | 507 | |
|
| 0 | 508 | | private void OnObjectSelected(EditableEntity entity, string gizmoType) { NotifyGizmosSelectedEvent(entity, gizmo |
| | 509 | |
|
| 0 | 510 | | private void OnNoObjectSelected() { NotifyGizmosSelectedEvent(null, DCLGizmos.Gizmo.NONE); } |
| | 511 | |
|
| 0 | 512 | | private void OnSelectionChanged(Transform selectionParent, List<EditableEntity> selectedEntitiesList) { selected |
| | 513 | |
|
| 0 | 514 | | private void NotifyGizmosTransformEvent(List<EditableEntity> entities, string gizmoType) { builderWebInterface.S |
| | 515 | |
|
| 0 | 516 | | private void NotifyGizmosSelectedEvent(EditableEntity entity, string gizmoType) { builderWebInterface.SendEntity |
| | 517 | |
|
| | 518 | | private IEnumerator TakeScreenshotRoutine(string id) |
| | 519 | | { |
| 0 | 520 | | yield return new WaitForEndOfFrame(); |
| | 521 | |
|
| 0 | 522 | | var texture = ScreenCapture.CaptureScreenshotAsTexture(); |
| 0 | 523 | | if (LOG_MESSAGES) |
| 0 | 524 | | Debug.Log($"SEND: SendScreenshot {id}"); |
| 0 | 525 | | WebInterface.SendScreenshot("data:image/png;base64," + System.Convert.ToBase64String(texture.EncodeToPNG()), |
| 0 | 526 | | Destroy(texture); |
| 0 | 527 | | } |
| | 528 | |
|
| | 529 | | private void SetPlayMode(bool isPreview) |
| | 530 | | { |
| 0 | 531 | | isPreviewMode = isPreview; |
| 0 | 532 | | OnPreviewModeChanged?.Invoke(isPreview); |
| | 533 | |
|
| 0 | 534 | | if (DCLCharacterController.i) |
| | 535 | | { |
| 0 | 536 | | DCLCharacterController.i.SetPosition(defaultCharacterPosition); |
| 0 | 537 | | DCLCharacterController.i.gameObject.SetActive(isPreview); |
| 0 | 538 | | DCLCharacterController.i.ResetGround(); |
| | 539 | | } |
| | 540 | |
|
| 0 | 541 | | if (mouseCatcher != null) |
| | 542 | | { |
| 0 | 543 | | mouseCatcher.enabled = isPreview; |
| 0 | 544 | | if (!isPreview) |
| 0 | 545 | | mouseCatcher.UnlockCursor(); |
| | 546 | | } |
| | 547 | |
|
| 0 | 548 | | cameraController?.gameObject.SetActive(isPreviewMode); |
| 0 | 549 | | cursorController?.gameObject.SetActive(isPreviewMode); |
| | 550 | |
|
| 0 | 551 | | if (!isPreview) |
| | 552 | | { |
| 0 | 553 | | HideHUDs(); |
| | 554 | | } |
| | 555 | |
|
| 0 | 556 | | SetCaptureKeyboardInputEnabled(isPreview); |
| 0 | 557 | | } |
| | 558 | |
|
| | 559 | | private void OnRenderingStateChanged(bool renderingEnabled, bool prevState) |
| | 560 | | { |
| 0 | 561 | | if (renderingEnabled) |
| | 562 | | { |
| 0 | 563 | | ParcelSettings.VISUAL_LOADING_ENABLED = false; |
| | 564 | | } |
| 0 | 565 | | } |
| | 566 | |
|
| | 567 | | private void SetCaptureKeyboardInputEnabled(bool value) |
| | 568 | | { |
| | 569 | | #if !(UNITY_EDITOR || UNITY_STANDALONE) && UNITY_WEBGL |
| | 570 | | WebGLInput.captureAllKeyboardInput = value; |
| | 571 | | #endif |
| 0 | 572 | | } |
| | 573 | |
|
| | 574 | | private void SetCurrentScene() |
| | 575 | | { |
| 2 | 576 | | currentScene = GetLoadedScene(); |
| | 577 | |
|
| 2 | 578 | | if (currentScene) |
| | 579 | | { |
| 2 | 580 | | currentScene.OnEntityAdded += OnEntityIsAdded; |
| 2 | 581 | | currentScene.OnEntityRemoved += OnEntityIsRemoved; |
| 2 | 582 | | currentScene.metricsController = new DCLBuilderSceneMetricsController(currentScene); |
| | 583 | |
|
| 2 | 584 | | if (DCLBuilderConfig.config.environment.disableFloor) |
| | 585 | | { |
| 0 | 586 | | currentScene.RemoveDebugPlane(); |
| 0 | 587 | | } |
| | 588 | | else |
| | 589 | | { |
| 2 | 590 | | currentScene.InitializeDebugPlane(); |
| | 591 | | } |
| | 592 | |
|
| 2 | 593 | | OnSceneChanged?.Invoke(currentScene); |
| | 594 | | } |
| 2 | 595 | | } |
| | 596 | |
|
| | 597 | | private void HideHUDs() |
| | 598 | | { |
| | 599 | | IHUD hud; |
| 62 | 600 | | for (int i = 0; i < (int)HUDElementID.COUNT; i++) |
| | 601 | | { |
| 30 | 602 | | hud = Environment.i.hud.controller.GetHUDElement((HUDElementID) i); |
| 30 | 603 | | if (hud != null) |
| | 604 | | { |
| 0 | 605 | | hud.SetVisibility(false); |
| | 606 | | } |
| | 607 | | } |
| 1 | 608 | | } |
| | 609 | |
|
| | 610 | | private void OnDestroy() |
| | 611 | | { |
| 1 | 612 | | if (currentScene) |
| | 613 | | { |
| 1 | 614 | | currentScene.OnEntityAdded -= OnEntityIsAdded; |
| 1 | 615 | | currentScene.OnEntityRemoved -= OnEntityIsRemoved; |
| | 616 | | } |
| 1 | 617 | | } |
| | 618 | |
|
| | 619 | | private DCLBuilderEntity AddBuilderEntityComponent(IDCLEntity entity) |
| | 620 | | { |
| 1 | 621 | | DCLBuilderEntity builderComponent = Utils.GetOrCreateComponent<DCLBuilderEntity>(entity.gameObject); |
| 1 | 622 | | builderComponent.SetEntity(entity); |
| 1 | 623 | | return builderComponent; |
| | 624 | | } |
| | 625 | |
|
| | 626 | | private void ProcessEntityBoundaries(DCLBuilderEntity entity) |
| | 627 | | { |
| 1 | 628 | | string entityId = entity.rootEntity.entityId; |
| 1 | 629 | | int entityIndexInList = outOfBoundariesEntitiesId.IndexOf(entityId); |
| | 630 | |
|
| 1 | 631 | | bool wasInsideSceneBoundaries = entityIndexInList == -1; |
| 1 | 632 | | bool isInsideSceneBoundaries = entity.IsInsideSceneBoundaries(); |
| | 633 | |
|
| 1 | 634 | | if (wasInsideSceneBoundaries && !isInsideSceneBoundaries) |
| | 635 | | { |
| 0 | 636 | | outOfBoundariesEntitiesId.Add(entityId); |
| 0 | 637 | | } |
| 1 | 638 | | else if (!wasInsideSceneBoundaries && isInsideSceneBoundaries) |
| | 639 | | { |
| 0 | 640 | | outOfBoundariesEntitiesId.RemoveAt(entityIndexInList); |
| | 641 | | } |
| | 642 | |
|
| 1 | 643 | | Environment.i.world.sceneBoundsChecker?.EvaluateEntityPosition(entity.rootEntity); |
| 1 | 644 | | } |
| | 645 | |
|
| 0 | 646 | | private void SendOutOfBoundariesEntities() { builderWebInterface.SendEntitiesOutOfBoundaries(outOfBoundariesEnti |
| | 647 | |
|
| | 648 | | private void EvaluateSelectedEntitiesPosition() |
| | 649 | | { |
| 0 | 650 | | if (selectedEntities != null) |
| | 651 | | { |
| 0 | 652 | | for (int i = 0; i < selectedEntities.Count; i++) |
| | 653 | | { |
| 0 | 654 | | Environment.i.world.sceneBoundsChecker?.EvaluateEntityPosition(selectedEntities[i].rootEntity); |
| | 655 | | } |
| | 656 | | } |
| 0 | 657 | | } |
| | 658 | |
|
| | 659 | | private void SetupRendererPipeline() |
| | 660 | | { |
| 1 | 661 | | UnityEngine.Rendering.Universal.UniversalRenderPipelineAsset lwrpa = ScriptableObject.Instantiate(GraphicsSe |
| | 662 | |
|
| 1 | 663 | | if (lwrpa != null) |
| | 664 | | { |
| 1 | 665 | | lwrpa.shadowDepthBias = 3; |
| 1 | 666 | | lwrpa.shadowDistance = 80f; |
| 1 | 667 | | GraphicsSettings.renderPipelineAsset = lwrpa; |
| | 668 | | } |
| 1 | 669 | | } |
| | 670 | |
|
| | 671 | | private void SetupQualitySettings() |
| | 672 | | { |
| 1 | 673 | | DCL.SettingsData.QualitySettings settings = new DCL.SettingsData.QualitySettings() |
| | 674 | | { |
| | 675 | | baseResolution = DCL.SettingsData.QualitySettings.BaseResolution.BaseRes_1080, |
| | 676 | | antiAliasing = UnityEngine.Rendering.Universal.MsaaQuality._2x, |
| | 677 | | renderScale = 1, |
| | 678 | | shadows = true, |
| | 679 | | softShadows = true, |
| | 680 | | shadowResolution = UnityEngine.Rendering.Universal.ShadowResolution._256, |
| | 681 | | cameraDrawDistance = 100, |
| | 682 | | bloom = true, |
| | 683 | | colorGrading = true |
| | 684 | | }; |
| 1 | 685 | | Settings.i.ApplyQualitySettings(settings); |
| 1 | 686 | | } |
| | 687 | | } |
| | 688 | | } |