ClearAllNavMeshes() private method

private ClearAllNavMeshes ( ) : void
return void
Example #1
0
        void SaveCombinedAsset()
        {
            // Create an asset describing all surfaces.
            var targetPath        = GetAndEnsureTargetPath(this);
            var combinedAssetData = new List <NavMeshData>();

            // Collect valid navmesh data.
            foreach (var s in NavMeshSurface.activeSurfaces)
            {
                if (s.bakedNavMeshData != null)
                {
                    combinedAssetData.Add(s.bakedNavMeshData);
                }
            }

            // Clear the legacy navmesh data reference on the scene
            if (NavMeshEditorHelpers.CurrentNavMeshAssetFormat() == NavMeshEditorHelpers.NavMeshDataFormat.Single)
            {
                NavMeshBuilder.ClearAllNavMeshes();
            }

            // Store baked navmesh data in one asset.
            var combinedAssetPath = Path.Combine(targetPath, "NavMesh.asset");

            if (combinedAssetData.Count == 0)
            {
                AssetDatabase.DeleteAsset(combinedAssetPath);
            }
            else
            {
                if (!File.Exists(combinedAssetPath))
                {
                    // NOTE: Creates empty dummy NavMeshData to represent the main asset,
                    // this is done in order to show all the built meshes equally in the list.
                    var dummy = new NavMeshData();
                    AssetDatabase.CreateAsset(dummy, combinedAssetPath);
                }

                // Only add the data that has not been added already.
                // Call to NavMeshSurface.Clear () also deletes the data from the asset.
                foreach (var data in combinedAssetData)
                {
                    if (!AssetDatabase.Contains(data))
                    {
                        AssetDatabase.AddObjectToAsset(data, combinedAssetPath);
                    }
                }
                AssetDatabase.SaveAssets();
                AssetDatabase.ImportAsset(combinedAssetPath);
            }
        }
Example #2
0
        static void BakeButtons()
        {
            const float kButtonWidth = 95;

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            bool wasEnabled = GUI.enabled;

            GUI.enabled &= !Application.isPlaying;
            if (GUILayout.Button("Clear", GUILayout.Width(kButtonWidth)))
            {
                EditorNavMeshBuilder.ClearAllNavMeshes();
            }
            GUI.enabled = wasEnabled;

            if (EditorNavMeshBuilder.isRunning)
            {
                if (GUILayout.Button("Cancel", GUILayout.Width(kButtonWidth)))
                {
                    EditorNavMeshBuilder.Cancel();
                }
            }
            else
            {
                wasEnabled   = GUI.enabled;
                GUI.enabled &= !Application.isPlaying;
                if (GUILayout.Button("Bake", GUILayout.Width(kButtonWidth)))
                {
                    EditorNavMeshBuilder.BuildNavMeshAsync();
                }
                GUI.enabled = wasEnabled;
            }

            GUILayout.EndHorizontal();

            EditorGUILayout.Space();
        }