// public void DeleteAndDestroySoundMarker(SoundMarker soundObj, bool removeFromList = true, bool eraseHotspotData = true) { // if (soundObj == null) { return; } // // TODO: Implement object pooling // if (removeFromList) { // soundObj.markerDelegate = null; // soundMarkers.Remove(soundObj); // } // if (eraseHotspotData) layoutManager.EraseHotspot(soundObj.hotspot); // if (soundObj.transform.parent != null) { // Destroy(soundObj.transform.parent.gameObject); // } else { // Destroy(soundObj); // } // } // private void UnloadCurrentSoundMarkers() { // foreach (SoundMarker s in soundMarkers) { // DeleteAndDestroySoundMarker(s, removeFromList: false, eraseHotspotData: false); // } // soundMarkers.Clear(); // } /// <summary> /// Place the next sound marker /// </summary> private void PlaceSoundTapped() { // Place a new sound with default config SoundMarker soundMarker = _soundMarkerPooling.GetSoundMarker(); // Create and position the prefab. if (canvasControl.placeSoundsOverlay.placeSoundsOnCursor && cursorTransform != null) { SoundMarker.SetupUnanchoredMarker(soundMarker, cursorTransform, anchorWrapperTransform); // soundMarker = SoundMarker.CreatePrefab(cursorTransform, soundMarkerPrefab, anchorWrapperTransform); } else { SoundMarker.SetupUnanchoredMarker(soundMarker, firstPersonCamera.transform, anchorWrapperTransform); // soundMarker = SoundMarker.CreatePrefab(firstPersonCamera.transform, soundMarkerPrefab, anchorWrapperTransform); } soundMarker.markerDelegate = this; Anchor anchorParent = soundMarker.transform.parent.GetComponent<Anchor>(); Vector3 anchorPos = anchorParent.transform.localPosition; // Create a new hotspot for the json file and save it. soundMarkers.Add(soundMarker); Hotspot h = layoutManager.AddNewHotspot( localPos: anchorPos, rotation: Vector3.zero, minDist: defaultMinDistance * 0.5f, maxDist: canvasControl.placeSoundsOverlay.maxRadiusSlider.radiusValue); layoutManager.Bind(soundMarker, h, !playbackIsStopped, reloadSoundClips: false); soundMarker.SetIconAndRangeToRandomValue(); }
private IEnumerator InitSoundMarkers( List<Hotspot> hotspots, System.Action<int> progressCallback = null, System.Action completeCallback = null) { float waitTime = hotspots.Count < 6 ? (1.2f / hotspots.Count) : 0; int markersToLoadBeforeYield = Mathf.Min(2, Mathf.Max(1, hotspots.Count / 16)); Debug.Log ("markersToLoadBeforeYield: " + markersToLoadBeforeYield); int index = 0; int numLoadedAfterLastYield = 0; // Bind all the sounds to their game objects foreach (Hotspot h in hotspots) { // SoundMarker newSoundMarker = SoundMarker.CreatePrefab( // anchorWrapperTransform.TransformPoint(h.positon), // h.rotation, soundMarkerPrefab, anchorWrapperTransform); SoundMarker newSoundMarker = _soundMarkerPooling.GetSoundMarker(); SoundMarker.SetupUnanchoredMarker(newSoundMarker, anchorWrapperTransform.TransformPoint(h.positon), h.rotation, anchorWrapperTransform); layoutManager.Bind(newSoundMarker, h, !playbackIsStopped, reloadSoundClips: false); newSoundMarker.markerDelegate = this; soundMarkers.Add(newSoundMarker); ++index; // Debug.Log("InitSoundMarkers LOADED " + index + " - Marker('" + h.soundID + "')"); if (progressCallback != null) { progressCallback(index); } ++numLoadedAfterLastYield; if (waitTime > 0) { yield return new WaitForSeconds(waitTime); } else if (numLoadedAfterLastYield >= markersToLoadBeforeYield) { numLoadedAfterLastYield = 0; yield return null; } } completeCallback(); }