예제 #1
0
        protected internal override void OnSystemRemove()
        {
            // Destroy all the SoundInstance created by the processor before closing.
            foreach (var soundInstance in ComponentDataValues.SelectMany(x => x.AudioEmitterComponent.SoundToController.Values))
            {
                soundInstance.DestroyAllSoundInstances();
            }

            audioSystem.Listeners.CollectionChanged -= OnListenerCollectionChanged;
        }
예제 #2
0
        private void DynamicNavigationMeshSystemOnNavigationMeshUpdatedUpdated(object sender, NavigationMeshUpdatedEventArgs eventArgs)
        {
            var newNavigationMesh = eventArgs.BuildResult.NavigationMesh;
            NavigationMeshData data;

            if (eventArgs.OldNavigationMesh != null && loadedNavigationMeshes.TryGetValue(eventArgs.OldNavigationMesh, out data))
            {
                // Move to new navigation mesh
                loadedNavigationMeshes.Remove(eventArgs.OldNavigationMesh);
                loadedNavigationMeshes.Add(newNavigationMesh, data);

                data.NavigationMesh = newNavigationMesh;

                // Replace tiles in recast navigation mesh for all loaded groups
                var updatedLayers = eventArgs.BuildResult.UpdatedLayers.ToDictionary(x => x.GroupId);
                var oldGroupKeys  = data.LoadedGroups.Keys.ToList();
                foreach (var oldGroupKey in oldGroupKeys)
                {
                    var loadedGroup = data.LoadedGroups[oldGroupKey];

                    // See if this layer was updated
                    NavigationMeshLayerUpdateInfo layerUpdateInfo;
                    if (!updatedLayers.TryGetValue(oldGroupKey, out layerUpdateInfo))
                    {
                        continue;
                    }

                    // Check if the new navigation mesh contains this layer
                    //  if it does not, that means it was removed completely and we
                    //  will remove all the loaded tiles in the loop below
                    NavigationMeshLayer newLayer = null;
                    newNavigationMesh.Layers.TryGetValue(oldGroupKey, out newLayer);

                    foreach (var updatedTileCoord in layerUpdateInfo.UpdatedTiles)
                    {
                        NavigationMeshTile newTile = null;
                        if (newLayer != null)
                        {
                            if (!newLayer.Tiles.TryGetValue(updatedTileCoord, out newTile))
                            {
                                continue;
                            }
                        }

                        // Either add the tile if it is contained in the new navigation mesh or
                        //  try to remove it if it does not
                        if (newTile != null)
                        {
                            loadedGroup.RecastNavigationMesh.AddOrReplaceTile(newTile.Data);
                        }
                        else
                        {
                            loadedGroup.RecastNavigationMesh.RemoveTile(updatedTileCoord);
                        }
                    }
                }
            }

            // Update loaded navigation meshes for components that are useing it,
            //  in case a group was added
            var componentsToUpdate = ComponentDataValues.Where(x => x.Component.NavigationMesh == null).ToArray();

            foreach (var component in componentsToUpdate)
            {
                UpdateNavigationMesh(component);
            }
        }