public bool unloadOnDemandAudioForSoundMarkerIfAllowed(SoundMarker marker, SoundFile soundFile) { if (!onDemandIsActive) { return false; } Debug.LogWarning("ON-DEMAND should NOT be Loaded: " + soundFile.filename, this); // FIRST - make sure no other SoundMarkers are using the SoundFile IEnumerable<SoundMarker> otherMarkersUsingSoundFile = layoutManager.SoundMarkersUsingSoundFileID( soundFile.filename, hotspotIDToExclude: marker.hotspot.id); foreach (SoundMarker otherMarker in otherMarkersUsingSoundFile) { if (otherMarker.onDemandAudioShouldBeLoaded) { return false; } } // UNLOAD Synced Marker friends if none of them need to be loaded IEnumerable<SoundMarker> syncedMarkers = layoutManager.layout.getSynchronisedMarkers(marker.hotspot.id); Debug.LogError("unloadOnDemandAudioForSoundMarkerIsPossible: " + marker.gameObject.name); if (syncedMarkers == null || !atLeastOneSyncedMarkerClipShouldBeLoaded(syncedMarkers)) { Debug.LogError (" UNLOAD ON DEMAND!"); // We should UNLOAD this AudioClip... layoutManager.UnloadSoundMarkerAndSyncedClips(marker, syncedMarkers); canvasControl.editSoundOverlay.refreshDebugText(); return true; } return false; }
private void performMarkerProximityChecks() { // TODO: foreach (SoundMarker sm in MainController.soundMarkers) { // Sounds that have an infinte range (indicated by a negative maxDistance) can be ignored if (sm.hotspot.hasInfiniteMaxDistance) { continue; } SoundFile sf; if (!_layoutManager.soundDictionary.TryGetValue(sm.hotspot.soundID, out sf)) { continue; } if (sf.isDefaultSoundFile) { continue; } // Skip the default soundFile float distToMaxRadius = Vector2.Distance( new Vector2(_camTransform.position.x, _camTransform.position.z), new Vector2(sm.transform.position.x, sm.transform.position.z) ) - sm.soundMaxDist; if (sf.loadState == LoadState.Success && distToMaxRadius > _unloadDistance) { IEnumerable <SoundMarker> syncedMarkers = _layoutManager.layout.getSynchronisedMarkers(sm.hotspot.id); if (!atLeastOneSyncedMarkerShouldBeLoaded(syncedMarkers)) { // We should UNLOAD this AudioClip... _layoutManager.UnloadSoundMarkerAndSyncedClips(sm, syncedMarkers); } } if (sf.loadState != LoadState.Success && distToMaxRadius < _loadDistance) { // We should LOAD this AudioClip... _layoutManager.LoadSoundMarkerAndSyncedClips(sm, completion: (HashSet <SoundMarker> loadedMarkers) => { // TODO: Should we stop playing and start playing all clips? foreach (var loadedMarker in loadedMarkers) { loadedMarker.PlayAudioFromBeginning(ignoreTrigger: true); } }); } } }