< Summary

Class:DCL.Interface.WebInterfaceUUIDEvent[TPayload]
Assembly:WebInterface
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WebInterface/Interface.cs
Covered lines:1
Uncovered lines:0
Coverable lines:1
Total lines:1407
Line coverage:100% (1 of 1)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
UUIDEvent()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WebInterface/Interface.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using DCL.Helpers;
 4using DCL.Models;
 5using UnityEngine;
 6using Ray = UnityEngine.Ray;
 7
 8#if UNITY_WEBGL && !UNITY_EDITOR
 9using System.Runtime.InteropServices;
 10#endif
 11
 12namespace DCL.Interface
 13{
 14    /**
 15     * This class contains the outgoing interface of Decentraland.
 16     * You must call those functions to interact with the WebInterface.
 17     *
 18     * The messages comming from the WebInterface instead, are reported directly to
 19     * the handler GameObject by name.
 20     */
 21    public static class WebInterface
 22    {
 23        public static bool VERBOSE = false;
 24        public static System.Action<string, string> OnMessageFromEngine;
 25
 26        [System.Serializable]
 27        private class ReportPositionPayload
 28        {
 29            /** Camera position, world space */
 30            public Vector3 position;
 31
 32            /** Camera rotation */
 33            public Quaternion rotation;
 34
 35            /** Camera height, relative to the feet of the avatar or ground */
 36            public float playerHeight;
 37
 38            public Vector3 mousePosition;
 39
 40            public string id;
 41        }
 42
 43        [System.Serializable]
 44        public abstract class ControlEvent
 45        {
 46            public string eventType;
 47        }
 48
 49        public abstract class ControlEvent<T> : ControlEvent
 50        {
 51            public T payload;
 52
 53            protected ControlEvent(string eventType, T payload)
 54            {
 55                this.eventType = eventType;
 56                this.payload = payload;
 57            }
 58        }
 59
 60        [System.Serializable]
 61        public class StartStatefulMode : ControlEvent<StartStatefulMode.Payload>
 62        {
 63            [System.Serializable]
 64            public class Payload
 65            {
 66                public string sceneId;
 67            }
 68
 69            public StartStatefulMode(string sceneId) : base("StartStatefulMode", new Payload() { sceneId = sceneId }) { 
 70        }
 71
 72        [System.Serializable]
 73        public class StopStatefulMode : ControlEvent<StopStatefulMode.Payload>
 74        {
 75            [System.Serializable]
 76            public class Payload
 77            {
 78                public string sceneId;
 79            }
 80
 81            public StopStatefulMode(string sceneId) : base("StopStatefulMode", new Payload() { sceneId = sceneId }) { }
 82        }
 83
 84        [System.Serializable]
 85        public class SceneReady : ControlEvent<SceneReady.Payload>
 86        {
 87            [System.Serializable]
 88            public class Payload
 89            {
 90                public string sceneId;
 91            }
 92
 93            public SceneReady(string sceneId) : base("SceneReady", new Payload() { sceneId = sceneId }) { }
 94        }
 95
 96        [System.Serializable]
 97        public class ActivateRenderingACK : ControlEvent<object>
 98        {
 99            public ActivateRenderingACK() : base("ActivateRenderingACK", null) { }
 100        }
 101
 102        [System.Serializable]
 103        public class DeactivateRenderingACK : ControlEvent<object>
 104        {
 105            public DeactivateRenderingACK() : base("DeactivateRenderingACK", null) { }
 106        }
 107
 108        [System.Serializable]
 109        public class SceneEvent<T>
 110        {
 111            public string sceneId;
 112            public string eventType;
 113            public T payload;
 114        }
 115
 116        [System.Serializable]
 117        public class AllScenesEvent<T>
 118        {
 119            public string eventType;
 120            public T payload;
 121        }
 122
 123        [System.Serializable]
 124        public class UUIDEvent<TPayload>
 125            where TPayload : class, new()
 126        {
 127            public string uuid;
 61128            public TPayload payload = new TPayload();
 129        }
 130
 131        public enum ACTION_BUTTON
 132        {
 133            POINTER,
 134            PRIMARY,
 135            SECONDARY,
 136            ANY,
 137            FORWARD,
 138            BACKWARD,
 139            RIGHT,
 140            LEFT,
 141            JUMP,
 142            WALK,
 143            ACTION_3,
 144            ACTION_4,
 145            ACTION_5,
 146            ACTION_6
 147        }
 148
 149        [System.Serializable]
 150        public class OnClickEvent : UUIDEvent<OnClickEventPayload>
 151        {
 152        };
 153
 154        [System.Serializable]
 155        public class CameraModePayload
 156        {
 157            public CameraMode.ModeId cameraMode;
 158        };
 159
 160        [System.Serializable]
 161        public class IdleStateChangedPayload
 162        {
 163            public bool isIdle;
 164        };
 165
 166        [System.Serializable]
 167        public class OnPointerDownEvent : UUIDEvent<OnPointerEventPayload>
 168        {
 169        };
 170
 171        [System.Serializable]
 172        public class OnGlobalPointerEvent
 173        {
 174            public OnGlobalPointerEventPayload payload = new OnGlobalPointerEventPayload();
 175        };
 176
 177        [System.Serializable]
 178        public class OnPointerUpEvent : UUIDEvent<OnPointerEventPayload>
 179        {
 180        };
 181
 182        [System.Serializable]
 183        private class OnTextSubmitEvent : UUIDEvent<OnTextSubmitEventPayload>
 184        {
 185        };
 186
 187        [System.Serializable]
 188        private class OnTextInputChangeEvent : UUIDEvent<OnTextInputChangeEventPayload>
 189        {
 190        };
 191
 192        [System.Serializable]
 193        private class OnTextInputChangeTextEvent : UUIDEvent<OnTextInputChangeTextEventPayload> { };
 194
 195        [System.Serializable]
 196        private class OnScrollChangeEvent : UUIDEvent<OnScrollChangeEventPayload>
 197        {
 198        };
 199
 200        [System.Serializable]
 201        private class OnFocusEvent : UUIDEvent<EmptyPayload>
 202        {
 203        };
 204
 205        [System.Serializable]
 206        private class OnBlurEvent : UUIDEvent<EmptyPayload>
 207        {
 208        };
 209
 210        [System.Serializable]
 211        public class OnEnterEvent : UUIDEvent<OnEnterEventPayload>
 212        {
 213        };
 214
 215        [System.Serializable]
 216        public class OnClickEventPayload
 217        {
 218            public ACTION_BUTTON buttonId = ACTION_BUTTON.POINTER;
 219        }
 220
 221        [System.Serializable]
 222        public class SendChatMessageEvent
 223        {
 224            public ChatMessage message;
 225        }
 226
 227        [System.Serializable]
 228        public class RemoveEntityComponentsPayLoad
 229        {
 230            public string entityId;
 231            public string componentId;
 232        };
 233
 234        [System.Serializable]
 235        public class StoreSceneStateEvent
 236        {
 237            public string type = "StoreSceneState";
 238            public string payload = "";
 239        };
 240
 241        [System.Serializable]
 242        public class OnPointerEventPayload
 243        {
 244            [System.Serializable]
 245            public class Hit
 246            {
 247                public Vector3 origin;
 248                public float length;
 249                public Vector3 hitPoint;
 250                public Vector3 normal;
 251                public Vector3 worldNormal;
 252                public string meshName;
 253                public string entityId;
 254            }
 255
 256            public ACTION_BUTTON buttonId;
 257            public Vector3 origin;
 258            public Vector3 direction;
 259            public Hit hit;
 260        }
 261
 262        [System.Serializable]
 263        public class OnGlobalPointerEventPayload : OnPointerEventPayload
 264        {
 265            public enum InputEventType
 266            {
 267                DOWN,
 268                UP
 269            }
 270
 271            public InputEventType type;
 272        }
 273
 274        [System.Serializable]
 275        public class OnTextSubmitEventPayload
 276        {
 277            public string id;
 278            public string text;
 279        }
 280
 281        [System.Serializable]
 282        public class OnTextInputChangeEventPayload
 283        {
 284            public string value;
 285        }
 286
 287        [System.Serializable]
 288        public class OnTextInputChangeTextEventPayload
 289        {
 290            [System.Serializable]
 291            public class Payload
 292            {
 293                public string value;
 294                public bool isSubmit;
 295            }
 296            public Payload value = new Payload();
 297        }
 298
 299        [System.Serializable]
 300        public class OnScrollChangeEventPayload
 301        {
 302            public Vector2 value;
 303            public int pointerId;
 304        }
 305
 306        [System.Serializable]
 307        public class EmptyPayload
 308        {
 309        }
 310
 311        [System.Serializable]
 312        public class MetricsModel
 313        {
 314            public int meshes;
 315            public int bodies;
 316            public int materials;
 317            public int textures;
 318            public int triangles;
 319            public int entities;
 320
 321            public static MetricsModel operator + (MetricsModel lhs, MetricsModel rhs)
 322            {
 323                return new MetricsModel()
 324                {
 325                    meshes = lhs.meshes + rhs.meshes,
 326                    bodies = lhs.bodies + rhs.bodies,
 327                    materials = lhs.materials + rhs.materials,
 328                    textures = lhs.textures + rhs.textures,
 329                    triangles = lhs.triangles + rhs.triangles,
 330                    entities = lhs.entities + rhs.entities
 331                };
 332            }
 333        }
 334
 335        [System.Serializable]
 336        private class OnMetricsUpdate
 337        {
 338            public MetricsModel given = new MetricsModel();
 339            public MetricsModel limit = new MetricsModel();
 340        }
 341
 342        [System.Serializable]
 343        public class OnEnterEventPayload
 344        {
 345        }
 346
 347        [System.Serializable]
 348        public class TransformPayload
 349        {
 350            public Vector3 position = Vector3.zero;
 351            public Quaternion rotation = Quaternion.identity;
 352            public Vector3 scale = Vector3.one;
 353        }
 354
 355        public class OnSendScreenshot
 356        {
 357            public string id;
 358            public string encodedTexture;
 359        };
 360
 361        [System.Serializable]
 362        public class GotoEvent
 363        {
 364            public int x;
 365            public int y;
 366        };
 367
 368        [System.Serializable]
 369        public class BaseResolution
 370        {
 371            public int baseResolution;
 372        };
 373
 374        //-----------------------------------------------------
 375        // Raycast
 376        [System.Serializable]
 377        public class RayInfo
 378        {
 379            public Vector3 origin;
 380            public Vector3 direction;
 381            public float distance;
 382        }
 383
 384        [System.Serializable]
 385        public class RaycastHitInfo
 386        {
 387            public bool didHit;
 388            public RayInfo ray;
 389
 390            public Vector3 hitPoint;
 391            public Vector3 hitNormal;
 392        }
 393
 394        [System.Serializable]
 395        public class HitEntityInfo
 396        {
 397            public string entityId;
 398            public string meshName;
 399        }
 400
 401        [System.Serializable]
 402        public class RaycastHitEntity : RaycastHitInfo
 403        {
 404            public HitEntityInfo entity;
 405        }
 406
 407        [System.Serializable]
 408        public class RaycastHitEntities : RaycastHitInfo
 409        {
 410            public RaycastHitEntity[] entities;
 411        }
 412
 413        [System.Serializable]
 414        public class RaycastResponse<T> where T : RaycastHitInfo
 415        {
 416            public string queryId;
 417            public string queryType;
 418            public T payload;
 419        }
 420
 421        // Note (Zak): We need to explicitly define this classes for the JsonUtility to
 422        // be able to serialize them
 423        [System.Serializable]
 424        public class RaycastHitFirstResponse : RaycastResponse<RaycastHitEntity>
 425        {
 426        }
 427
 428        [System.Serializable]
 429        public class RaycastHitAllResponse : RaycastResponse<RaycastHitEntities>
 430        {
 431        }
 432
 433        [System.Serializable]
 434        public class SendExpressionPayload
 435        {
 436            public string id;
 437            public long timestamp;
 438        }
 439
 440        [System.Serializable]
 441        public class UserAcceptedCollectiblesPayload
 442        {
 443            public string id;
 444        }
 445
 446        [System.Serializable]
 447        public class SendBlockPlayerPayload
 448        {
 449            public string userId;
 450        }
 451
 452        [System.Serializable]
 453        public class SendUnblockPlayerPayload
 454        {
 455            public string userId;
 456        }
 457
 458        [System.Serializable]
 459        public class TutorialStepPayload
 460        {
 461            public int tutorialStep;
 462        }
 463
 464        [System.Serializable]
 465        public class PerformanceReportPayload
 466        {
 467            public string samples;
 468            public bool fpsIsCapped;
 469            public int hiccupsInThousandFrames;
 470            public float hiccupsTime;
 471            public float totalTime;
 472        }
 473
 474        [System.Serializable]
 475        public class SystemInfoReportPayload
 476        {
 477            public string graphicsDeviceName = SystemInfo.graphicsDeviceName;
 478            public string graphicsDeviceVersion = SystemInfo.graphicsDeviceVersion;
 479            public int graphicsMemorySize = SystemInfo.graphicsMemorySize;
 480            public string processorType = SystemInfo.processorType;
 481            public int processorCount = SystemInfo.processorCount;
 482            public int systemMemorySize = SystemInfo.systemMemorySize;
 483        }
 484
 485        [System.Serializable]
 486        public class GenericAnalyticPayload
 487        {
 488            public string eventName;
 489            public Dictionary<object, object> data;
 490        }
 491
 492        [System.Serializable]
 493        public class PerformanceHiccupPayload
 494        {
 495            public int hiccupsInThousandFrames;
 496            public float hiccupsTime;
 497            public float totalTime;
 498        }
 499
 500        [System.Serializable]
 501        public class TermsOfServiceResponsePayload
 502        {
 503            public string sceneId;
 504            public bool dontShowAgain;
 505            public bool accepted;
 506        }
 507
 508        [System.Serializable]
 509        public class OpenURLPayload
 510        {
 511            public string url;
 512        }
 513
 514        [System.Serializable]
 515        public class GIFSetupPayload
 516        {
 517            public string imageSource;
 518            public string id;
 519            public bool isWebGL1;
 520        }
 521
 522        [System.Serializable]
 523        public class RequestScenesInfoAroundParcelPayload
 524        {
 525            public Vector2 parcel;
 526            public int scenesAround;
 527        }
 528
 529        [System.Serializable]
 530        public class AudioStreamingPayload
 531        {
 532            public string url;
 533            public bool play;
 534            public float volume;
 535        }
 536
 537        [System.Serializable]
 538        public class SetScenesLoadRadiusPayload
 539        {
 540            public float newRadius;
 541        }
 542
 543        [System.Serializable]
 544        public class SetVoiceChatRecordingPayload
 545        {
 546            public bool recording;
 547        }
 548
 549        [System.Serializable]
 550        public class ApplySettingsPayload
 551        {
 552            public float voiceChatVolume;
 553            public int voiceChatAllowCategory;
 554        }
 555
 556        [System.Serializable]
 557        public class JumpInPayload
 558        {
 559            public FriendsController.UserStatus.Realm realm = new FriendsController.UserStatus.Realm();
 560            public Vector2 gridPosition;
 561        }
 562
 563        [System.Serializable]
 564        public class LoadingFeedbackMessage
 565        {
 566            public string message;
 567            public int loadPercentage;
 568        }
 569
 570        [System.Serializable]
 571        public class AnalyticsPayload
 572        {
 573            [System.Serializable]
 574            public class Property
 575            {
 576                public string key;
 577                public string value;
 578
 579                public Property(string key, string value)
 580                {
 581                    this.key = key;
 582                    this.value = value;
 583                }
 584            }
 585
 586            public string name;
 587            public Property[] properties;
 588        }
 589
 590        [System.Serializable]
 591        public class DelightedSurveyEnabledPayload
 592        {
 593            public bool enabled;
 594        }
 595
 596        [System.Serializable]
 597        public class ExternalActionSceneEventPayload
 598        {
 599            public string type;
 600            public string payload;
 601        }
 602
 603        [System.Serializable]
 604        public class MuteUserPayload
 605        {
 606            public string[] usersId;
 607            public bool mute;
 608        }
 609
 610        [System.Serializable]
 611        public class CloseUserAvatarPayload
 612        {
 613            public bool isSignUpFlow;
 614        }
 615
 616        [System.Serializable]
 617        public class StringPayload
 618        {
 619            public string value;
 620        }
 621
 622        [System.Serializable]
 623        public class KillPortableExperiencePayload
 624        {
 625            public string portableExperienceId;
 626        }
 627
 628        [System.Serializable]
 629        public class WearablesRequestFiltersPayload
 630        {
 631            public string ownedByUser;
 632            public string[] wearableIds;
 633            public string[] collectionIds;
 634        }
 635
 636        [System.Serializable]
 637        public class RequestWearablesPayload
 638        {
 639            public WearablesRequestFiltersPayload filters;
 640            public string context;
 641        }
 642
 643        [System.Serializable]
 644        public class HeadersPayload
 645        {
 646            public string method;
 647            public string url;
 648            public Dictionary<string, object> metadata = new Dictionary<string, object>();
 649        }
 650
 651        [System.Serializable]
 652        public class SearchENSOwnerPayload
 653        {
 654            public string name;
 655            public int maxResults;
 656        }
 657
 658        [System.Serializable]
 659        public class UnpublishScenePayload
 660        {
 661            public string coordinates;
 662        }
 663
 664#if UNITY_WEBGL && !UNITY_EDITOR
 665    /**
 666     * This method is called after the first render. It marks the loading of the
 667     * rest of the JS client.
 668     */
 669    [DllImport("__Internal")] public static extern void StartDecentraland();
 670    [DllImport("__Internal")] public static extern void MessageFromEngine(string type, string message);
 671    [DllImport("__Internal")] public static extern string GetGraphicCard();
 672    [DllImport("__Internal")] public static extern bool CheckURLParam(string targetParam);
 673#else
 674        private static bool hasQueuedMessages = false;
 675        private static List<(string, string)> queuedMessages = new List<(string, string)>();
 676        public static void StartDecentraland() { }
 677        public static bool CheckURLParam(string targetParam) { return false; }
 678
 679        public static void MessageFromEngine(string type, string message)
 680        {
 681            if (OnMessageFromEngine != null)
 682            {
 683                if (hasQueuedMessages)
 684                {
 685                    ProcessQueuedMessages();
 686                }
 687
 688                OnMessageFromEngine.Invoke(type, message);
 689                if (VERBOSE)
 690                {
 691                    Debug.Log("MessageFromEngine called with: " + type + ", " + message);
 692                }
 693            }
 694            else
 695            {
 696                lock (queuedMessages)
 697                {
 698                    queuedMessages.Add((type, message));
 699                }
 700
 701                hasQueuedMessages = true;
 702            }
 703        }
 704
 705        private static void ProcessQueuedMessages()
 706        {
 707            hasQueuedMessages = false;
 708            lock (queuedMessages)
 709            {
 710                foreach ((string type, string payload) in queuedMessages)
 711                {
 712                    MessageFromEngine(type, payload);
 713                }
 714
 715                queuedMessages.Clear();
 716            }
 717        }
 718
 719        public static string GetGraphicCard() => "In Editor Graphic Card";
 720#endif
 721
 722        public static void SendMessage(string type)
 723        {
 724            // sending an empty JSON object to be compatible with other messages
 725            MessageFromEngine(type, "{}");
 726        }
 727
 728        public static void SendMessage<T>(string type, T message)
 729        {
 730            string messageJson = JsonUtility.ToJson(message);
 731
 732            if (VERBOSE)
 733            {
 734                Debug.Log($"Sending message: " + messageJson);
 735            }
 736
 737            MessageFromEngine(type, messageJson);
 738        }
 739
 740        private static ReportPositionPayload positionPayload = new ReportPositionPayload();
 741        private static CameraModePayload cameraModePayload = new CameraModePayload();
 742        private static IdleStateChangedPayload idleStateChangedPayload = new IdleStateChangedPayload();
 743        private static OnMetricsUpdate onMetricsUpdate = new OnMetricsUpdate();
 744        private static OnClickEvent onClickEvent = new OnClickEvent();
 745        private static OnPointerDownEvent onPointerDownEvent = new OnPointerDownEvent();
 746        private static OnPointerUpEvent onPointerUpEvent = new OnPointerUpEvent();
 747        private static OnTextSubmitEvent onTextSubmitEvent = new OnTextSubmitEvent();
 748        private static OnTextInputChangeEvent onTextInputChangeEvent = new OnTextInputChangeEvent();
 749        private static OnTextInputChangeTextEvent onTextInputChangeTextEvent = new OnTextInputChangeTextEvent();
 750        private static OnScrollChangeEvent onScrollChangeEvent = new OnScrollChangeEvent();
 751        private static OnFocusEvent onFocusEvent = new OnFocusEvent();
 752        private static OnBlurEvent onBlurEvent = new OnBlurEvent();
 753        private static OnEnterEvent onEnterEvent = new OnEnterEvent();
 754        private static OnSendScreenshot onSendScreenshot = new OnSendScreenshot();
 755        private static OnPointerEventPayload onPointerEventPayload = new OnPointerEventPayload();
 756        private static OnGlobalPointerEventPayload onGlobalPointerEventPayload = new OnGlobalPointerEventPayload();
 757        private static OnGlobalPointerEvent onGlobalPointerEvent = new OnGlobalPointerEvent();
 758        private static AudioStreamingPayload onAudioStreamingEvent = new AudioStreamingPayload();
 759        private static SetVoiceChatRecordingPayload setVoiceChatRecordingPayload = new SetVoiceChatRecordingPayload();
 760        private static SetScenesLoadRadiusPayload setScenesLoadRadiusPayload = new SetScenesLoadRadiusPayload();
 761        private static ApplySettingsPayload applySettingsPayload = new ApplySettingsPayload();
 762        private static GIFSetupPayload gifSetupPayload = new GIFSetupPayload();
 763        private static JumpInPayload jumpInPayload = new JumpInPayload();
 764        private static GotoEvent gotoEvent = new GotoEvent();
 765        private static SendChatMessageEvent sendChatMessageEvent = new SendChatMessageEvent();
 766        private static BaseResolution baseResEvent = new BaseResolution();
 767        private static AnalyticsPayload analyticsEvent = new AnalyticsPayload();
 768        private static DelightedSurveyEnabledPayload delightedSurveyEnabled = new DelightedSurveyEnabledPayload();
 769        private static ExternalActionSceneEventPayload sceneExternalActionEvent = new ExternalActionSceneEventPayload();
 770        private static MuteUserPayload muteUserEvent = new MuteUserPayload();
 771        private static StoreSceneStateEvent storeSceneState = new StoreSceneStateEvent();
 772        private static CloseUserAvatarPayload closeUserAvatarPayload = new CloseUserAvatarPayload();
 773        private static StringPayload stringPayload = new StringPayload();
 774        private static KillPortableExperiencePayload killPortableExperiencePayload = new KillPortableExperiencePayload()
 775        private static RequestWearablesPayload requestWearablesPayload = new RequestWearablesPayload();
 776        private static SearchENSOwnerPayload searchEnsOwnerPayload = new SearchENSOwnerPayload();
 777        private static HeadersPayload headersPayload = new HeadersPayload();
 778
 779        public static void SendSceneEvent<T>(string sceneId, string eventType, T payload)
 780        {
 781            SceneEvent<T> sceneEvent = new SceneEvent<T>();
 782            sceneEvent.sceneId = sceneId;
 783            sceneEvent.eventType = eventType;
 784            sceneEvent.payload = payload;
 785
 786            SendMessage("SceneEvent", sceneEvent);
 787        }
 788
 789        private static void SendAllScenesEvent<T>(string eventType, T payload)
 790        {
 791            AllScenesEvent<T> allScenesEvent = new AllScenesEvent<T>();
 792            allScenesEvent.eventType = eventType;
 793            allScenesEvent.payload = payload;
 794
 795            SendMessage("AllScenesEvent", allScenesEvent);
 796        }
 797
 798        public static void ReportPosition(Vector3 position, Quaternion rotation, float playerHeight)
 799        {
 800            positionPayload.position = position;
 801            positionPayload.rotation = rotation;
 802            positionPayload.playerHeight = playerHeight;
 803
 804            SendMessage("ReportPosition", positionPayload);
 805        }
 806
 807        public static void ReportCameraChanged(CameraMode.ModeId cameraMode)
 808        {
 809            cameraModePayload.cameraMode = cameraMode;
 810            SendAllScenesEvent("cameraModeChanged", cameraModePayload);
 811        }
 812
 813        public static void ReportIdleStateChanged(bool isIdle)
 814        {
 815            idleStateChangedPayload.isIdle = isIdle;
 816            SendAllScenesEvent("idleStateChanged", idleStateChangedPayload);
 817        }
 818
 819        public static void ReportControlEvent<T>(T controlEvent) where T : ControlEvent { SendMessage("ControlEvent", co
 820
 821        public static void SendRequestHeadersForUrl(string eventName, string method, string url, Dictionary<string, obje
 822        {
 823            headersPayload.method = method;
 824            headersPayload.url = url;
 825            if(metadata != null)
 826                headersPayload.metadata = metadata;
 827            SendMessage(eventName, headersPayload );
 828        }
 829
 830        public static void BuilderInWorldMessage(string type, string message) { MessageFromEngine(type, message); }
 831
 832        public static void ReportOnClickEvent(string sceneId, string uuid)
 833        {
 834            if (string.IsNullOrEmpty(uuid))
 835            {
 836                return;
 837            }
 838
 839            onClickEvent.uuid = uuid;
 840
 841            SendSceneEvent(sceneId, "uuidEvent", onClickEvent);
 842        }
 843
 844        private static void ReportRaycastResult<T, P>(string sceneId, string queryId, string queryType, P payload) where
 845        {
 846            T response = new T();
 847            response.queryId = queryId;
 848            response.queryType = queryType;
 849            response.payload = payload;
 850
 851            SendSceneEvent<T>(sceneId, "raycastResponse", response);
 852        }
 853
 854        public static void ReportRaycastHitFirstResult(string sceneId, string queryId, RaycastType raycastType, RaycastH
 855
 856        public static void ReportRaycastHitAllResult(string sceneId, string queryId, RaycastType raycastType, RaycastHit
 857
 858        private static OnPointerEventPayload.Hit CreateHitObject(string entityId, string meshName, Vector3 point, Vector
 859        {
 860            OnPointerEventPayload.Hit hit = new OnPointerEventPayload.Hit();
 861
 862            hit.hitPoint = point;
 863            hit.length = distance;
 864            hit.normal = normal;
 865            hit.worldNormal = normal;
 866            hit.meshName = meshName;
 867            hit.entityId = entityId;
 868
 869            return hit;
 870        }
 871
 872        private static void SetPointerEventPayload(OnPointerEventPayload pointerEventPayload, ACTION_BUTTON buttonId, st
 873        {
 874            pointerEventPayload.origin = ray.origin;
 875            pointerEventPayload.direction = ray.direction;
 876            pointerEventPayload.buttonId = buttonId;
 877
 878            if (isHitInfoValid)
 879                pointerEventPayload.hit = CreateHitObject(entityId, meshName, point, normal, distance);
 880            else
 881                pointerEventPayload.hit = null;
 882        }
 883
 884        public static void ReportGlobalPointerDownEvent(ACTION_BUTTON buttonId, Ray ray, Vector3 point, Vector3 normal, 
 885        {
 886            SetPointerEventPayload((OnPointerEventPayload) onGlobalPointerEventPayload, buttonId, entityId, meshName, ra
 887            onGlobalPointerEventPayload.type = OnGlobalPointerEventPayload.InputEventType.DOWN;
 888
 889            onGlobalPointerEvent.payload = onGlobalPointerEventPayload;
 890
 891            SendSceneEvent(sceneId, "actionButtonEvent", onGlobalPointerEvent);
 892        }
 893
 894        public static void ReportGlobalPointerUpEvent(ACTION_BUTTON buttonId, Ray ray, Vector3 point, Vector3 normal, fl
 895        {
 896            SetPointerEventPayload((OnPointerEventPayload) onGlobalPointerEventPayload, buttonId, entityId, meshName, ra
 897            onGlobalPointerEventPayload.type = OnGlobalPointerEventPayload.InputEventType.UP;
 898
 899            onGlobalPointerEvent.payload = onGlobalPointerEventPayload;
 900
 901            SendSceneEvent(sceneId, "actionButtonEvent", onGlobalPointerEvent);
 902        }
 903
 904        public static void ReportOnPointerDownEvent(ACTION_BUTTON buttonId, string sceneId, string uuid, string entityId
 905        {
 906            if (string.IsNullOrEmpty(uuid))
 907            {
 908                return;
 909            }
 910
 911            onPointerDownEvent.uuid = uuid;
 912            SetPointerEventPayload(onPointerEventPayload, buttonId, entityId, meshName, ray, point, normal, distance, is
 913            onPointerDownEvent.payload = onPointerEventPayload;
 914
 915            SendSceneEvent(sceneId, "uuidEvent", onPointerDownEvent);
 916        }
 917
 918        public static void ReportOnPointerUpEvent(ACTION_BUTTON buttonId, string sceneId, string uuid, string entityId, 
 919        {
 920            if (string.IsNullOrEmpty(uuid))
 921            {
 922                return;
 923            }
 924
 925            onPointerUpEvent.uuid = uuid;
 926            SetPointerEventPayload(onPointerEventPayload, buttonId, entityId, meshName, ray, point, normal, distance, is
 927            onPointerUpEvent.payload = onPointerEventPayload;
 928
 929            SendSceneEvent(sceneId, "uuidEvent", onPointerUpEvent);
 930        }
 931
 932        public static void ReportOnTextSubmitEvent(string sceneId, string uuid, string text)
 933        {
 934            if (string.IsNullOrEmpty(uuid))
 935            {
 936                return;
 937            }
 938
 939            onTextSubmitEvent.uuid = uuid;
 940            onTextSubmitEvent.payload.text = text;
 941
 942            SendSceneEvent(sceneId, "uuidEvent", onTextSubmitEvent);
 943        }
 944
 945        public static void ReportOnTextInputChangedEvent(string sceneId, string uuid, string text)
 946        {
 947            if (string.IsNullOrEmpty(uuid))
 948            {
 949                return;
 950            }
 951
 952            onTextInputChangeEvent.uuid = uuid;
 953            onTextInputChangeEvent.payload.value = text;
 954
 955            SendSceneEvent(sceneId, "uuidEvent", onTextInputChangeEvent);
 956        }
 957
 958        public static void ReportOnTextInputChangedTextEvent(string sceneId, string uuid, string text, bool isSubmit)
 959        {
 960            if (string.IsNullOrEmpty(uuid))
 961            {
 962                return;
 963            }
 964
 965            onTextInputChangeTextEvent.uuid = uuid;
 966            onTextInputChangeTextEvent.payload.value.value = text;
 967            onTextInputChangeTextEvent.payload.value.isSubmit = isSubmit;
 968
 969            SendSceneEvent(sceneId, "uuidEvent", onTextInputChangeTextEvent);
 970        }
 971
 972        public static void ReportOnFocusEvent(string sceneId, string uuid)
 973        {
 974            if (string.IsNullOrEmpty(uuid))
 975            {
 976                return;
 977            }
 978
 979            onFocusEvent.uuid = uuid;
 980            SendSceneEvent(sceneId, "uuidEvent", onFocusEvent);
 981        }
 982
 983        public static void ReportOnBlurEvent(string sceneId, string uuid)
 984        {
 985            if (string.IsNullOrEmpty(uuid))
 986            {
 987                return;
 988            }
 989
 990            onBlurEvent.uuid = uuid;
 991            SendSceneEvent(sceneId, "uuidEvent", onBlurEvent);
 992        }
 993
 994        public static void ReportOnScrollChange(string sceneId, string uuid, Vector2 value, int pointerId)
 995        {
 996            if (string.IsNullOrEmpty(uuid))
 997            {
 998                return;
 999            }
 1000
 1001            onScrollChangeEvent.uuid = uuid;
 1002            onScrollChangeEvent.payload.value = value;
 1003            onScrollChangeEvent.payload.pointerId = pointerId;
 1004
 1005            SendSceneEvent(sceneId, "uuidEvent", onScrollChangeEvent);
 1006        }
 1007
 1008        public static void ReportEvent<T>(string sceneId, T @event) { SendSceneEvent(sceneId, "uuidEvent", @event); }
 1009
 1010        public static void ReportOnMetricsUpdate(string sceneId, MetricsModel current,
 1011            MetricsModel limit)
 1012        {
 1013            onMetricsUpdate.given = current;
 1014            onMetricsUpdate.limit = limit;
 1015
 1016            SendSceneEvent(sceneId, "metricsUpdate", onMetricsUpdate);
 1017        }
 1018
 1019        public static void ReportOnEnterEvent(string sceneId, string uuid)
 1020        {
 1021            if (string.IsNullOrEmpty(uuid))
 1022                return;
 1023
 1024            onEnterEvent.uuid = uuid;
 1025
 1026            SendSceneEvent(sceneId, "uuidEvent", onEnterEvent);
 1027        }
 1028
 1029        public static void LogOut() { SendMessage("LogOut"); }
 1030
 1031        public static void RedirectToSignUp() { SendMessage("RedirectToSignUp"); }
 1032
 1033        public static void PreloadFinished(string sceneId) { SendMessage("PreloadFinished", sceneId); }
 1034
 1035        public static void ReportMousePosition(Vector3 mousePosition, string id)
 1036        {
 1037            positionPayload.mousePosition = mousePosition;
 1038            positionPayload.id = id;
 1039            SendMessage("ReportMousePosition", positionPayload);
 1040        }
 1041
 1042        public static void SendScreenshot(string encodedTexture, string id)
 1043        {
 1044            onSendScreenshot.encodedTexture = encodedTexture;
 1045            onSendScreenshot.id = id;
 1046            SendMessage("SendScreenshot", onSendScreenshot);
 1047        }
 1048
 1049        public static void SetDelightedSurveyEnabled(bool enabled)
 1050        {
 1051            delightedSurveyEnabled.enabled = enabled;
 1052            SendMessage("SetDelightedSurveyEnabled", delightedSurveyEnabled);
 1053        }
 1054
 1055        public static void SetScenesLoadRadius(float newRadius)
 1056        {
 1057            setScenesLoadRadiusPayload.newRadius = newRadius;
 1058            SendMessage("SetScenesLoadRadius", setScenesLoadRadiusPayload);
 1059        }
 1060
 1061        [System.Serializable]
 1062        public class SaveAvatarPayload
 1063        {
 1064            public string face;
 1065            public string face128;
 1066            public string face256;
 1067            public string body;
 1068            public bool isSignUpFlow;
 1069            public AvatarModel avatar;
 1070        }
 1071
 1072        public static class RendererAuthenticationType
 1073        {
 1074            public static string Guest => "guest";
 1075            public static string WalletConnect => "wallet_connect";
 1076        }
 1077
 1078        [System.Serializable]
 1079        public class SendAuthenticationPayload
 1080        {
 1081            public string rendererAuthenticationType;
 1082        }
 1083
 1084        [System.Serializable]
 1085        public class SendPassportPayload
 1086        {
 1087            public string name;
 1088            public string email;
 1089        }
 1090
 1091        [System.Serializable]
 1092        public class SendSaveUserUnverifiedNamePayload
 1093        {
 1094            public string newUnverifiedName;
 1095        }
 1096
 1097        [System.Serializable]
 1098        public class SendSaveUserDescriptionPayload
 1099        {
 1100            public string description;
 1101
 1102            public SendSaveUserDescriptionPayload(string description)
 1103            {
 1104                this.description = description;
 1105            }
 1106        }
 1107
 1108        [Serializable]
 1109        public class SendVideoProgressEvent
 1110        {
 1111            public string componentId;
 1112            public string sceneId;
 1113            public string videoTextureId;
 1114            public int status;
 1115            public float currentOffset;
 1116            public float videoLength;
 1117        }
 1118
 1119        public static void RequestOwnProfileUpdate() { SendMessage("RequestOwnProfileUpdate"); }
 1120
 1121        public static void SendSaveAvatar(AvatarModel avatar, Texture2D faceSnapshot, Texture2D face128Snapshot, Texture
 1122        {
 1123            var payload = new SaveAvatarPayload()
 1124            {
 1125                avatar = avatar,
 1126                face = System.Convert.ToBase64String(faceSnapshot.EncodeToPNG()),
 1127                face128 = System.Convert.ToBase64String(face128Snapshot.EncodeToPNG()),
 1128                face256 = System.Convert.ToBase64String(face256Snapshot.EncodeToPNG()),
 1129                body = System.Convert.ToBase64String(bodySnapshot.EncodeToPNG()),
 1130                isSignUpFlow = isSignUpFlow
 1131            };
 1132            SendMessage("SaveUserAvatar", payload);
 1133        }
 1134
 1135        public static void SendAuthentication(string rendererAuthenticationType) { SendMessage("SendAuthentication", new
 1136
 1137        public static void SendPassport(string name, string email) { SendMessage("SendPassport", new SendPassportPayload
 1138
 1139        public static void SendSaveUserUnverifiedName(string newName)
 1140        {
 1141            var payload = new SendSaveUserUnverifiedNamePayload()
 1142            {
 1143                newUnverifiedName = newName
 1144            };
 1145
 1146            SendMessage("SaveUserUnverifiedName", payload);
 1147        }
 1148
 1149        public static void SendSaveUserDescription(string about)
 1150        {
 1151            SendMessage("SaveUserDescription", new SendSaveUserDescriptionPayload(about));
 1152        }
 1153
 1154        public static void SendUserAcceptedCollectibles(string airdropId) { SendMessage("UserAcceptedCollectibles", new 
 1155
 1156        public static void SaveUserTutorialStep(int newTutorialStep) { SendMessage("SaveUserTutorialStep", new TutorialS
 1157
 1158        public static void SendPerformanceReport(string encodedFrameTimesInMS, bool usingFPSCap, int hiccupsInThousandFr
 1159        {
 1160            SendMessage("PerformanceReport", new PerformanceReportPayload()
 1161            {
 1162                samples = encodedFrameTimesInMS,
 1163                fpsIsCapped = usingFPSCap,
 1164                hiccupsInThousandFrames = hiccupsInThousandFrames,
 1165                hiccupsTime = hiccupsTime,
 1166                totalTime = totalTime
 1167            });
 1168        }
 1169
 1170        public static void SendSystemInfoReport() { SendMessage("SystemInfoReport", new SystemInfoReportPayload()); }
 1171
 1172        public static void SendTermsOfServiceResponse(string sceneId, bool accepted, bool dontShowAgain)
 1173        {
 1174            var payload = new TermsOfServiceResponsePayload()
 1175            {
 1176                sceneId = sceneId,
 1177                accepted = accepted,
 1178                dontShowAgain = dontShowAgain
 1179            };
 1180            SendMessage("TermsOfServiceResponse", payload);
 1181        }
 1182
 1183        public static void SendExpression(string expressionID, long timestamp)
 1184        {
 1185            SendMessage("TriggerExpression", new SendExpressionPayload()
 1186            {
 1187                id = expressionID,
 1188                timestamp = timestamp
 1189            });
 1190        }
 1191
 1192        public static void ReportMotdClicked() { SendMessage("MotdConfirmClicked"); }
 1193
 1194        public static void OpenURL(string url) { SendMessage("OpenWebURL", new OpenURLPayload { url = url }); }
 1195
 1196        public static void SendReportScene(string sceneID) { SendMessage("ReportScene", sceneID); }
 1197
 1198        public static void SendReportPlayer(string playerName) { SendMessage("ReportPlayer", playerName); }
 1199
 1200        public static void SendBlockPlayer(string userId)
 1201        {
 1202            SendMessage("BlockPlayer", new SendBlockPlayerPayload()
 1203            {
 1204                userId = userId
 1205            });
 1206        }
 1207
 1208        public static void SendUnblockPlayer(string userId)
 1209        {
 1210            SendMessage("UnblockPlayer", new SendUnblockPlayerPayload()
 1211            {
 1212                userId = userId
 1213            });
 1214        }
 1215
 1216        public static void RequestScenesInfoAroundParcel(Vector2 parcel, int maxScenesArea)
 1217        {
 1218            SendMessage("RequestScenesInfoInArea", new RequestScenesInfoAroundParcelPayload()
 1219            {
 1220                parcel = parcel,
 1221                scenesAround = maxScenesArea
 1222            });
 1223        }
 1224
 1225        public static void SendAudioStreamEvent(string url, bool play, float volume)
 1226        {
 1227            onAudioStreamingEvent.url = url;
 1228            onAudioStreamingEvent.play = play;
 1229            onAudioStreamingEvent.volume = volume;
 1230            SendMessage("SetAudioStream", onAudioStreamingEvent);
 1231        }
 1232
 1233        public static void SendSetVoiceChatRecording(bool recording)
 1234        {
 1235            setVoiceChatRecordingPayload.recording = recording;
 1236            SendMessage("SetVoiceChatRecording", setVoiceChatRecordingPayload);
 1237        }
 1238
 1239        public static void ToggleVoiceChatRecording() { SendMessage("ToggleVoiceChatRecording"); }
 1240
 1241        public static void ApplySettings(float voiceChatVolume, int voiceChatAllowCategory)
 1242        {
 1243            applySettingsPayload.voiceChatVolume = voiceChatVolume;
 1244            applySettingsPayload.voiceChatAllowCategory = voiceChatAllowCategory;
 1245            SendMessage("ApplySettings", applySettingsPayload);
 1246        }
 1247
 1248        public static void RequestGIFProcessor(string gifURL, string gifId, bool isWebGL1)
 1249        {
 1250            gifSetupPayload.imageSource = gifURL;
 1251            gifSetupPayload.id = gifId;
 1252            gifSetupPayload.isWebGL1 = isWebGL1;
 1253
 1254            SendMessage("RequestGIFProcessor", gifSetupPayload);
 1255        }
 1256
 1257        public static void DeleteGIF(string id)
 1258        {
 1259            stringPayload.value = id;
 1260            SendMessage("DeleteGIF", stringPayload);
 1261        }
 1262
 1263        public static void GoTo(int x, int y)
 1264        {
 1265            gotoEvent.x = x;
 1266            gotoEvent.y = y;
 1267            SendMessage("GoTo", gotoEvent);
 1268        }
 1269
 1270        public static void GoToCrowd() { SendMessage("GoToCrowd"); }
 1271
 1272        public static void GoToMagic() { SendMessage("GoToMagic"); }
 1273
 1274        public static void JumpIn(int x, int y, string serverName, string layerName)
 1275        {
 1276            jumpInPayload.realm.serverName = serverName;
 1277            jumpInPayload.realm.layer = layerName;
 1278
 1279            jumpInPayload.gridPosition.x = x;
 1280            jumpInPayload.gridPosition.y = y;
 1281
 1282            SendMessage("JumpIn", jumpInPayload);
 1283        }
 1284
 1285        public static void SendChatMessage(ChatMessage message)
 1286        {
 1287            sendChatMessageEvent.message = message;
 1288            SendMessage("SendChatMessage", sendChatMessageEvent);
 1289        }
 1290
 1291        public static void UpdateFriendshipStatus(FriendsController.FriendshipUpdateStatusMessage message) { SendMessage
 1292
 1293        public static void ScenesLoadingFeedback(LoadingFeedbackMessage message) { SendMessage("ScenesLoadingFeedback", 
 1294
 1295        public static void FetchHotScenes() { SendMessage("FetchHotScenes"); }
 1296
 1297        public static void SetBaseResolution(int resolution)
 1298        {
 1299            baseResEvent.baseResolution = resolution;
 1300            SendMessage("SetBaseResolution", baseResEvent);
 1301        }
 1302
 1303        public static void ReportAnalyticsEvent(string eventName) { ReportAnalyticsEvent(eventName, null); }
 1304
 1305        public static void ReportAnalyticsEvent(string eventName, AnalyticsPayload.Property[] eventProperties)
 1306        {
 1307            analyticsEvent.name = eventName;
 1308            analyticsEvent.properties = eventProperties;
 1309            SendMessage("Track", analyticsEvent);
 1310        }
 1311
 1312        public static void FetchBalanceOfMANA() { SendMessage("FetchBalanceOfMANA"); }
 1313
 1314        public static void SendSceneExternalActionEvent(string sceneId, string type, string payload)
 1315        {
 1316            sceneExternalActionEvent.type = type;
 1317            sceneExternalActionEvent.payload = payload;
 1318            SendSceneEvent(sceneId, "externalAction", sceneExternalActionEvent);
 1319        }
 1320
 1321        public static void SetMuteUsers(string[] usersId, bool mute)
 1322        {
 1323            muteUserEvent.usersId = usersId;
 1324            muteUserEvent.mute = mute;
 1325            SendMessage("SetMuteUsers", muteUserEvent);
 1326        }
 1327
 1328        public static void SendCloseUserAvatar(bool isSignUpFlow)
 1329        {
 1330            closeUserAvatarPayload.isSignUpFlow = isSignUpFlow;
 1331            SendMessage("CloseUserAvatar", closeUserAvatarPayload);
 1332        }
 1333
 1334        public static void KillPortableExperience(string portableExperienceId)
 1335        {
 1336            killPortableExperiencePayload.portableExperienceId = portableExperienceId;
 1337            SendMessage("KillPortableExperience", killPortableExperiencePayload);
 1338        }
 1339
 1340        public static void RequestWearables(
 1341            string ownedByUser,
 1342            string[] wearableIds,
 1343            string[] collectionIds,
 1344            string context)
 1345        {
 1346            requestWearablesPayload.filters = new WearablesRequestFiltersPayload
 1347            {
 1348                ownedByUser = ownedByUser,
 1349                wearableIds = wearableIds,
 1350                collectionIds = collectionIds
 1351            };
 1352
 1353            requestWearablesPayload.context = context;
 1354
 1355            SendMessage("RequestWearables", requestWearablesPayload);
 1356        }
 1357
 1358        public static void SearchENSOwner(string name, int maxResults)
 1359        {
 1360            searchEnsOwnerPayload.name = name;
 1361            searchEnsOwnerPayload.maxResults = maxResults;
 1362
 1363            SendMessage("SearchENSOwner", searchEnsOwnerPayload);
 1364        }
 1365
 1366        public static void RequestUserProfile(string userId)
 1367        {
 1368            stringPayload.value = userId;
 1369            SendMessage("RequestUserProfile", stringPayload);
 1370        }
 1371
 1372        public static void ReportAvatarFatalError() { SendMessage("ReportAvatarFatalError"); }
 1373
 1374        public static void UnpublishScene(Vector2Int sceneCoordinates)
 1375        {
 1376            var payload = new UnpublishScenePayload() { coordinates = $"{sceneCoordinates.x},{sceneCoordinates.y}" };
 1377            SendMessage("UnpublishScene", payload);
 1378        }
 1379
 1380        public static void NotifyStatusThroughChat(string message)
 1381        {
 1382            stringPayload.value = message;
 1383            SendMessage("NotifyStatusThroughChat", stringPayload);
 1384        }
 1385
 1386        public static void ReportVideoProgressEvent(
 1387            string componentId,
 1388            string sceneId,
 1389            string videoClipId,
 1390            int videoStatus,
 1391            float currentOffset,
 1392            float length)
 1393        {
 1394            SendVideoProgressEvent progressEvent = new SendVideoProgressEvent()
 1395            {
 1396                componentId = componentId,
 1397                sceneId = sceneId,
 1398                videoTextureId = videoClipId,
 1399                status = videoStatus,
 1400                currentOffset =  currentOffset,
 1401                videoLength = length
 1402            };
 1403
 1404            SendMessage("VideoProgressEvent", progressEvent);
 1405        }
 1406    }
 1407}

Methods/Properties

UUIDEvent()