//saving only for editor cause it saved in scriptable object //for existed scenes only //if you wanna save navmesh in save file then write how you store properties and get serialized navmesh using Serialize/Deserialize functions public static void SaveCurrentSceneData() { Init(); SceneNavmeshData data = _sceneInstance.sceneNavmeshData; if (data == null) { string path = EditorUtility.SaveFilePanel("Save NavMesh", "Assets", SceneManager.GetActiveScene().name + ".asset", "asset"); if (path == "") { return; } path = FileUtil.GetProjectRelativePath(path); data = ScriptableObject.CreateInstance <SceneNavmeshData>(); AssetDatabase.CreateAsset(data, path); AssetDatabase.SaveAssets(); Undo.RecordObject(_sceneInstance, "Set SceneNavmeshData to NavMesh scene instance"); _sceneInstance.sceneNavmeshData = data; EditorUtility.SetDirty(_sceneInstance); } HashSet <AgentProperties> allProperties = new HashSet <AgentProperties>(); foreach (var key in _chunkData.Keys) { allProperties.Add(key.properties); } List <AgentProperties> properties = new List <AgentProperties>(); List <SerializedNavmesh> navmesh = new List <SerializedNavmesh>(); foreach (var p in allProperties) { properties.Add(p); navmesh.Add(Serialize(p)); } data.properties = properties; data.navmesh = navmesh; EditorUtility.SetDirty(data); }
public static void ClearCurrentData() { Init(); SceneNavmeshData data = _sceneInstance.sceneNavmeshData; if (data == null) { Debug.LogWarning("data == null"); return; } if (data.properties != null) { if (data.properties.Count > 0) { StringBuilder sb = new StringBuilder(); sb.AppendLine("Cleared:"); for (int i = 0; i < data.properties.Count; i++) { sb.AppendFormat("properties: {0}, graphs: {1}, cells: {2}", data.properties[i].name, data.navmesh[i].serializedGraphs.Count, data.navmesh[i].cellCount); } Debug.Log(sb); } else { Debug.Log("nothing to clear"); } } if (data.properties != null) { data.properties.Clear(); } if (data.navmesh != null) { data.navmesh.Clear(); } EditorUtility.SetDirty(data); }