| | 1 | | using System.Collections.Generic; |
| | 2 | | using UnityEngine; |
| | 3 | | using DCL.Interface; |
| | 4 | | using DCL.Components; |
| | 5 | | using DCL.Models; |
| | 6 | |
|
| | 7 | | namespace Builder |
| | 8 | | { |
| | 9 | | public class DCLBuilderWebInterface |
| | 10 | | { |
| 1 | 11 | | static bool LOG_MESSAGES = false; |
| | 12 | |
|
| | 13 | | [System.Serializable] |
| | 14 | | private class EntityLoadingPayload |
| | 15 | | { |
| | 16 | | public string type; |
| | 17 | | public string entityId; |
| | 18 | | }; |
| | 19 | |
|
| | 20 | | [System.Serializable] |
| | 21 | | private class OnEntityLoadingEvent : DCL.Interface.WebInterface.UUIDEvent<EntityLoadingPayload> { }; |
| | 22 | |
|
| | 23 | | [System.Serializable] |
| | 24 | | private class EntitiesOutOfBoundariesEventPayload |
| | 25 | | { |
| | 26 | | public string[] entities; |
| | 27 | | }; |
| | 28 | |
|
| | 29 | | [System.Serializable] |
| | 30 | | public class BuilderSceneStartEvent |
| | 31 | | { |
| | 32 | | public string sceneId; |
| 0 | 33 | | public string eventType = "builderSceneStart"; |
| | 34 | | }; |
| | 35 | |
|
| | 36 | | [System.Serializable] |
| | 37 | | private class ReportCameraTargetPosition |
| | 38 | | { |
| | 39 | | public Vector3 cameraTarget; |
| | 40 | | public string id; |
| | 41 | | }; |
| | 42 | |
|
| | 43 | | [System.Serializable] |
| | 44 | | private class GizmosEventPayload |
| | 45 | | { |
| | 46 | | [System.Serializable] |
| | 47 | | public class TransformPayload |
| | 48 | | { |
| 0 | 49 | | public string entityId = string.Empty; |
| 0 | 50 | | public Vector3 position = Vector3.zero; |
| 0 | 51 | | public Quaternion rotation = Quaternion.identity; |
| 0 | 52 | | public Vector3 scale = Vector3.one; |
| | 53 | | } |
| | 54 | |
|
| | 55 | | public string[] entities = null; |
| | 56 | | public TransformPayload[] transforms = null; |
| 1 | 57 | | public string gizmoType = DCLGizmos.Gizmo.NONE; |
| 1 | 58 | | public string type = string.Empty; |
| | 59 | | }; |
| | 60 | |
|
| 1 | 61 | | private static OnEntityLoadingEvent onGetLoadingEntity = new OnEntityLoadingEvent(); |
| 1 | 62 | | private static EntitiesOutOfBoundariesEventPayload outOfBoundariesEventPayload = new EntitiesOutOfBoundariesEven |
| 1 | 63 | | private static ReportCameraTargetPosition onReportCameraTarget = new ReportCameraTargetPosition(); |
| 1 | 64 | | private static GizmosEventPayload onGizmoEventPayload = new GizmosEventPayload(); |
| | 65 | |
|
| | 66 | | public void SendEntityStartLoad(IDCLEntity entity) |
| | 67 | | { |
| 1 | 68 | | onGetLoadingEntity.uuid = entity.entityId; |
| 1 | 69 | | onGetLoadingEntity.payload.entityId = entity.entityId; |
| 1 | 70 | | onGetLoadingEntity.payload.type = "onEntityLoading"; |
| 1 | 71 | | if (LOG_MESSAGES) |
| 0 | 72 | | Debug.Log($"SEND: OnEntityLoadingEvent {entity.entityId}"); |
| 1 | 73 | | WebInterface.SendSceneEvent(entity.scene.sceneData.id, "uuidEvent", onGetLoadingEntity); |
| 1 | 74 | | } |
| | 75 | |
|
| | 76 | | public void SendEntityFinishLoad(IDCLEntity entity) |
| | 77 | | { |
| 1 | 78 | | onGetLoadingEntity.uuid = entity.entityId; |
| 1 | 79 | | onGetLoadingEntity.payload.entityId = entity.entityId; |
| 1 | 80 | | onGetLoadingEntity.payload.type = "onEntityFinishLoading"; |
| 1 | 81 | | if (LOG_MESSAGES) |
| 0 | 82 | | Debug.Log($"SEND: onEntityFinishLoading {entity.entityId}"); |
| 1 | 83 | | WebInterface.SendSceneEvent(entity.scene.sceneData.id, "uuidEvent", onGetLoadingEntity); |
| 1 | 84 | | } |
| | 85 | |
|
| | 86 | | public void SendEntitiesOutOfBoundaries(string[] entitiesId, string sceneId) |
| | 87 | | { |
| 0 | 88 | | outOfBoundariesEventPayload.entities = entitiesId; |
| 0 | 89 | | if (LOG_MESSAGES) |
| 0 | 90 | | Debug.Log($"SEND: entitiesOutOfBoundaries {outOfBoundariesEventPayload.entities.Length}"); |
| 0 | 91 | | WebInterface.SendSceneEvent<EntitiesOutOfBoundariesEventPayload>(sceneId, "entitiesOutOfBoundaries", outOfBo |
| 0 | 92 | | } |
| | 93 | |
|
| | 94 | | public void SendBuilderSceneStart(string sceneId) |
| | 95 | | { |
| 1 | 96 | | if (LOG_MESSAGES) |
| 0 | 97 | | Debug.Log($"SEND: BuilderSceneStartEvent {sceneId}"); |
| 1 | 98 | | WebInterface.SendMessage("SceneEvent", new BuilderSceneStartEvent() { sceneId = sceneId }); |
| 1 | 99 | | } |
| | 100 | |
|
| | 101 | | public void SendCameraTargetPosition(Vector3 targetPosition, string promiseId) |
| | 102 | | { |
| 0 | 103 | | onReportCameraTarget.cameraTarget = targetPosition; |
| 0 | 104 | | onReportCameraTarget.id = promiseId; |
| 0 | 105 | | if (LOG_MESSAGES) |
| 0 | 106 | | Debug.Log($"SEND: ReportBuilderCameraTarget {targetPosition}"); |
| 0 | 107 | | WebInterface.SendMessage("ReportBuilderCameraTarget", onReportCameraTarget); |
| 0 | 108 | | } |
| | 109 | |
|
| | 110 | | public void SendEntitySelected(EditableEntity entity, string gizmoType, string sceneId) |
| | 111 | | { |
| 0 | 112 | | onGizmoEventPayload.type = "gizmoSelected"; |
| 0 | 113 | | onGizmoEventPayload.entities = entity ? new string[] { entity.rootEntity.entityId } : null; |
| 0 | 114 | | onGizmoEventPayload.gizmoType = gizmoType != null ? gizmoType : DCLGizmos.Gizmo.NONE; |
| 0 | 115 | | onGizmoEventPayload.transforms = null; |
| | 116 | |
|
| 0 | 117 | | if (LOG_MESSAGES) |
| 0 | 118 | | Debug.Log($"SEND: NotifyGizmosSelectedEvent {JsonUtility.ToJson(onGizmoEventPayload)}"); |
| 0 | 119 | | WebInterface.SendSceneEvent(sceneId, "gizmoEvent", onGizmoEventPayload); |
| 0 | 120 | | } |
| | 121 | |
|
| | 122 | | public void SendEntitiesTransform(List<EditableEntity> entities, string gizmoType, string sceneId) |
| | 123 | | { |
| 0 | 124 | | onGizmoEventPayload.type = "gizmoDragEnded"; |
| 0 | 125 | | onGizmoEventPayload.entities = null; |
| 0 | 126 | | onGizmoEventPayload.gizmoType = gizmoType != null ? gizmoType : DCLGizmos.Gizmo.NONE; |
| 0 | 127 | | onGizmoEventPayload.transforms = new GizmosEventPayload.TransformPayload[entities.Count]; |
| | 128 | |
|
| 0 | 129 | | for (int i = 0; i < entities.Count; i++) |
| | 130 | | { |
| 0 | 131 | | onGizmoEventPayload.transforms[i] = new GizmosEventPayload.TransformPayload() |
| | 132 | | { |
| | 133 | | entityId = entities[i].rootEntity.entityId, |
| | 134 | | position = entities[i].transform.position, |
| | 135 | | rotation = entities[i].transform.rotation, |
| | 136 | | scale = entities[i].transform.lossyScale |
| | 137 | | }; |
| | 138 | | } |
| | 139 | |
|
| 0 | 140 | | if (LOG_MESSAGES) |
| 0 | 141 | | Debug.Log($"SEND: NotifyGizmosTransformEvent {JsonUtility.ToJson(onGizmoEventPayload)}"); |
| 0 | 142 | | WebInterface.SendSceneEvent(sceneId, "gizmoEvent", onGizmoEventPayload); |
| 0 | 143 | | } |
| | 144 | | } |
| | 145 | | } |