< Summary

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

Metrics

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

Methods/Properties

ControlEvent(System.String, T)