| | 1 | | using DCL; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | public interface IBIWPublishController { } |
| | 5 | |
|
| | 6 | | public class BIWPublishController : BIWController, IBIWPublishController |
| | 7 | | { |
| | 8 | | private IBIWEntityHandler entityHandler; |
| | 9 | | private IBIWCreatorController creatorController; |
| | 10 | |
|
| | 11 | | private BuilderInWorldBridge builderInWorldBridge; |
| | 12 | |
|
| | 13 | | private int checkerSceneLimitsOptimizationCounter = 0; |
| | 14 | |
|
| | 15 | | private const int FRAMES_BEETWEN_UPDATES = 10; |
| | 16 | | private const string FEEDBACK_MESSAGE_ENTITY_ERROR = "Some entities have errors (marked as pink cubes)."; |
| | 17 | | private const string FEEDBACK_MESSAGE_OUTSIDE_BOUNDARIES = "Some entities are outside of the Scene boundaries."; |
| | 18 | | private const string FEEDBACK_MESSAGE_TOO_MANY_ENTITIES = "Too many entities in the scene. Check scene limits."; |
| | 19 | |
|
| | 20 | | private float startPublishingTimestamp = 0; |
| | 21 | |
|
| | 22 | | public override void Init(BIWContext context) |
| | 23 | | { |
| 30 | 24 | | base.Init(context); |
| | 25 | |
|
| 30 | 26 | | entityHandler = context.entityHandler; |
| 30 | 27 | | creatorController = context.creatorController; |
| | 28 | |
|
| 30 | 29 | | if (HUDController.i?.builderInWorldMainHud != null) |
| | 30 | | { |
| 26 | 31 | | HUDController.i.builderInWorldMainHud.OnPublishAction += StartPublishFlow; |
| 26 | 32 | | HUDController.i.builderInWorldMainHud.OnConfirmPublishAction += StartPublishScene; |
| | 33 | | } |
| | 34 | |
|
| 30 | 35 | | builderInWorldBridge = context.sceneReferences.builderInWorldBridge; |
| | 36 | |
|
| 30 | 37 | | if (builderInWorldBridge != null) |
| 26 | 38 | | builderInWorldBridge.OnPublishEnd += PublishEnd; |
| 30 | 39 | | } |
| | 40 | |
|
| | 41 | | public override void Update() |
| | 42 | | { |
| 2 | 43 | | base.Update(); |
| 2 | 44 | | if (checkerSceneLimitsOptimizationCounter >= FRAMES_BEETWEN_UPDATES) |
| | 45 | | { |
| 0 | 46 | | checkerSceneLimitsOptimizationCounter = 0; |
| 0 | 47 | | CheckPublishConditions(); |
| 0 | 48 | | } |
| | 49 | | else |
| | 50 | | { |
| 2 | 51 | | checkerSceneLimitsOptimizationCounter++; |
| | 52 | | } |
| 2 | 53 | | } |
| | 54 | |
|
| | 55 | | public override void Dispose() |
| | 56 | | { |
| 31 | 57 | | base.Dispose(); |
| | 58 | |
|
| 31 | 59 | | if (HUDController.i.builderInWorldMainHud != null) |
| | 60 | | { |
| 27 | 61 | | HUDController.i.builderInWorldMainHud.OnPublishAction -= StartPublishFlow; |
| 27 | 62 | | HUDController.i.builderInWorldMainHud.OnConfirmPublishAction -= StartPublishScene; |
| | 63 | | } |
| 31 | 64 | | if (builderInWorldBridge != null) |
| 27 | 65 | | builderInWorldBridge.OnPublishEnd -= PublishEnd; |
| 31 | 66 | | } |
| | 67 | |
|
| | 68 | | public bool CanPublish() |
| | 69 | | { |
| 3 | 70 | | if (creatorController.IsAnyErrorOnEntities()) |
| 0 | 71 | | return false; |
| | 72 | |
|
| 3 | 73 | | if (!sceneToEdit.metricsController.IsInsideTheLimits()) |
| 1 | 74 | | return false; |
| | 75 | |
|
| 2 | 76 | | if (!entityHandler.AreAllEntitiesInsideBoundaries()) |
| 1 | 77 | | return false; |
| | 78 | |
|
| 1 | 79 | | return true; |
| | 80 | | } |
| | 81 | |
|
| | 82 | | /// <summary> |
| | 83 | | /// This function will check if you are able to publish the scene to the content server. If no error are present, an |
| | 84 | | /// </summary> |
| | 85 | | /// <returns>A message the with the reason telling you why you can't publish. If you can publish an empty message wi |
| | 86 | | public string CheckPublishConditions() |
| | 87 | | { |
| 1 | 88 | | string feedbackMessage = ""; |
| 1 | 89 | | if (creatorController.IsAnyErrorOnEntities()) |
| | 90 | | { |
| 0 | 91 | | feedbackMessage = FEEDBACK_MESSAGE_ENTITY_ERROR; |
| 0 | 92 | | } |
| 1 | 93 | | else if (!entityHandler.AreAllEntitiesInsideBoundaries()) |
| | 94 | | { |
| 0 | 95 | | feedbackMessage = FEEDBACK_MESSAGE_OUTSIDE_BOUNDARIES; |
| 0 | 96 | | } |
| 1 | 97 | | else if (!sceneToEdit.metricsController.IsInsideTheLimits()) |
| | 98 | | { |
| 0 | 99 | | feedbackMessage = FEEDBACK_MESSAGE_TOO_MANY_ENTITIES; |
| | 100 | | } |
| | 101 | |
|
| 1 | 102 | | if (HUDController.i.builderInWorldMainHud != null) |
| 0 | 103 | | HUDController.i.builderInWorldMainHud.SetPublishBtnAvailability(CanPublish(), feedbackMessage); |
| | 104 | |
|
| 1 | 105 | | return feedbackMessage; |
| | 106 | | } |
| | 107 | |
|
| | 108 | | private void StartPublishFlow() |
| | 109 | | { |
| 0 | 110 | | if (!CanPublish()) |
| 0 | 111 | | return; |
| | 112 | |
|
| 0 | 113 | | HUDController.i.builderInWorldMainHud.PublishStart(); |
| 0 | 114 | | } |
| | 115 | |
|
| | 116 | | private void StartPublishScene(string sceneName, string sceneDescription, string sceneScreenshot) |
| | 117 | | { |
| 0 | 118 | | startPublishingTimestamp = Time.realtimeSinceStartup; |
| 0 | 119 | | BIWAnalytics.StartScenePublish(sceneToEdit.metricsController.GetModel()); |
| 0 | 120 | | builderInWorldBridge.PublishScene(sceneToEdit, sceneName, sceneDescription, sceneScreenshot); |
| 0 | 121 | | } |
| | 122 | |
|
| | 123 | | private void PublishEnd(bool isOk, string message) |
| | 124 | | { |
| 0 | 125 | | if (HUDController.i.builderInWorldMainHud != null) |
| 0 | 126 | | HUDController.i.builderInWorldMainHud.PublishEnd(isOk, message); |
| 0 | 127 | | string successString = isOk ? "Success" : message; |
| 0 | 128 | | BIWAnalytics.EndScenePublish(sceneToEdit.metricsController.GetModel(), successString, Time.realtimeSinceStartup |
| 0 | 129 | | } |
| | 130 | | } |