| | 1 | | using System; |
| | 2 | | using DCL; |
| | 3 | | using DCL.Builder; |
| | 4 | | using UnityEngine; |
| | 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 Initialize(IContext context) |
| | 23 | | { |
| 4 | 24 | | base.Initialize(context); |
| | 25 | |
|
| 4 | 26 | | entityHandler = context.editorContext.entityHandler; |
| 4 | 27 | | creatorController = context.editorContext.creatorController; |
| | 28 | |
|
| 4 | 29 | | if (context.editorContext.editorHUD != null) |
| | 30 | | { |
| 4 | 31 | | context.editorContext.editorHUD.OnPublishAction += StartPublishFlow; |
| 4 | 32 | | context.editorContext.editorHUD.OnConfirmPublishAction += StartPublishScene; |
| | 33 | | } |
| | 34 | |
|
| 4 | 35 | | builderInWorldBridge = context.sceneReferences.biwBridgeGameObject.GetComponent<BuilderInWorldBridge>(); |
| | 36 | |
|
| 4 | 37 | | if (builderInWorldBridge != null) |
| 4 | 38 | | builderInWorldBridge.OnPublishEnd += PublishEnd; |
| 4 | 39 | | } |
| | 40 | |
|
| | 41 | | public override void Update() |
| | 42 | | { |
| 0 | 43 | | base.Update(); |
| 0 | 44 | | if (checkerSceneLimitsOptimizationCounter >= FRAMES_BEETWEN_UPDATES) |
| | 45 | | { |
| 0 | 46 | | checkerSceneLimitsOptimizationCounter = 0; |
| 0 | 47 | | CheckPublishConditions(); |
| 0 | 48 | | } |
| | 49 | | else |
| | 50 | | { |
| 0 | 51 | | checkerSceneLimitsOptimizationCounter++; |
| | 52 | | } |
| 0 | 53 | | } |
| | 54 | |
|
| | 55 | | public override void Dispose() |
| | 56 | | { |
| 4 | 57 | | base.Dispose(); |
| | 58 | |
|
| 4 | 59 | | if ( context.editorContext.editorHUD != null) |
| | 60 | | { |
| 4 | 61 | | context.editorContext.editorHUD.OnPublishAction -= StartPublishFlow; |
| 4 | 62 | | context.editorContext.editorHUD.OnConfirmPublishAction -= StartPublishScene; |
| | 63 | | } |
| | 64 | |
|
| 4 | 65 | | if (builderInWorldBridge != null) |
| 4 | 66 | | builderInWorldBridge.OnPublishEnd -= PublishEnd; |
| 4 | 67 | | } |
| | 68 | |
|
| | 69 | | public bool CanPublish() |
| | 70 | | { |
| 4 | 71 | | if (creatorController.IsAnyErrorOnEntities()) |
| 0 | 72 | | return false; |
| | 73 | |
|
| 4 | 74 | | if (!sceneToEdit.metricsCounter.IsInsideTheLimits()) |
| 1 | 75 | | return false; |
| | 76 | |
|
| 3 | 77 | | if (!entityHandler.AreAllEntitiesInsideBoundaries()) |
| 1 | 78 | | return false; |
| | 79 | |
|
| 2 | 80 | | return true; |
| | 81 | | } |
| | 82 | |
|
| | 83 | | /// <summary> |
| | 84 | | /// This function will check if you are able to publish the scene to the content server. If no error are present, an |
| | 85 | | /// </summary> |
| | 86 | | /// <returns>A message the with the reason telling you why you can't publish. If you can publish an empty message wi |
| | 87 | | public string CheckPublishConditions() |
| | 88 | | { |
| 1 | 89 | | string feedbackMessage = ""; |
| 1 | 90 | | if (creatorController.IsAnyErrorOnEntities()) |
| | 91 | | { |
| 0 | 92 | | feedbackMessage = FEEDBACK_MESSAGE_ENTITY_ERROR; |
| 0 | 93 | | } |
| 1 | 94 | | else if (!entityHandler.AreAllEntitiesInsideBoundaries()) |
| | 95 | | { |
| 0 | 96 | | feedbackMessage = FEEDBACK_MESSAGE_OUTSIDE_BOUNDARIES; |
| 0 | 97 | | } |
| 1 | 98 | | else if (!sceneToEdit.metricsCounter.IsInsideTheLimits()) |
| | 99 | | { |
| 0 | 100 | | feedbackMessage = FEEDBACK_MESSAGE_TOO_MANY_ENTITIES; |
| | 101 | | } |
| | 102 | |
|
| 1 | 103 | | if ( context.editorContext.editorHUD != null) |
| 1 | 104 | | context.editorContext.editorHUD.SetPublishBtnAvailability(CanPublish(), feedbackMessage); |
| | 105 | |
|
| 1 | 106 | | return feedbackMessage; |
| | 107 | | } |
| | 108 | |
|
| | 109 | | private void StartPublishFlow() |
| | 110 | | { |
| 0 | 111 | | if (!CanPublish()) |
| 0 | 112 | | return; |
| | 113 | |
|
| 0 | 114 | | if (DataStore.i.builderInWorld.isDevBuild.Get()) |
| | 115 | | { |
| | 116 | | //TODO: Implement project publish |
| | 117 | | } |
| | 118 | | else |
| | 119 | | { |
| 0 | 120 | | context.editorContext.editorHUD.PublishStart(); |
| | 121 | | } |
| 0 | 122 | | } |
| | 123 | |
|
| | 124 | | private void StartPublishScene(string sceneName, string sceneDescription, string sceneScreenshot) |
| | 125 | | { |
| 0 | 126 | | startPublishingTimestamp = Time.realtimeSinceStartup; |
| 0 | 127 | | BIWAnalytics.StartScenePublish(sceneToEdit.metricsCounter.currentCount); |
| 0 | 128 | | builderInWorldBridge.PublishScene(sceneToEdit, sceneName, sceneDescription, sceneScreenshot); |
| 0 | 129 | | } |
| | 130 | |
|
| | 131 | | private void PublishEnd(bool isOk, string message) |
| | 132 | | { |
| 0 | 133 | | if ( context.editorContext.editorHUD != null) |
| 0 | 134 | | context.editorContext.editorHUD.PublishEnd(isOk, message); |
| 0 | 135 | | string successString = isOk ? "Success" : message; |
| 0 | 136 | | BIWAnalytics.EndScenePublish(sceneToEdit.metricsCounter.currentCount, successString, Time.realtimeSinceStartup - |
| 0 | 137 | | } |
| | 138 | | } |