| | 1 | | using System; |
| | 2 | | using System.Runtime.InteropServices; |
| | 3 | | using DCL; |
| | 4 | | using DCL.Interface; |
| | 5 | | using DCL.Models; |
| | 6 | | using UnityEngine; |
| | 7 | | using Ray = DCL.Models.Ray; |
| | 8 | |
|
| | 9 | | public class EntryPoint_World |
| | 10 | | { |
| | 11 | | private static string currentEntityId; |
| | 12 | | private static string currentSceneId; |
| | 13 | | private static string currentTag; |
| | 14 | |
|
| | 15 | | private static IMessageQueueHandler queueHandler; |
| | 16 | |
|
| | 17 | | delegate void JS_Delegate_VIS(int a, string b); |
| | 18 | |
|
| | 19 | | delegate void JS_Delegate_VSS(string a, string b); |
| | 20 | |
|
| | 21 | | delegate void JS_Delegate_VSSS(string a, string b, string c); |
| | 22 | |
|
| | 23 | | delegate void JS_Delegate_VS(string a); |
| | 24 | |
|
| | 25 | | delegate void JS_Delegate_Query(Protocol.QueryPayload a); |
| | 26 | |
|
| | 27 | | delegate void JS_Delegate_V(); |
| | 28 | |
|
| 5 | 29 | | public EntryPoint_World(IMessageQueueHandler queueHandler) |
| | 30 | | { |
| 5 | 31 | | EntryPoint_World.queueHandler = queueHandler; |
| | 32 | | #if UNITY_WEBGL && !UNITY_EDITOR |
| | 33 | | SetCallback_CreateEntity(CreateEntity); |
| | 34 | | SetCallback_RemoveEntity(RemoveEntity); |
| | 35 | | SetCallback_SceneReady(SceneReady); |
| | 36 | |
|
| | 37 | | SetCallback_SetEntityId(SetEntityId); |
| | 38 | | SetCallback_SetSceneId(SetSceneId); |
| | 39 | | SetCallback_SetTag(SetTag); |
| | 40 | |
|
| | 41 | | SetCallback_SetEntityParent(SetEntityParent); |
| | 42 | |
|
| | 43 | | SetCallback_EntityComponentCreateOrUpdate(EntityComponentCreateOrUpdate); |
| | 44 | | SetCallback_EntityComponentDestroy(EntityComponentDestroy); |
| | 45 | |
|
| | 46 | | SetCallback_SharedComponentCreate(SharedComponentCreate); |
| | 47 | | SetCallback_SharedComponentAttach(SharedComponentAttach); |
| | 48 | | SetCallback_SharedComponentUpdate(SharedComponentUpdate); |
| | 49 | | SetCallback_SharedComponentDispose(SharedComponentDispose); |
| | 50 | |
|
| | 51 | | SetCallback_OpenExternalUrl(OpenExternalUrl); |
| | 52 | | SetCallback_OpenNftDialog(OpenNftDialog); |
| | 53 | |
|
| | 54 | | SetCallback_Query(Query); |
| | 55 | | #endif |
| 5 | 56 | | } |
| | 57 | |
|
| | 58 | | [MonoPInvokeCallback(typeof(JS_Delegate_VSSS))] |
| | 59 | | internal static void OpenNftDialog(string contactAddress, string comment, string tokenId) |
| | 60 | | { |
| 0 | 61 | | QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance(); |
| | 62 | |
|
| 0 | 63 | | Protocol.OpenNftDialog payload = new Protocol.OpenNftDialog |
| | 64 | | { |
| | 65 | | contactAddress = contactAddress, |
| | 66 | | comment = comment, |
| | 67 | | tokenId = tokenId |
| | 68 | | }; |
| | 69 | |
|
| 0 | 70 | | queuedMessage.payload = payload; |
| 0 | 71 | | queuedMessage.method = MessagingTypes.OPEN_NFT_DIALOG; |
| | 72 | |
|
| 0 | 73 | | queueHandler.EnqueueSceneMessage(queuedMessage); |
| 0 | 74 | | } |
| | 75 | |
|
| | 76 | | [MonoPInvokeCallback(typeof(JS_Delegate_VS))] |
| | 77 | | internal static void OpenExternalUrl(string url) |
| | 78 | | { |
| 0 | 79 | | QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance(); |
| | 80 | |
|
| 0 | 81 | | Protocol.OpenExternalUrl payload = new Protocol.OpenExternalUrl |
| | 82 | | { |
| | 83 | | url = url |
| | 84 | | }; |
| | 85 | |
|
| 0 | 86 | | queuedMessage.payload = payload; |
| 0 | 87 | | queuedMessage.method = MessagingTypes.OPEN_EXTERNAL_URL; |
| | 88 | |
|
| 0 | 89 | | queueHandler.EnqueueSceneMessage(queuedMessage); |
| 0 | 90 | | } |
| | 91 | |
|
| | 92 | | [MonoPInvokeCallback(typeof(JS_Delegate_VS))] |
| | 93 | | internal static void EntityComponentDestroy(string name) |
| | 94 | | { |
| 1 | 95 | | QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance(); |
| | 96 | |
|
| 1 | 97 | | Protocol.EntityComponentDestroy payload = new Protocol.EntityComponentDestroy |
| | 98 | | { |
| | 99 | | entityId = currentEntityId, |
| | 100 | | name = name |
| | 101 | | }; |
| | 102 | |
|
| 1 | 103 | | queuedMessage.payload = payload; |
| 1 | 104 | | queuedMessage.method = MessagingTypes.ENTITY_COMPONENT_DESTROY; |
| | 105 | |
|
| 1 | 106 | | queueHandler.EnqueueSceneMessage(queuedMessage); |
| 1 | 107 | | } |
| | 108 | |
|
| | 109 | | [MonoPInvokeCallback(typeof(JS_Delegate_VSS))] |
| | 110 | | internal static void SharedComponentAttach(string id, string name) |
| | 111 | | { |
| 1 | 112 | | QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance(); |
| | 113 | |
|
| 1 | 114 | | Protocol.SharedComponentAttach payload = new Protocol.SharedComponentAttach |
| | 115 | | { |
| | 116 | | entityId = currentEntityId, |
| | 117 | | id = id, |
| | 118 | | name = name |
| | 119 | | }; |
| | 120 | |
|
| 1 | 121 | | queuedMessage.payload = payload; |
| 1 | 122 | | queuedMessage.method = MessagingTypes.SHARED_COMPONENT_ATTACH; |
| | 123 | |
|
| 1 | 124 | | queueHandler.EnqueueSceneMessage(queuedMessage); |
| 1 | 125 | | } |
| | 126 | |
|
| | 127 | | [MonoPInvokeCallback(typeof(JS_Delegate_Query))] |
| | 128 | | internal static void Query(Protocol.QueryPayload payload) |
| | 129 | | { |
| 1 | 130 | | QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance(); |
| | 131 | |
|
| 1 | 132 | | string queryId = Convert.ToString(payload.raycastPayload.id); |
| | 133 | |
|
| 1 | 134 | | RaycastType raycastType = (RaycastType) payload.raycastPayload.raycastType; |
| | 135 | |
|
| 1 | 136 | | Ray ray = new Ray() |
| | 137 | | { |
| | 138 | | origin = payload.raycastPayload.origin, |
| | 139 | | direction = payload.raycastPayload.direction, |
| | 140 | | distance = payload.raycastPayload.distance |
| | 141 | | }; |
| | 142 | |
|
| 1 | 143 | | queuedMessage.method = MessagingTypes.QUERY; |
| 1 | 144 | | queuedMessage.payload = new QueryMessage() |
| | 145 | | { |
| | 146 | | payload = new RaycastQuery() |
| | 147 | | { |
| | 148 | | id = queryId, |
| | 149 | | raycastType = raycastType, |
| | 150 | | ray = ray, |
| | 151 | | sceneId = currentSceneId |
| | 152 | | } |
| | 153 | | }; |
| | 154 | |
|
| 1 | 155 | | queueHandler.EnqueueSceneMessage(queuedMessage); |
| 1 | 156 | | } |
| | 157 | |
|
| | 158 | | [MonoPInvokeCallback(typeof(JS_Delegate_VSS))] |
| | 159 | | internal static void SharedComponentUpdate(string id, string json) |
| | 160 | | { |
| 1 | 161 | | QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance(); |
| | 162 | |
|
| 1 | 163 | | Protocol.SharedComponentUpdate payload = |
| | 164 | | new Protocol.SharedComponentUpdate |
| | 165 | | { |
| | 166 | | componentId = id, |
| | 167 | | json = json |
| | 168 | | }; |
| | 169 | |
|
| 1 | 170 | | queuedMessage.payload = payload; |
| 1 | 171 | | queuedMessage.method = MessagingTypes.SHARED_COMPONENT_UPDATE; |
| | 172 | |
|
| 1 | 173 | | queueHandler.EnqueueSceneMessage(queuedMessage); |
| 1 | 174 | | } |
| | 175 | |
|
| | 176 | | [MonoPInvokeCallback(typeof(JS_Delegate_VS))] |
| | 177 | | internal static void SharedComponentDispose(string id) |
| | 178 | | { |
| 1 | 179 | | QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance(); |
| | 180 | |
|
| 1 | 181 | | Protocol.SharedComponentDispose payload = |
| | 182 | | new Protocol.SharedComponentDispose |
| | 183 | | { |
| | 184 | | id = id |
| | 185 | | }; |
| | 186 | |
|
| 1 | 187 | | queuedMessage.payload = payload; |
| 1 | 188 | | queuedMessage.method = MessagingTypes.SHARED_COMPONENT_DISPOSE; |
| | 189 | |
|
| 1 | 190 | | queueHandler.EnqueueSceneMessage(queuedMessage); |
| 1 | 191 | | } |
| | 192 | |
|
| | 193 | | [MonoPInvokeCallback(typeof(JS_Delegate_VIS))] |
| | 194 | | internal static void SharedComponentCreate(int classId, string id) |
| | 195 | | { |
| 1 | 196 | | QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance(); |
| | 197 | |
|
| 1 | 198 | | Protocol.SharedComponentCreate payload = |
| | 199 | | new Protocol.SharedComponentCreate |
| | 200 | | { |
| | 201 | | id = id, |
| | 202 | | classId = classId |
| | 203 | | }; |
| | 204 | |
|
| 1 | 205 | | queuedMessage.payload = payload; |
| 1 | 206 | | queuedMessage.method = MessagingTypes.SHARED_COMPONENT_CREATE; |
| | 207 | |
|
| 1 | 208 | | queueHandler.EnqueueSceneMessage(queuedMessage); |
| 1 | 209 | | } |
| | 210 | |
|
| | 211 | | [MonoPInvokeCallback(typeof(JS_Delegate_VIS))] |
| | 212 | | internal static void EntityComponentCreateOrUpdate(int classId, string json) |
| | 213 | | { |
| 1 | 214 | | QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance(); |
| | 215 | |
|
| 1 | 216 | | Protocol.EntityComponentCreateOrUpdate payload = |
| | 217 | | new Protocol.EntityComponentCreateOrUpdate |
| | 218 | | { |
| | 219 | | entityId = currentEntityId, |
| | 220 | | classId = classId, |
| | 221 | | json = json |
| | 222 | | }; |
| | 223 | |
|
| 1 | 224 | | queuedMessage.payload = payload; |
| 1 | 225 | | queuedMessage.method = MessagingTypes.ENTITY_COMPONENT_CREATE_OR_UPDATE; |
| | 226 | |
|
| 1 | 227 | | queueHandler.EnqueueSceneMessage(queuedMessage); |
| 1 | 228 | | } |
| | 229 | |
|
| | 230 | | [MonoPInvokeCallback(typeof(JS_Delegate_VS))] |
| | 231 | | internal static void SetEntityParent(string parentId) |
| | 232 | | { |
| 1 | 233 | | QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance(); |
| | 234 | |
|
| 1 | 235 | | Protocol.SetEntityParent payload = |
| | 236 | | new Protocol.SetEntityParent |
| | 237 | | { |
| | 238 | | entityId = currentEntityId, |
| | 239 | | parentId = parentId |
| | 240 | | }; |
| | 241 | |
|
| 1 | 242 | | queuedMessage.payload = payload; |
| 1 | 243 | | queuedMessage.method = MessagingTypes.ENTITY_REPARENT; |
| | 244 | |
|
| 1 | 245 | | queueHandler.EnqueueSceneMessage(queuedMessage); |
| 1 | 246 | | } |
| | 247 | |
|
| | 248 | | [MonoPInvokeCallback(typeof(JS_Delegate_VS))] |
| 0 | 249 | | internal static void SetEntityId(string id) { currentEntityId = id; } |
| | 250 | |
|
| | 251 | | [MonoPInvokeCallback(typeof(JS_Delegate_VS))] |
| 10 | 252 | | internal static void SetSceneId(string id) { currentSceneId = id; } |
| | 253 | |
|
| | 254 | | [MonoPInvokeCallback(typeof(JS_Delegate_VS))] |
| 10 | 255 | | internal static void SetTag(string id) { currentTag = id; } |
| | 256 | |
|
| | 257 | | [MonoPInvokeCallback(typeof(JS_Delegate_V))] |
| | 258 | | internal static void CreateEntity() |
| | 259 | | { |
| 4 | 260 | | QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance(); |
| | 261 | |
|
| 4 | 262 | | Protocol.CreateEntity payload = |
| | 263 | | new Protocol.CreateEntity |
| | 264 | | { |
| | 265 | | entityId = currentEntityId |
| | 266 | | }; |
| | 267 | |
|
| 4 | 268 | | queuedMessage.payload = payload; |
| 4 | 269 | | queuedMessage.method = MessagingTypes.ENTITY_CREATE; |
| | 270 | |
|
| 4 | 271 | | queueHandler.EnqueueSceneMessage(queuedMessage); |
| 4 | 272 | | } |
| | 273 | |
|
| | 274 | | [MonoPInvokeCallback(typeof(JS_Delegate_V))] |
| | 275 | | internal static void RemoveEntity() |
| | 276 | | { |
| 2 | 277 | | QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance(); |
| 2 | 278 | | Protocol.RemoveEntity payload = |
| | 279 | | new Protocol.RemoveEntity() |
| | 280 | | { |
| | 281 | | entityId = currentEntityId |
| | 282 | | }; |
| | 283 | |
|
| 2 | 284 | | queuedMessage.payload = payload; |
| 2 | 285 | | queuedMessage.method = MessagingTypes.ENTITY_DESTROY; |
| | 286 | |
|
| 2 | 287 | | queueHandler.EnqueueSceneMessage(queuedMessage); |
| 2 | 288 | | } |
| | 289 | |
|
| | 290 | | [MonoPInvokeCallback(typeof(JS_Delegate_V))] |
| | 291 | | internal static void SceneReady() |
| | 292 | | { |
| 1 | 293 | | QueuedSceneMessage_Scene queuedMessage = GetSceneMessageInstance(); |
| 1 | 294 | | queuedMessage.method = MessagingTypes.INIT_DONE; |
| 1 | 295 | | queuedMessage.payload = new Protocol.SceneReady(); |
| | 296 | |
|
| 1 | 297 | | queueHandler.EnqueueSceneMessage(queuedMessage); |
| 1 | 298 | | } |
| | 299 | |
|
| | 300 | | internal static QueuedSceneMessage_Scene GetSceneMessageInstance() |
| | 301 | | { |
| | 302 | | QueuedSceneMessage_Scene message; |
| | 303 | |
|
| 15 | 304 | | var sceneMessagesPool = queueHandler.sceneMessagesPool; |
| | 305 | |
|
| 15 | 306 | | if (sceneMessagesPool.Count > 0) |
| 0 | 307 | | message = sceneMessagesPool.Dequeue(); |
| | 308 | | else |
| 15 | 309 | | message = new QueuedSceneMessage_Scene(); |
| | 310 | |
|
| 15 | 311 | | message.sceneId = currentSceneId; |
| 15 | 312 | | message.tag = currentTag; |
| 15 | 313 | | message.type = QueuedSceneMessage.Type.SCENE_MESSAGE; |
| | 314 | |
|
| 15 | 315 | | return message; |
| | 316 | | } |
| | 317 | |
|
| | 318 | | [DllImport("__Internal")] |
| | 319 | | private static extern void SetCallback_CreateEntity(JS_Delegate_V callback); |
| | 320 | |
|
| | 321 | | [DllImport("__Internal")] |
| | 322 | | private static extern void SetCallback_RemoveEntity(JS_Delegate_V callback); |
| | 323 | |
|
| | 324 | | [DllImport("__Internal")] |
| | 325 | | private static extern void SetCallback_SceneReady(JS_Delegate_V callback); |
| | 326 | |
|
| | 327 | | [DllImport("__Internal")] |
| | 328 | | private static extern void SetCallback_SetEntityId(JS_Delegate_VS callback); |
| | 329 | |
|
| | 330 | | [DllImport("__Internal")] |
| | 331 | | private static extern void SetCallback_SetSceneId(JS_Delegate_VS callback); |
| | 332 | |
|
| | 333 | | [DllImport("__Internal")] |
| | 334 | | private static extern void SetCallback_SetEntityParent(JS_Delegate_VS callback); |
| | 335 | |
|
| | 336 | | [DllImport("__Internal")] |
| | 337 | | private static extern void SetCallback_EntityComponentCreateOrUpdate(JS_Delegate_VIS callback); |
| | 338 | |
|
| | 339 | | [DllImport("__Internal")] |
| | 340 | | private static extern void SetCallback_SharedComponentAttach(JS_Delegate_VSS callback); |
| | 341 | |
|
| | 342 | | [DllImport("__Internal")] |
| | 343 | | private static extern void SetCallback_EntityComponentDestroy(JS_Delegate_VS callback); |
| | 344 | |
|
| | 345 | | [DllImport("__Internal")] |
| | 346 | | private static extern void SetCallback_OpenExternalUrl(JS_Delegate_VS callback); |
| | 347 | |
|
| | 348 | | [DllImport("__Internal")] |
| | 349 | | private static extern void SetCallback_OpenNftDialog(JS_Delegate_VSSS callback); |
| | 350 | |
|
| | 351 | | [DllImport("__Internal")] |
| | 352 | | private static extern void SetCallback_SharedComponentUpdate(JS_Delegate_VSS callback); |
| | 353 | |
|
| | 354 | | [DllImport("__Internal")] |
| | 355 | | private static extern void SetCallback_SharedComponentDispose(JS_Delegate_VS callback); |
| | 356 | |
|
| | 357 | | [DllImport("__Internal")] |
| | 358 | | private static extern void SetCallback_SharedComponentCreate(JS_Delegate_VIS callback); |
| | 359 | |
|
| | 360 | | [DllImport("__Internal")] |
| | 361 | | private static extern void SetCallback_SetTag(JS_Delegate_VS callback); |
| | 362 | |
|
| | 363 | | [DllImport("__Internal")] |
| | 364 | | private static extern void SetCallback_Query(JS_Delegate_Query callback); |
| | 365 | | } |