| | 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 | |
|
| | 9 | | public class UUIDEventsPlugin : IPlugin |
| | 10 | | { |
| | 11 | | public PointerEventsController pointerEventsController; |
| | 12 | | public InputController_Legacy inputControllerLegacy; |
| | 13 | | public InteractionHoverCanvasController hoverCanvas; |
| | 14 | |
|
| 83 | 15 | | public UUIDEventsPlugin() |
| | 16 | | { |
| 83 | 17 | | inputControllerLegacy = new InputController_Legacy(); |
| 83 | 18 | | hoverCanvas = LoadAndInstantiate<InteractionHoverCanvasController>("InteractionHoverCanvas"); |
| | 19 | |
|
| 83 | 20 | | pointerEventsController = new PointerEventsController(inputControllerLegacy, hoverCanvas); |
| | 21 | |
|
| 83 | 22 | | IRuntimeComponentFactory factory = Environment.i.world.componentFactory; |
| | 23 | |
|
| 83 | 24 | | factory.RegisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_DOWN, |
| | 25 | | BuildUUIDEventComponent<OnPointerDown>); |
| 83 | 26 | | factory.RegisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_UP, |
| | 27 | | BuildUUIDEventComponent<OnPointerUp>); |
| 83 | 28 | | factory.RegisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_CLICK, |
| | 29 | | BuildUUIDEventComponent<OnClick>); |
| 83 | 30 | | factory.RegisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_HOVER_EXIT, |
| | 31 | | BuildUUIDEventComponent<OnPointerHoverExit>); |
| 83 | 32 | | factory.RegisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_HOVER_ENTER, |
| | 33 | | BuildUUIDEventComponent<OnPointerHoverEnter>); |
| | 34 | |
|
| 83 | 35 | | factory.createOverrides.Add((int) CLASS_ID_COMPONENT.UUID_CALLBACK, OnUUIDCallbackIsAdded); |
| 83 | 36 | | } |
| | 37 | |
|
| | 38 | | private void OnUUIDCallbackIsAdded(string sceneid, long entityid, ref int classId, object data) |
| | 39 | | { |
| 70 | 40 | | OnPointerEvent.Model model = JsonUtility.FromJson<OnPointerEvent.Model>(data as string); |
| 70 | 41 | | classId = (int) model.GetClassIdFromType(); |
| 70 | 42 | | } |
| | 43 | |
|
| | 44 | | public void Dispose() |
| | 45 | | { |
| 83 | 46 | | pointerEventsController.Dispose(); |
| 83 | 47 | | inputControllerLegacy.Dispose(); |
| | 48 | |
|
| 83 | 49 | | IRuntimeComponentFactory factory = Environment.i.world.componentFactory; |
| | 50 | |
|
| 83 | 51 | | factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_DOWN); |
| 83 | 52 | | factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_UP); |
| 83 | 53 | | factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_CLICK); |
| 83 | 54 | | factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_HOVER_EXIT); |
| 83 | 55 | | factory.UnregisterBuilder((int) CLASS_ID_COMPONENT.UUID_ON_HOVER_ENTER); |
| | 56 | |
|
| 83 | 57 | | factory.createOverrides.Remove((int) CLASS_ID_COMPONENT.UUID_CALLBACK); |
| 83 | 58 | | } |
| | 59 | |
|
| | 60 | | private static T LoadAndInstantiate<T>(string name) |
| | 61 | | { |
| 83 | 62 | | GameObject instance = Object.Instantiate(Resources.Load(name)) as GameObject; |
| 83 | 63 | | instance.name = name; |
| 83 | 64 | | return instance.GetComponent<T>(); |
| | 65 | | } |
| | 66 | |
|
| | 67 | | private T BuildUUIDEventComponent<T>() |
| | 68 | | where T : Component |
| | 69 | | { |
| 59 | 70 | | var go = new GameObject("UUID Component"); |
| 59 | 71 | | T newComponent = go.GetOrCreateComponent<T>(); |
| 59 | 72 | | return newComponent; |
| | 73 | | } |
| | 74 | | } |