Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions Assets/AirConsole/examples/basic/AudioPlayer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#if !DISABLE_AIRCONSOLE
namespace NDream.AirConsole.Examples {
using NDream.AirConsole;
using UnityEngine;

/// <summary>
/// Example Audio Player that starts playing when the game is ready and stops when the game ends.
/// It also listens to volume changes and adjusts the audio accordingly.
/// </summary>
[RequireComponent(typeof(AudioSource))]
public class AudioPlayer : MonoBehaviour {
private AudioSource _audioSource;

private void Awake() {
_audioSource = GetComponent<AudioSource>();
if (!_audioSource) {
AirConsoleLogger.LogError(() => "AudioPlayer requires an AudioSource component.", this);
enabled = false;
return;
}

SetupAudioSource();
AirConsole.instance.onReady += HandleOnReady;
AirConsole.instance.onGameEnd += HandleOnGameEnd;

// Until OnReady is called, we don't want any audio from Unity playing as the Player Lobby overlay will be shown.
AudioListener.pause = true;
}

private void SetupAudioSource() {
_audioSource.playOnAwake = false;
_audioSource.loop = true;
_audioSource.volume = 1.0f;
if (!_audioSource.clip) {
_audioSource.clip = Resources.Load<AudioClip>("Audio/Music/Happy_1");
}
}

private void HandleOnGameEnd() {
// After OnGameEnd is called, we must not play any audio until OnReady is called again. During this time the Player Lobby
// overlay will be shown.
AudioListener.pause = true;
}

private void HandleOnReady(string code) {
AirConsoleLogger.Log(() => $"OnReady for {code}");
AudioListener.pause = false;
_audioSource.Play();
}

private void HandleAudioVolumeChange(float volume) {
AirConsoleLogger.Log(() => $"Setting volume to {volume}");
if (volume > 0) {
AudioListener.pause = false;
AudioListener.volume = volume;
_audioSource.Play();
} else if (Mathf.Approximately(0, volume)) {
AudioListener.pause = true;
}
}
}
}
#endif
11 changes: 11 additions & 0 deletions Assets/AirConsole/examples/basic/AudioPlayer.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Assets/AirConsole/examples/basic/ExampleBasicLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ private void Awake() {
}

private void OnReady(string code) {
AirConsoleLogger.Log(() => "OnReady: " + code);
//Log to on-screen Console
logWindow.text = "ExampleBasic: AirConsole is ready! \n \n";

Time.timeScale = 1.0f;

//Mark Buttons as Interactable as soon as AirConsole is ready
Button[] allButtons = (Button[])FindObjectsOfType(typeof(Button));
foreach (Button button in allButtons) {
Expand Down Expand Up @@ -114,8 +117,7 @@ private void OnAdComplete(bool adWasShown) {
}

private void OnGameEnd() {
Debug.Log("OnGameEnd is called");
Camera.main.enabled = false;
AirConsoleLogger.Log(() => "OnGameEnd is called");
Time.timeScale = 0.0f;
}

Expand Down
142 changes: 142 additions & 0 deletions Assets/AirConsole/examples/basic/basic.unity
Original file line number Diff line number Diff line change
Expand Up @@ -4467,6 +4467,147 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1064712596}
m_CullTransparentMesh: 0
--- !u!1 &1070081529
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1070081532}
- component: {fileID: 1070081531}
- component: {fileID: 1070081530}
m_Layer: 0
m_Name: AudioPlayer
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1070081530
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1070081529}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d33481c3f96324d4bba3e5db8826fd6e, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!82 &1070081531
AudioSource:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1070081529}
m_Enabled: 1
serializedVersion: 4
OutputAudioMixerGroup: {fileID: 0}
m_audioClip: {fileID: 8300000, guid: 804632e1e46684476b4ea5f752e8df15, type: 3}
m_PlayOnAwake: 0
m_Volume: 1
m_Pitch: 1
Loop: 1
Mute: 0
Spatialize: 0
SpatializePostEffects: 0
Priority: 128
DopplerLevel: 1
MinDistance: 1
MaxDistance: 500
Pan2D: 0
rolloffMode: 0
BypassEffects: 0
BypassListenerEffects: 0
BypassReverbZones: 0
rolloffCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 1
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
panLevelCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
spreadCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
reverbZoneMixCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
--- !u!4 &1070081532
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1070081529}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0.36577117, y: -0.17775297, z: 0.030780792}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1087830224
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -7557,3 +7698,4 @@ SceneRoots:
- {fileID: 607279077}
- {fileID: 1179297379}
- {fileID: 535473225}
- {fileID: 1070081532}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"references": [
"Unity.TextMeshPro",
"UnityEngine.UI",
"unity-webview"
"com.airconsole.unity-webview.runtime"
],
"includePlatforms": [
"Android",
Expand Down
Loading