| | 1 | | using System.Collections; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using DCL; |
| | 4 | | using DCL.Components; |
| | 5 | | using DCL.Helpers; |
| | 6 | | using DCL.Models; |
| | 7 | | using UnityEngine; |
| | 8 | | using Decentraland.Sdk.Ecs6; |
| | 9 | |
|
| | 10 | | public class UUIDEventsPlugin : IPlugin |
| | 11 | | { |
| | 12 | | public PointerEventsController pointerEventsController; |
| | 13 | | public InputController_Legacy inputControllerLegacy; |
| | 14 | | public InteractionHoverCanvasController hoverCanvas; |
| | 15 | |
|
| 85 | 16 | | public UUIDEventsPlugin() |
| | 17 | | { |
| 85 | 18 | | inputControllerLegacy = new InputController_Legacy(); |
| 85 | 19 | | hoverCanvas = LoadAndInstantiate<InteractionHoverCanvasController>("InteractionHoverCanvas"); |
| | 20 | |
|
| 85 | 21 | | pointerEventsController = new PointerEventsController(inputControllerLegacy, hoverCanvas, SceneReferences.i?.mou |
| | 22 | |
|
| 85 | 23 | | IRuntimeComponentFactory factory = Environment.i.world.componentFactory; |
| | 24 | |
|
| 85 | 25 | | factory.RegisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_DOWN, |
| | 26 | | BuildUUIDEventComponent<OnPointerDown>); |
| 85 | 27 | | factory.RegisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_UP, |
| | 28 | | BuildUUIDEventComponent<OnPointerUp>); |
| 85 | 29 | | factory.RegisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_CLICK, |
| | 30 | | BuildUUIDEventComponent<OnClick>); |
| 85 | 31 | | factory.RegisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_HOVER_EXIT, |
| | 32 | | BuildUUIDEventComponent<OnPointerHoverExit>); |
| 85 | 33 | | factory.RegisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_HOVER_ENTER, |
| | 34 | | BuildUUIDEventComponent<OnPointerHoverEnter>); |
| | 35 | |
|
| 85 | 36 | | factory.createOverrides.Add((int) CLASS_ID_COMPONENT.UUID_CALLBACK, OnUUIDCallbackIsAdded); |
| 85 | 37 | | } |
| | 38 | |
|
| | 39 | | private void OnUUIDCallbackIsAdded(int sceneNumber, long entityid, ref int classId, object data) |
| | 40 | | { |
| 70 | 41 | | OnPointerEvent.Model model = new OnPointerEvent.Model(); |
| 70 | 42 | | if (data is string json) |
| 70 | 43 | | model = (OnPointerEvent.Model)model.GetDataFromJSON(json); |
| 0 | 44 | | else if (data is Decentraland.Sdk.Ecs6.ComponentBodyPayload payload) |
| 0 | 45 | | model = (OnPointerEvent.Model)model.GetDataFromPb(payload); |
| | 46 | |
|
| 70 | 47 | | classId = (int) model.GetClassIdFromType(); |
| 70 | 48 | | } |
| | 49 | |
|
| | 50 | | public void Dispose() |
| | 51 | | { |
| 85 | 52 | | pointerEventsController.Dispose(); |
| 85 | 53 | | inputControllerLegacy.Dispose(); |
| | 54 | |
|
| 85 | 55 | | IRuntimeComponentFactory factory = Environment.i.world.componentFactory; |
| | 56 | |
|
| 85 | 57 | | factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_DOWN); |
| 85 | 58 | | factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_UP); |
| 85 | 59 | | factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_CLICK); |
| 85 | 60 | | factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_HOVER_EXIT); |
| 85 | 61 | | factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_HOVER_ENTER); |
| | 62 | |
|
| 85 | 63 | | factory.createOverrides.Remove((int) CLASS_ID_COMPONENT.UUID_CALLBACK); |
| 85 | 64 | | } |
| | 65 | |
|
| | 66 | | private static T LoadAndInstantiate<T>(string name) |
| | 67 | | { |
| 85 | 68 | | GameObject instance = Object.Instantiate(Resources.Load(name)) as GameObject; |
| 85 | 69 | | instance.name = name; |
| 85 | 70 | | return instance.GetComponent<T>(); |
| | 71 | | } |
| | 72 | |
|
| | 73 | | private T BuildUUIDEventComponent<T>() |
| | 74 | | where T : Component |
| | 75 | | { |
| 59 | 76 | | var go = new GameObject("UUID Component"); |
| 59 | 77 | | T newComponent = go.GetOrCreateComponent<T>(); |
| 59 | 78 | | return newComponent; |
| | 79 | | } |
| | 80 | | } |