Skip to content

Commit 2ac1332

Browse files
authored
Merge pull request #16 from neocortex-link/feature/mobile-support
Mobile Microphone Permission Utility
2 parents 06c74ce + 610b684 commit 2ac1332

File tree

6 files changed

+3512
-2
lines changed

6 files changed

+3512
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.3.6] - 28 March 2025
8+
- Microphone Permission utility for mobile builds
9+
- Mobile Audio Chat Test sample
710

8-
## [0.3.5] - 26 April 2025
11+
## [0.3.5] - 26 March 2025
912
- Neocortex Audio Receiver microphone picker improvements
1013

1114
## [0.3.4] - 21 February 2025

Runtime/MicrophonePermission.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using UnityEngine;
2+
using System.Collections;
3+
4+
#if UNITY_ANDROID
5+
using UnityEngine.Android;
6+
#endif
7+
8+
namespace Neocortex
9+
{
10+
public class MicrophonePermission : MonoBehaviour
11+
{
12+
[SerializeField] private GameObject[] activateOnPermission;
13+
[SerializeField] private GameObject[] deactivateOnPermission;
14+
15+
private IEnumerator Start()
16+
{
17+
RequestMicrophonePermission();
18+
yield return StartCoroutine(WaitForMicrophonePermission());
19+
20+
foreach (GameObject go in activateOnPermission)
21+
{
22+
go.SetActive(true);
23+
}
24+
25+
foreach (GameObject go in deactivateOnPermission)
26+
{
27+
go.SetActive(false);
28+
}
29+
}
30+
31+
private void RequestMicrophonePermission()
32+
{
33+
#if UNITY_ANDROID
34+
if (!Permission.HasUserAuthorizedPermission(Permission.Microphone))
35+
{
36+
Permission.RequestUserPermission(Permission.Microphone);
37+
}
38+
#elif UNITY_IOS
39+
if (!Application.HasUserAuthorization(UserAuthorization.Microphone))
40+
{
41+
Application.RequestUserAuthorization(UserAuthorization.Microphone);
42+
}
43+
#endif
44+
}
45+
46+
private IEnumerator WaitForMicrophonePermission()
47+
{
48+
#if UNITY_ANDROID
49+
while (!Permission.HasUserAuthorizedPermission(Permission.Microphone))
50+
{
51+
yield return null;
52+
}
53+
#elif UNITY_IOS
54+
while (!Application.HasUserAuthorization(UserAuthorization.Microphone))
55+
{
56+
yield return null;
57+
}
58+
#else
59+
yield return null;
60+
#endif
61+
}
62+
}
63+
}

Runtime/MicrophonePermission.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)