| | 1 | | using DCL; |
| | 2 | | using DCL.Builder; |
| | 3 | |
|
| | 4 | | public class BuilderInWorldPlugin : IPlugin |
| | 5 | | { |
| | 6 | | private const string DEV_FLAG_NAME = "builder-dev"; |
| | 7 | | internal IBIWEditor editor; |
| | 8 | | internal IBuilderMainPanelController panelController; |
| | 9 | | internal IBuilderAPIController builderAPIController; |
| | 10 | | internal ISceneManager sceneManager; |
| | 11 | | internal ICameraController cameraController; |
| | 12 | | internal IPublisher publisher; |
| | 13 | |
|
| | 14 | | internal IContext context; |
| | 15 | |
|
| 0 | 16 | | public BuilderInWorldPlugin() |
| | 17 | | { |
| 0 | 18 | | if (DataStore.i.featureFlags.flags.Get().IsFeatureEnabled(DEV_FLAG_NAME)) |
| 0 | 19 | | DataStore.i.builderInWorld.isDevBuild.Set(true); |
| | 20 | |
|
| 0 | 21 | | panelController = new BuilderMainPanelController(); |
| 0 | 22 | | editor = new BuilderInWorldEditor(); |
| 0 | 23 | | builderAPIController = new BuilderAPIController(); |
| 0 | 24 | | sceneManager = new SceneManager(); |
| 0 | 25 | | cameraController = new CameraController(); |
| 0 | 26 | | publisher = new Publisher(); |
| | 27 | |
|
| 0 | 28 | | context = new Context(editor, |
| | 29 | | panelController, |
| | 30 | | builderAPIController, |
| | 31 | | sceneManager, |
| | 32 | | cameraController, |
| | 33 | | publisher, |
| | 34 | | new BuilderEditorHUDController(), |
| | 35 | | new BIWOutlinerController(), |
| | 36 | | new BIWInputHandler(), |
| | 37 | | new BIWInputWrapper(), |
| | 38 | | new BIWPublishController(), |
| | 39 | | new BIWCreatorController(), |
| | 40 | | new BIWModeController(), |
| | 41 | | new BIWFloorHandler(), |
| | 42 | | new BIWEntityHandler(), |
| | 43 | | new BIWActionController(), |
| | 44 | | new BIWSaveController(), |
| | 45 | | new BIWRaycastController(), |
| | 46 | | new BIWGizmosController(), |
| | 47 | | SceneReferences.i); |
| | 48 | |
|
| 0 | 49 | | Initialize(); |
| 0 | 50 | | } |
| | 51 | |
|
| 7 | 52 | | public BuilderInWorldPlugin(IContext context) |
| | 53 | | { |
| 7 | 54 | | this.context = context; |
| 7 | 55 | | sceneManager = context.sceneManager; |
| 7 | 56 | | panelController = context.panelHUD; |
| 7 | 57 | | editor = context.editor; |
| 7 | 58 | | builderAPIController = context.builderAPIController; |
| 7 | 59 | | cameraController = context.cameraController; |
| 7 | 60 | | publisher = context.publisher; |
| | 61 | |
|
| 7 | 62 | | Initialize(); |
| 7 | 63 | | } |
| | 64 | |
|
| | 65 | | private void Initialize() |
| | 66 | | { |
| | 67 | | //We init the lands so we don't have a null reference |
| 7 | 68 | | DataStore.i.builderInWorld.landsWithAccess.Set(new LandWithAccess[0]); |
| | 69 | |
|
| 7 | 70 | | BIWCatalogManager.Init(); |
| | 71 | |
|
| 7 | 72 | | panelController.Initialize(context); |
| 7 | 73 | | editor.Initialize(context); |
| 7 | 74 | | builderAPIController.Initialize(context); |
| 7 | 75 | | sceneManager.Initialize(context); |
| 7 | 76 | | cameraController.Initialize(context); |
| 7 | 77 | | publisher.Initialize(); |
| | 78 | |
|
| 7 | 79 | | DCL.Environment.i.platform.updateEventHandler.AddListener(IUpdateEventHandler.EventType.Update, Update); |
| 7 | 80 | | DCL.Environment.i.platform.updateEventHandler.AddListener(IUpdateEventHandler.EventType.LateUpdate, LateUpdate); |
| 7 | 81 | | DCL.Environment.i.platform.updateEventHandler.AddListener(IUpdateEventHandler.EventType.OnGui, OnGUI); |
| | 82 | |
|
| 7 | 83 | | DataStore.i.builderInWorld.isInitialized.Set(true); |
| 7 | 84 | | } |
| | 85 | |
|
| | 86 | | public void Dispose() |
| | 87 | | { |
| 7 | 88 | | if (DataStore.i.common.isApplicationQuitting.Get()) |
| 0 | 89 | | return; |
| | 90 | |
|
| 7 | 91 | | editor.Dispose(); |
| 7 | 92 | | panelController.Dispose(); |
| 7 | 93 | | sceneManager.Dispose(); |
| 7 | 94 | | cameraController.Dispose(); |
| 7 | 95 | | publisher.Dipose(); |
| 7 | 96 | | context.Dispose(); |
| | 97 | |
|
| 7 | 98 | | Environment.i.platform.updateEventHandler.RemoveListener(IUpdateEventHandler.EventType.Update, Update); |
| 7 | 99 | | Environment.i.platform.updateEventHandler.RemoveListener(IUpdateEventHandler.EventType.LateUpdate, LateUpdate); |
| 7 | 100 | | Environment.i.platform.updateEventHandler.RemoveListener(IUpdateEventHandler.EventType.OnGui, OnGUI); |
| 7 | 101 | | } |
| | 102 | |
|
| | 103 | | public void Update() |
| | 104 | | { |
| 2 | 105 | | editor.Update(); |
| 2 | 106 | | sceneManager.Update(); |
| 2 | 107 | | } |
| | 108 | |
|
| 4 | 109 | | public void LateUpdate() { editor.LateUpdate(); } |
| | 110 | |
|
| 2 | 111 | | public void OnGUI() { editor.OnGUI(); } |
| | 112 | | } |