| | 1 | | using UnityEngine; |
| | 2 | |
|
| | 3 | | public class BIWPublishController : BIWController |
| | 4 | | { |
| | 5 | | public BuilderInWorldEntityHandler builderInWorldEntityHandler; |
| | 6 | | public BuilderInWorldBridge builderInWorldBridge; |
| | 7 | | public BIWCreatorController biwCreatorController; |
| | 8 | |
|
| | 9 | | private int checkerSceneLimitsOptimizationCounter = 0; |
| | 10 | |
|
| | 11 | | private const int FRAMES_BEETWEN_UPDATES = 10; |
| | 12 | | private const string FEEDBACK_MESSAGE_ENTITY_ERROR = "Some entities have errors (marked as pink cubes)."; |
| | 13 | | private const string FEEDBACK_MESSAGE_OUTSIDE_BOUNDARIES = "Some entities are outside of the Scene boundaries."; |
| | 14 | | private const string FEEDBACK_MESSAGE_TOO_MANY_ENTITIES = "Too many entities in the scene. Check scene limits."; |
| | 15 | |
|
| 198 | 16 | | private bool reportSceneLimitsOverpassedAnalytic = true; |
| | 17 | | private float startPublishingTimestamp = 0; |
| | 18 | |
|
| | 19 | | public override void Init() |
| | 20 | | { |
| 9 | 21 | | if (HUDController.i?.builderInWorldMainHud != null) |
| | 22 | | { |
| 0 | 23 | | HUDController.i.builderInWorldMainHud.OnPublishAction += StartPublishFlow; |
| 0 | 24 | | HUDController.i.builderInWorldMainHud.OnConfirmPublishAction += StartPublishScene; |
| | 25 | | } |
| 9 | 26 | | if (builderInWorldBridge != null) |
| 0 | 27 | | builderInWorldBridge.OnPublishEnd += PublishEnd; |
| 9 | 28 | | } |
| | 29 | |
|
| | 30 | | protected override void FrameUpdate() |
| | 31 | | { |
| 0 | 32 | | base.FrameUpdate(); |
| 0 | 33 | | if (checkerSceneLimitsOptimizationCounter >= FRAMES_BEETWEN_UPDATES) |
| | 34 | | { |
| 0 | 35 | | checkerSceneLimitsOptimizationCounter = 0; |
| 0 | 36 | | CheckPublishConditions(); |
| 0 | 37 | | } |
| | 38 | | else |
| | 39 | | { |
| 0 | 40 | | checkerSceneLimitsOptimizationCounter++; |
| | 41 | | } |
| 0 | 42 | | } |
| | 43 | |
|
| | 44 | | private void OnDestroy() |
| | 45 | | { |
| 0 | 46 | | if (HUDController.i.builderInWorldMainHud != null) |
| | 47 | | { |
| 0 | 48 | | HUDController.i.builderInWorldMainHud.OnPublishAction -= StartPublishFlow; |
| 0 | 49 | | HUDController.i.builderInWorldMainHud.OnConfirmPublishAction -= StartPublishScene; |
| | 50 | | } |
| 0 | 51 | | if (builderInWorldBridge != null) |
| 0 | 52 | | builderInWorldBridge.OnPublishEnd -= PublishEnd; |
| 0 | 53 | | } |
| | 54 | |
|
| | 55 | | public bool CanPublish() |
| | 56 | | { |
| 3 | 57 | | if (biwCreatorController.IsAnyErrorOnEntities()) |
| 0 | 58 | | return false; |
| | 59 | |
|
| 3 | 60 | | if (!sceneToEdit.metricsController.IsInsideTheLimits()) |
| 1 | 61 | | return false; |
| | 62 | |
|
| 2 | 63 | | if (!builderInWorldEntityHandler.AreAllEntitiesInsideBoundaries()) |
| 1 | 64 | | return false; |
| | 65 | |
|
| 1 | 66 | | reportSceneLimitsOverpassedAnalytic = true; |
| 1 | 67 | | return true; |
| | 68 | | } |
| | 69 | |
|
| | 70 | | void CheckPublishConditions() |
| | 71 | | { |
| 0 | 72 | | if (HUDController.i.builderInWorldMainHud is null) |
| 0 | 73 | | return; |
| | 74 | |
|
| 0 | 75 | | string feedbackMessage = ""; |
| 0 | 76 | | if (biwCreatorController.IsAnyErrorOnEntities()) |
| | 77 | | { |
| 0 | 78 | | feedbackMessage = FEEDBACK_MESSAGE_ENTITY_ERROR; |
| 0 | 79 | | } |
| 0 | 80 | | else if (!builderInWorldEntityHandler.AreAllEntitiesInsideBoundaries()) |
| | 81 | | { |
| 0 | 82 | | feedbackMessage = FEEDBACK_MESSAGE_OUTSIDE_BOUNDARIES; |
| 0 | 83 | | } |
| 0 | 84 | | else if (!sceneToEdit.metricsController.IsInsideTheLimits()) |
| | 85 | | { |
| 0 | 86 | | feedbackMessage = FEEDBACK_MESSAGE_TOO_MANY_ENTITIES; |
| 0 | 87 | | if (reportSceneLimitsOverpassedAnalytic) |
| | 88 | | { |
| 0 | 89 | | BIWAnalytics.SceneLimitsOverPassed(sceneToEdit.metricsController.GetModel()); |
| 0 | 90 | | reportSceneLimitsOverpassedAnalytic = false; |
| | 91 | | } |
| | 92 | | } |
| | 93 | |
|
| 0 | 94 | | HUDController.i.builderInWorldMainHud.SetPublishBtnAvailability(CanPublish(), feedbackMessage); |
| 0 | 95 | | } |
| | 96 | |
|
| | 97 | | private void StartPublishFlow() |
| | 98 | | { |
| 0 | 99 | | if (!CanPublish()) |
| 0 | 100 | | return; |
| | 101 | |
|
| 0 | 102 | | HUDController.i.builderInWorldMainHud.PublishStart(); |
| 0 | 103 | | } |
| | 104 | |
|
| | 105 | | private void StartPublishScene(string sceneName, string sceneDescription, string sceneScreenshot) |
| | 106 | | { |
| 0 | 107 | | startPublishingTimestamp = Time.realtimeSinceStartup; |
| 0 | 108 | | BIWAnalytics.StartScenePublish(sceneToEdit.metricsController.GetModel()); |
| 0 | 109 | | builderInWorldBridge.PublishScene(sceneToEdit, sceneName, sceneDescription, sceneScreenshot); |
| 0 | 110 | | } |
| | 111 | |
|
| | 112 | | private void PublishEnd(bool isOk, string message) |
| | 113 | | { |
| 0 | 114 | | if (HUDController.i.builderInWorldMainHud != null) |
| 0 | 115 | | HUDController.i.builderInWorldMainHud.PublishEnd(isOk, message); |
| 0 | 116 | | string successString = isOk ? "Success" : message; |
| 0 | 117 | | BIWAnalytics.EndScenePublish(sceneToEdit.metricsController.GetModel(), successString, Time.realtimeSinceStartup |
| 0 | 118 | | } |
| | 119 | | } |