public GameplayAreaDataControl(MapSceneDataControl mapSceneDataControl)
 {
     this.mapSceneDataControl = mapSceneDataControl;
     this.mapScene            = mapSceneDataControl.getContent() as MapScene;
     this.gameplayArea        = new GameplayArea
     {
         UsesGameplayArea   = mapScene.UsesGameplayArea,
         BoundingBox        = mapScene.GameplayArea,
         TileMetaIdentifier = mapScene.TileMetaIdentifier
     };
 }
Ejemplo n.º 2
0
        public void StoreTiles(MapSceneDataControl mapSceneDataControl, bool displayProgressBar, System.Action <bool> callback)
        {
            StartProcess(mapSceneDataControl);

            if (displayProgressBar)
            {
                EditorUtility.DisplayProgressBar("Geo.TileManager.Progress.Title".Traslate(),
                                                 "Geo.TileManager.Calculating".Traslate(), 0);
            }

            var allAreas     = GetAllAreasExcept(mapSceneDataControl);
            var mapScene     = mapSceneDataControl.getContent() as MapScene;
            var previousArea = new AreaMeta(mapScene);
            var newArea      = new AreaMeta(mapSceneDataControl);
            var current      = new StorageProcess();

            storageProcesses[mapSceneDataControl] = current;

            // Get the tile metas to remove or to download if they exist
            current.toRemoveMeta   = TileProvider.Instance.GetTileMeta(mapScene.TileMetaIdentifier);
            current.toDownloadMeta = TileProvider.Instance.GetTileMeta(mapSceneDataControl.GameplayArea.TileMetaIdentifier);

            // We have to remove if there is gameplayArea based on the previous area and we must substract the new area if it's used
            current.toRemoveTiles = GetNonCollidingStorableTiles(mapScene.UsesGameplayArea, allAreas, previousArea,
                                                                 mapSceneDataControl.GameplayArea.UsesGameplayArea, newArea, current.toRemoveMeta);

            // We have to download if there is gameplayArea based on the new area and we must substract the old area if it's used
            current.toDownloadTiles = GetNonCollidingStorableTiles(mapSceneDataControl.GameplayArea.UsesGameplayArea, allAreas,
                                                                   newArea, mapScene.UsesGameplayArea, previousArea, current.toDownloadMeta);

            // In case any of them is null it means that we have no storer to use for any of the tiles
            if (current.toRemoveTiles == null || current.toDownloadTiles == null)
            {
                FinishProcess(mapSceneDataControl);
                callback(false);
                return;
            }

            RemoveAndDownloadTiles(mapSceneDataControl, new ProgressCallback(current.toRemoveTiles.Count + current.toDownloadTiles.Count * 2,
                                                                             (fase, progress, result) =>
            {
                bool cancel = false;
                if (displayProgressBar)
                {
                    if (fase == 0)
                    {
                        EditorUtility.DisplayProgressBar("Geo.TileManager.Progress.Title".Traslate(),
                                                         "Geo.TileManager.Removing".Traslate(), progress.Progress);
                    }
                    else if (fase == 1)
                    {
                        cancel = EditorUtility.DisplayCancelableProgressBar("Geo.TileManager.Progress.Title".Traslate(),
                                                                            "Geo.TileManager.Downloading".Traslate(), progress.Progress);
                    }
                    else if (fase == 2)
                    {
                        cancel = EditorUtility.DisplayCancelableProgressBar("Geo.TileManager.Progress.Title".Traslate(),
                                                                            "Geo.TileManager.Storing".Traslate(), progress.Progress);
                    }
                }

                if ((fase != 0 && !result) || cancel)
                {
                    FinishProcess(mapSceneDataControl);
                    callback(false);
                }

                if (progress.Progress >= 1f)
                {
                    FinishProcess(mapSceneDataControl);
                    callback(true);
                }
            }).Update);
        }