| | 1 | | using DCL; |
| | 2 | | using DCL.Builder; |
| | 3 | | using DCL.Components; |
| | 4 | | using DCL.Models; |
| | 5 | |
|
| | 6 | | public class BuilderInWorldPlugin : IPlugin |
| | 7 | | { |
| | 8 | | private const string DEV_FLAG_NAME = "builder-dev"; |
| | 9 | | internal IBIWEditor editor; |
| | 10 | | internal IBuilderMainPanelController panelController; |
| | 11 | | internal IBuilderAPIController builderAPIController; |
| | 12 | | internal ISceneManager sceneManager; |
| | 13 | | internal ICameraController cameraController; |
| | 14 | | internal IPublisher publisher; |
| | 15 | | internal ICommonHUD commonHUD; |
| | 16 | |
|
| | 17 | | internal IContext context; |
| | 18 | |
|
| 0 | 19 | | public BuilderInWorldPlugin() |
| | 20 | | { |
| 0 | 21 | | if (DataStore.i.featureFlags.flags.Get().IsFeatureEnabled(DEV_FLAG_NAME)) |
| 0 | 22 | | DataStore.i.builderInWorld.isDevBuild.Set(true); |
| | 23 | |
|
| 0 | 24 | | RegisterRuntimeComponents(); |
| | 25 | |
|
| 0 | 26 | | panelController = new BuilderMainPanelController(); |
| 0 | 27 | | editor = new BuilderInWorldEditor(); |
| 0 | 28 | | builderAPIController = new BuilderAPIController(); |
| 0 | 29 | | sceneManager = new SceneManager(); |
| 0 | 30 | | cameraController = new CameraController(); |
| 0 | 31 | | publisher = new Publisher(); |
| 0 | 32 | | commonHUD = new CommonHUD(); |
| | 33 | |
|
| 0 | 34 | | context = new Context(editor, |
| | 35 | | panelController, |
| | 36 | | builderAPIController, |
| | 37 | | sceneManager, |
| | 38 | | cameraController, |
| | 39 | | publisher, |
| | 40 | | commonHUD, |
| | 41 | | new BuilderEditorHUDController(), |
| | 42 | | new BIWOutlinerController(), |
| | 43 | | new BIWInputHandler(), |
| | 44 | | new BIWInputWrapper(), |
| | 45 | | new BIWPublishController(), |
| | 46 | | new BIWCreatorController(), |
| | 47 | | new BIWModeController(), |
| | 48 | | new BIWFloorHandler(), |
| | 49 | | new BIWEntityHandler(), |
| | 50 | | new BIWActionController(), |
| | 51 | | new BIWSaveController(), |
| | 52 | | new BIWRaycastController(), |
| | 53 | | new BIWGizmosController(), |
| | 54 | | SceneReferences.i); |
| | 55 | |
|
| 0 | 56 | | Initialize(); |
| 0 | 57 | | } |
| | 58 | |
|
| 7 | 59 | | public BuilderInWorldPlugin(IContext context) |
| | 60 | | { |
| 7 | 61 | | this.context = context; |
| 7 | 62 | | sceneManager = context.sceneManager; |
| 7 | 63 | | panelController = context.panelHUD; |
| 7 | 64 | | editor = context.editor; |
| 7 | 65 | | builderAPIController = context.builderAPIController; |
| 7 | 66 | | cameraController = context.cameraController; |
| 7 | 67 | | publisher = context.publisher; |
| 7 | 68 | | commonHUD = context.commonHUD; |
| | 69 | |
|
| 7 | 70 | | Initialize(); |
| 7 | 71 | | } |
| | 72 | |
|
| | 73 | | private void Initialize() |
| | 74 | | { |
| | 75 | | //We init the lands so we don't have a null reference |
| 7 | 76 | | DataStore.i.builderInWorld.landsWithAccess.Set(new LandWithAccess[0]); |
| | 77 | |
|
| 7 | 78 | | BIWCatalogManager.Init(); |
| | 79 | |
|
| 7 | 80 | | panelController.Initialize(context); |
| 7 | 81 | | editor.Initialize(context); |
| 7 | 82 | | builderAPIController.Initialize(context); |
| 7 | 83 | | sceneManager.Initialize(context); |
| 7 | 84 | | cameraController.Initialize(context); |
| 7 | 85 | | publisher.Initialize(context); |
| 7 | 86 | | commonHUD.Initialize(context); |
| | 87 | |
|
| 7 | 88 | | DCL.Environment.i.platform.updateEventHandler.AddListener(IUpdateEventHandler.EventType.Update, Update); |
| 7 | 89 | | DCL.Environment.i.platform.updateEventHandler.AddListener(IUpdateEventHandler.EventType.LateUpdate, LateUpdate); |
| 7 | 90 | | DCL.Environment.i.platform.updateEventHandler.AddListener(IUpdateEventHandler.EventType.OnGui, OnGUI); |
| | 91 | |
|
| 7 | 92 | | DataStore.i.builderInWorld.isInitialized.Set(true); |
| 7 | 93 | | } |
| | 94 | |
|
| | 95 | | public void Dispose() |
| | 96 | | { |
| 7 | 97 | | if (DataStore.i.common.isApplicationQuitting.Get()) |
| 0 | 98 | | return; |
| | 99 | |
|
| 7 | 100 | | editor.Dispose(); |
| 7 | 101 | | panelController.Dispose(); |
| 7 | 102 | | sceneManager.Dispose(); |
| 7 | 103 | | cameraController.Dispose(); |
| 7 | 104 | | publisher.Dispose(); |
| 7 | 105 | | commonHUD.Dispose(); |
| 7 | 106 | | context.Dispose(); |
| | 107 | |
|
| 7 | 108 | | Environment.i.platform.updateEventHandler.RemoveListener(IUpdateEventHandler.EventType.Update, Update); |
| 7 | 109 | | Environment.i.platform.updateEventHandler.RemoveListener(IUpdateEventHandler.EventType.LateUpdate, LateUpdate); |
| 7 | 110 | | Environment.i.platform.updateEventHandler.RemoveListener(IUpdateEventHandler.EventType.OnGui, OnGUI); |
| | 111 | |
|
| 7 | 112 | | UnregisterRuntimeComponents(); |
| 7 | 113 | | } |
| | 114 | |
|
| | 115 | | public void Update() |
| | 116 | | { |
| 2 | 117 | | editor.Update(); |
| 2 | 118 | | sceneManager.Update(); |
| 2 | 119 | | } |
| | 120 | |
|
| 4 | 121 | | public void LateUpdate() { editor.LateUpdate(); } |
| | 122 | |
|
| 2 | 123 | | public void OnGUI() { editor.OnGUI(); } |
| | 124 | |
|
| | 125 | | public static void UnregisterRuntimeComponents() |
| | 126 | | { |
| | 127 | | // Builder in world |
| 82 | 128 | | IRuntimeComponentFactory factory = Environment.i.world.componentFactory; |
| 82 | 129 | | factory.UnregisterBuilder((int) CLASS_ID.NAME); |
| 82 | 130 | | factory.UnregisterBuilder((int) CLASS_ID.LOCKED_ON_EDIT); |
| 82 | 131 | | factory.UnregisterBuilder((int) CLASS_ID.VISIBLE_ON_EDIT); |
| 82 | 132 | | } |
| | 133 | |
|
| | 134 | | public static void RegisterRuntimeComponents() |
| | 135 | | { |
| | 136 | | // Builder in world |
| 75 | 137 | | IRuntimeComponentFactory factory = Environment.i.world.componentFactory; |
| 75 | 138 | | factory.RegisterBuilder((int) CLASS_ID.NAME, BuildComponent<DCLName>); |
| 75 | 139 | | factory.RegisterBuilder((int) CLASS_ID.LOCKED_ON_EDIT, BuildComponent<DCLLockedOnEdit>); |
| 75 | 140 | | factory.RegisterBuilder((int) CLASS_ID.VISIBLE_ON_EDIT, BuildComponent<DCLVisibleOnEdit>); |
| 75 | 141 | | } |
| | 142 | |
|
| | 143 | | private static T BuildComponent<T>() |
| | 144 | | where T : IComponent, new() |
| | 145 | | { |
| 71 | 146 | | return new T(); |
| | 147 | | } |
| | 148 | |
|
| | 149 | | } |