| | 1 | | using System.Collections; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using DCL; |
| | 4 | | using DCL.Components; |
| | 5 | | using DCL.Controllers; |
| | 6 | | using DCL.Models; |
| | 7 | | using UnityEngine; |
| | 8 | |
|
| | 9 | | public class UIComponentsPlugin : IPlugin |
| | 10 | | { |
| 61 | 11 | | public UIComponentsPlugin() |
| | 12 | | { |
| 61 | 13 | | IRuntimeComponentFactory factory = Environment.i.world.componentFactory; |
| | 14 | |
|
| | 15 | | // UI |
| 61 | 16 | | factory.RegisterBuilder((int) CLASS_ID.UI_INPUT_TEXT_SHAPE, BuildComponent<UIInputText>); |
| 61 | 17 | | factory.RegisterBuilder((int) CLASS_ID.UI_FULLSCREEN_SHAPE, BuildComponent<UIScreenSpace>); |
| 61 | 18 | | factory.RegisterBuilder((int) CLASS_ID.UI_SCREEN_SPACE_SHAPE, BuildComponent<UIScreenSpace>); |
| 61 | 19 | | factory.RegisterBuilder((int) CLASS_ID.UI_CONTAINER_RECT, BuildComponent<UIContainerRect>); |
| 61 | 20 | | factory.RegisterBuilder((int) CLASS_ID.UI_SLIDER_SHAPE, BuildComponent<UIScrollRect>); |
| 61 | 21 | | factory.RegisterBuilder((int) CLASS_ID.UI_CONTAINER_STACK, BuildComponent<UIContainerStack>); |
| 61 | 22 | | factory.RegisterBuilder((int) CLASS_ID.UI_IMAGE_SHAPE, BuildComponent<UIImage>); |
| 61 | 23 | | factory.RegisterBuilder((int) CLASS_ID.UI_TEXT_SHAPE, BuildComponent<UIText>); |
| | 24 | |
|
| 61 | 25 | | factory.createConditions.Add((int) CLASS_ID.UI_SCREEN_SPACE_SHAPE, CanCreateScreenShape); |
| 61 | 26 | | factory.createConditions.Add((int) CLASS_ID.UI_FULLSCREEN_SHAPE, CanCreateScreenShape); |
| 61 | 27 | | } |
| | 28 | |
|
| | 29 | | bool CanCreateScreenShape(string sceneId, int classId) |
| | 30 | | { |
| 44 | 31 | | IParcelScene scene = Environment.i.world.state.GetScene(sceneId); |
| | 32 | |
|
| 44 | 33 | | if (scene.componentsManagerLegacy.GetSceneSharedComponent<UIScreenSpace>() != null) |
| 0 | 34 | | return false; |
| | 35 | |
|
| 44 | 36 | | return true; |
| | 37 | | } |
| | 38 | |
|
| | 39 | |
|
| | 40 | | protected T BuildComponent<T>() |
| | 41 | | where T : IComponent, new() |
| | 42 | | { |
| 122 | 43 | | return new T(); |
| | 44 | | } |
| | 45 | |
|
| | 46 | |
|
| | 47 | | public void Dispose() |
| | 48 | | { |
| 61 | 49 | | IRuntimeComponentFactory factory = Environment.i.world.componentFactory; |
| | 50 | |
|
| 61 | 51 | | factory.UnregisterBuilder((int) CLASS_ID.UI_INPUT_TEXT_SHAPE); |
| 61 | 52 | | factory.UnregisterBuilder((int) CLASS_ID.UI_FULLSCREEN_SHAPE); |
| 61 | 53 | | factory.UnregisterBuilder((int) CLASS_ID.UI_SCREEN_SPACE_SHAPE); |
| 61 | 54 | | factory.UnregisterBuilder((int) CLASS_ID.UI_CONTAINER_RECT); |
| 61 | 55 | | factory.UnregisterBuilder((int) CLASS_ID.UI_SLIDER_SHAPE); |
| 61 | 56 | | factory.UnregisterBuilder((int) CLASS_ID.UI_CONTAINER_STACK); |
| 61 | 57 | | factory.UnregisterBuilder((int) CLASS_ID.UI_IMAGE_SHAPE); |
| 61 | 58 | | factory.UnregisterBuilder((int) CLASS_ID.UI_TEXT_SHAPE); |
| | 59 | |
|
| 61 | 60 | | factory.createConditions.Remove((int) CLASS_ID.UI_SCREEN_SPACE_SHAPE); |
| 61 | 61 | | factory.createConditions.Remove((int) CLASS_ID.UI_FULLSCREEN_SHAPE); |
| 61 | 62 | | } |
| | 63 | | } |