public IEnumerator DisposeSceneGroup(SceneGroup group) { string[] sceneNames = GetSceneNames(group); numberOfHandledScene = 0; numberOfScenesToBeHandle = sceneNames.Length; loadingScenes = new Dictionary <AsyncOperation, string>(); loadedGroup.Remove(group); foreach (var name in sceneNames) { var asyncOperation = UnityEngine.SceneManagement.SceneManager.UnloadSceneAsync(name); loadingScenes.Add(asyncOperation, name); asyncOperation.completed += SceneHandleFinished; if (activeScenes.ContainsKey(name)) { activeScenes.Remove(name); } } while (numberOfHandledScene != numberOfScenesToBeHandle) { yield return(null); } }
private SceneGroup OnSceneGroupData(SceneGroup.Type type, string name, SceneGroup parent, ref SceneGroup leaf) { SceneGroup group = null; if (SceneGroup.Test(type, groupOptions)) { if (parent.childs.ContainsKey(name)) { group = parent.childs[name]; } // No group found for this idenfier if (group == null) { group = new SceneGroup(type, name); parent.childs[name] = group; } // Update the leaf if (SceneGroup.IsLeaf(type, groupOptions)) { leaf = group; } } else { group = parent; } return(group); }
private void SceneGroupToggle(MapzenMap mapzenMap, SceneGroup.Type type) { bool isSet = SceneGroup.Test(type, mapzenMap.GroupOptions); isSet = EditorGUILayout.Toggle(type.ToString(), isSet); mapzenMap.GroupOptions = isSet ? mapzenMap.GroupOptions | type : mapzenMap.GroupOptions & ~type; }
public void Load(SceneGroup group) { _sceneGroup = group; _loadedCount = 0; // Load Loading Scene var op = SceneManager.LoadSceneAsync(_loadingSceneName, LoadSceneMode.Single); CoroutineManager.Start(LoadingScene(op)); }
public void ExportActiveScenes() { allComponentsNotWritten.Clear(); SceneGroup group = null; if (activeGroup >= 0 && activeGroup < config.groups.Count) { group = config.groups[activeGroup]; } if (group == null) { Debug.LogError("Export failed: Active group " + activeGroup + " does not exist."); return; } progress.SetItemsToDo(group.scenes.Count); progress.Info("************************ START LEVEL EXPORT FOR GROUP " + group.name + " ****************************", true); // Find all Unity scenes starting from the base path and record the path to the scene Dictionary <string, string> scenePaths = new Dictionary <string, string>(); foreach (string file in Directory.GetFiles(Path.Combine(Application.dataPath, group.baseSceneDir), "*.unity", SearchOption.AllDirectories)) { scenePaths[Path.GetFileNameWithoutExtension(file)] = file; } foreach (string name in group.scenes) { if (!scenePaths.ContainsKey(name)) { Debug.LogError("Could not find scene " + name); continue; } if (EditorApplication.OpenScene(scenePaths[name])) { ExportOpenScene(); } else { Debug.LogError("Could not open scene " + scenePaths[name]); } } string notWritten = ""; foreach (string item in allComponentsNotWritten) { notWritten += item + ", "; } Debug.Log(notWritten); }
public void LoadAndActivateSceneGroup(SceneGroup sceneGroup, OnDone onDone) { Assert.IsNotNull(sceneGroup); #if SCENEGROUPLOADER_LOGGING Debug.LogFormat("LoadAndActivateSceneGroup: load and activate sceneGroup {0}", sceneGroup.name); #endif SceneGroupHandle sceneGroupHandle = asyncSceneGroupLoader.LoadSceneGroupAsync(sceneGroup); inProgressSceneGroups.Add(new InProgressSceneGroup(sceneGroupHandle, () => { LoadAndActivateSceneGroupDone(sceneGroupHandle, onDone); })); }
public void LoadSceneGroup(SceneGroup sceneGroup, OnDone onDone) { Assert.IsNotNull(sceneGroup); #if SCENEGROUPLOADER_LOGGING Debug.LogFormat("LoadSceneGroup: load sceneGroup {0}", sceneGroup.name); #endif Assert.IsNull(inProgressSceneGroup, "Scene group load is not allowed when another async operation is in progress"); SceneGroupHandle sceneGroupHandle = asyncSceneGroupLoader.LoadSceneGroupAsync(sceneGroup); loadedButNotActivatedSceneGroups.Enqueue(sceneGroupHandle); inProgressSceneGroup = new InProgressSceneGroup(sceneGroupHandle, () => { LoadSceneGroupDone(sceneGroupHandle, onDone); }); }
public IEnumerator SwitchSceneGroup(SceneGroup currentGroup, SceneGroup nextGroup, string openSceneName) { if (!loadedGroup.Contains(nextGroup)) { yield return(LoadSceneGroup(nextGroup)); } OpenScene(openSceneName); if (loadedGroup.Contains(currentGroup)) { yield return(DisposeSceneGroup(currentGroup)); } }
public string[] GetSceneNames(SceneGroup group) { switch (group) { case SceneGroup.HomeGroup: return(SceneName.HOME_GROUP); case SceneGroup.TitleGroup: return(SceneName.TITLE_GROUP); default: return(null); } }
public void DownloadTiles() { TileBounds bounds = new TileBounds(Area); tasks.Clear(); nTasksForArea = 0; regionMap = new SceneGroup(SceneGroup.Type.None, RegionName); foreach (var tileAddress in bounds.TileAddressRange) { nTasksForArea++; } foreach (var tileAddress in bounds.TileAddressRange) { var wrappedTileAddress = tileAddress.Wrapped(); var uri = new Uri(string.Format("https://tile.mapzen.com/mapzen/vector/v1/all/{0}/{1}/{2}.mvt?api_key={3}", wrappedTileAddress.z, wrappedTileAddress.x, wrappedTileAddress.y, ApiKey)); Debug.Log("URL request " + uri.AbsoluteUri); IO.IORequestCallback onTileFetched = (response) => { if (response.hasError()) { Debug.Log("TileIO Error: " + response.error); return; } if (response.data.Length == 0) { Debug.Log("Empty Response"); return; } float offsetX = (tileAddress.x - bounds.min.x); float offsetY = (-tileAddress.y + bounds.min.y); TileTask task = new TileTask(tileAddress, groupOptions, response.data, offsetX, offsetY, regionScaleRatio); task.Start(featureStyling, regionMap); OnTaskReady(task); }; // Starts the HTTP request StartCoroutine(tileIO.FetchNetworkData(uri, onTileFetched)); } }
public void LoadSceneGroup(SceneGroup sceneGroup, SceneGroupLoader.OnDone onDone) { SceneGroupLoader.LoadSceneGroup(sceneGroup, onDone); }
/// <summary> /// Visits the scene group root recursively and generate a scene graph hierarchy in the Unity scene /// </summary> /// <param name="group">The scene group to visit.</param> /// <param name="parent">The parent transform of the generated game object for the current scene group.</param> public static void Generate(SceneGroup group, Transform parent, GameObjectOptions options) { if (group.meshData.Meshes.Count == 0 && group.childs.Count == 0) { return; } if (group.childs.Count > 0) { var gameObject = new GameObject(group.ToString()); gameObject.isStatic = options.IsStatic; if (parent != null) { gameObject.transform.parent = parent; } foreach (var child in group.childs) { Generate(child.Value, gameObject.transform, options); } } else { group.meshData.FlipIndices(); if (group.meshData.Meshes.Count > 1) { var gameObject = new GameObject(group.ToString()); gameObject.transform.parent = parent; parent = gameObject.transform; gameObject.isStatic = options.IsStatic; } // Create one game object per mesh object 'bucket', each bucket is ensured to // have less that 65535 vertices (valid under Unity mesh max vertex count). for (int i = 0; i < group.meshData.Meshes.Count; ++i) { var meshBucket = group.meshData.Meshes[i]; var gameObject = new GameObject(group.ToString()); gameObject.isStatic = options.IsStatic; if (group.meshData.Meshes.Count > 1) { gameObject.name += "_Part" + i; } gameObject.transform.parent = parent; var mesh = new Mesh(); mesh.SetVertices(meshBucket.Vertices); mesh.subMeshCount = meshBucket.Submeshes.Count; for (int s = 0; s < meshBucket.Submeshes.Count; s++) { mesh.SetTriangles(meshBucket.Submeshes[s].Indices, s); } mesh.RecalculateNormals(); if (options.IsStatic) { #ifdef UNITY_EDITOR // Generate default uvs for this mesh Unwrapping.GenerateSecondaryUVSet(mesh); #endif } // Associate the mesh filter and mesh renderer components with this game object var materials = meshBucket.Submeshes.Select(s => s.Material).ToArray(); var meshFilterComponent = gameObject.AddComponent <MeshFilter>(); var meshRendererComponent = gameObject.AddComponent <MeshRenderer>(); meshRendererComponent.materials = materials; meshFilterComponent.mesh = mesh; if (options.GeneratePhysicMeshCollider) { var meshColliderComponent = gameObject.AddComponent <MeshCollider>(); meshColliderComponent.material = options.PhysicMaterial; meshColliderComponent.sharedMesh = mesh; } } } }
public bool IsGroupLoaded(SceneGroup group) { return(loadedGroup.Contains(group)); }
public SceneGroupInfo(SceneGroup sceneGroup, IntMinMaxRange sceneInstanceCount, float weight) { this.sceneGroup = sceneGroup; this.sceneInstanceCount = sceneInstanceCount; this.weight = weight; }
public void LoadAndActivateSceneGroup(SceneGroup sceneGroup, SceneGroupLoader.OnDone onDone) { SceneGroupLoader.LoadAndActivateSceneGroup(sceneGroup, onDone); }
public void Start(List <FeatureStyle> featureStyling, SceneGroup root) { // Parse the GeoJSON // var tileData = new GeoJsonTile(address, response); var tileData = new MvtTile(address, response); // The leaf currently used (will hold the mesh data for the currently matched group) SceneGroup leaf = root; var tileGroup = OnSceneGroupData(SceneGroup.Type.Tile, address.ToString(), root, ref leaf); foreach (var style in featureStyling) { // TODO: group by style? foreach (var filterStyle in style.FilterStyles) { var filterGroup = OnSceneGroupData(SceneGroup.Type.Filter, filterStyle.Name, tileGroup, ref leaf); foreach (var layer in tileData.FeatureCollections) { var layerGroup = OnSceneGroupData(SceneGroup.Type.Layer, layer.Name, filterGroup, ref leaf); foreach (var feature in filterStyle.Filter.Filter(layer)) { var layerStyle = filterStyle.LayerStyles.Find(ls => ls.LayerName == layer.Name); string featureName = ""; object identifier; if (feature.TryGetProperty("id", out identifier)) { featureName += identifier.ToString(); } OnSceneGroupData(SceneGroup.Type.Feature, featureName, layerGroup, ref leaf); if (feature.Type == GeometryType.Polygon || feature.Type == GeometryType.MultiPolygon) { var polygonOptions = layerStyle.GetPolygonOptions(feature, inverseTileScale); if (polygonOptions.Enabled) { var builder = new PolygonBuilder(leaf.meshData, polygonOptions, transform); feature.HandleGeometry(builder); } } if (feature.Type == GeometryType.LineString || feature.Type == GeometryType.MultiLineString) { var polylineOptions = layerStyle.GetPolylineOptions(feature, inverseTileScale); if (polylineOptions.Enabled) { var builder = new PolylineBuilder(leaf.meshData, polylineOptions, transform); feature.HandleGeometry(builder); } } } } } } ready = true; }