-
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Spatialized max distance needs to be adjusted based on the `App.Scene.Pose.scale` to do so we introduce a new script `MultiplayerAudioSourcesManager` which set all of the remote users audioSources max distance whenever the scene scales up or down
- Loading branch information
Showing
5 changed files
with
111 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
Assets/Scripts/Multiplayer/MultiplayerAudioSourcesManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright 2023 The Open Brush Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using TiltBrush; | ||
using UnityEngine; | ||
|
||
public class MultiplayerAudioSourcesManager : MonoBehaviour | ||
{ | ||
public static MultiplayerAudioSourcesManager m_Instance; | ||
private List<AudioSource> sources; | ||
private float _previousScale; | ||
|
||
public void AddAudioSource(AudioSource source) | ||
{ | ||
|
||
sources.Append(source); | ||
|
||
} | ||
|
||
void Update() | ||
{ | ||
float currentScale = App.Scene.Pose.scale; | ||
|
||
if (!Mathf.Approximately(currentScale, _previousScale)) | ||
{ | ||
_previousScale = currentScale; | ||
UpdateAudioSources(currentScale); | ||
} | ||
} | ||
|
||
private void UpdateAudioSources(float sceneScale) | ||
{ | ||
// Loop backward to remove invalid AudioSources | ||
for (int i = sources.Count - 1; i >= 0; i--) | ||
{ | ||
var source = sources[i]; | ||
if (source != null) | ||
{ | ||
float adjustedMaxDistance = CalculateMaxDistance(sceneScale); | ||
source.maxDistance = adjustedMaxDistance; | ||
} | ||
else sources.RemoveAt(i); | ||
} | ||
} | ||
|
||
private float CalculateMaxDistance(float sceneScale) | ||
{ | ||
// This is based on OpenBrush default scene max radius | ||
// - At scale 0.1, the mountains diameter is 200 (close range). | ||
// - At scale 1.0,the mountains diameter is 20000 (far range). | ||
return Mathf.Lerp(200f, 20000f, Mathf.Clamp01(sceneScale)); | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
Assets/Scripts/Multiplayer/MultiplayerAudioSourcesManager.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters