「Unity/Agora/voicechat community」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→デモから音声通話サンプル作成) |
|||
| 行83: | 行83: | ||
app.join(ChannelName, enableVideo, muted); | app.join(ChannelName, enableVideo, muted); | ||
#endif | #endif | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
} | } | ||
} | } | ||
| 行109: | 行99: | ||
#AssetsAgoraEngine/Prefabs/AgoraEventHandlerを、ロードSceneに追加しておく。 | #AssetsAgoraEngine/Prefabs/AgoraEventHandlerを、ロードSceneに追加しておく。 | ||
| + | ===切断処理=== | ||
| + | <pre> | ||
| + | public void Disconnect() | ||
| + | { | ||
| + | if (!ReferenceEquals(app, null)) | ||
| + | { | ||
| + | app.leave(); // leave channel | ||
| + | app.unloadEngine(); // delete engine | ||
| + | app = null; // delete app | ||
| + | } | ||
| + | } | ||
| + | </pre> | ||
===ビルド後html表示時に"NullReferenceException"エラーとなる場合=== | ===ビルド後html表示時に"NullReferenceException"エラーとなる場合=== | ||
エラー詳細 | エラー詳細 | ||
2022年10月28日 (金) 11:16時点における版
目次
agoraコミュニティ側
sdkはどれを使っている
unitysdkではなく、websdkを使ってる。
Assets/WebGLTemplates/AgoraTemplate2020/AgoraWebSDK
agoraインストール
- https://github.com/AgoraIO-Community/Agora_Unity_WebGL をDL
- Assets/AgoraEngine/Demo/SceneHomeを開く
- GameControllerのInspectorを開きAppIDを入力する
- Unityメインメニュー/File/BuildSettings/PlayerSetttings/WebGL/WebGLTemplateをAgoraTemplete2020
- Unityメインメニュー/File/BuildSettings/PlayerSetttings/SceneInBuildのSceneHomeとSceneHellowVideoに、チェックを追加
- WebGLでビルドすると、htmlがブラウザで開くのでJoinを確認
agoraSdkCWrapperなエラーが出る場合
詳細
DllNotFoundException: agoraSdkCWrapper assembly:<unknown assembly> type:<unknown type> member:(null)
UnityEditorで表示するとこのエラーが出る。WebGLでビルドしてブラウザで表示すると良い。
デモ版ソース解析
- AgoraEngine/Demo/ButtonHandler.csに、ボタンの挙動が、記述されてる
- AgoraEngine/Demo/TestHome.csが、テストロジック処理が、記述されてる
- TestHome.onJoinButtonClickedが、動画音声処理
- TestHome.onJoinAudienceが、配信受け取る(Audience)処理
- TestHome.onJoinAudienceが通信周りロジック
- AssetsAgoraEngine/Prefabs/AgoraEventHandlerを、ロードSceneに追加しておく。
- Hostボタンのオンオフ処理は、Assets/AgoraEngine/Demo/TestHome.onJoinAudience.csのGameObject.Find("RoleButton")とAssets/API-Example/tools/ToggleStateButton.csあたり。Audience表示されてる時Broadcastされ、Host表示のときに、Audienceとなっている様子。
- AgoraEngine/Demo/TestHelloUnityVideo.csが通信ロジック周りの処理が、記述されてる
動画音声オンオフ
- AgoraEngine/Demo/TestHelloUnityVideo.csの以下部分
AudioVideoState.pubAudio = av.togglePubAudio.isOn; AudioVideoState.pubVideo = av.togglePubVideo.isOn; AudioVideoState.subAudio = av.toggleSubAudio.isOn; AudioVideoState.subVideo = av.toggleSubVideo.isOn;
音声オフだと
こちらの処理になる。
gameController.onJoinButtonClicked(false);
Android時の権限追加
#if (UNITY_2018_3_OR_NEWER && UNITY_ANDROID)
ArrayList permissionList = new ArrayList();
permissionList.Add(Permission.Microphone);
permissionList.Add(Permission.Camera);
foreach(string permission in permissionList)
{
if (!Permission.HasUserAuthorizedPermission(permission))
{
Permission.RequestUserPermission(permission);
}
}
#endif
ビルド時の"Pointer_stringify"のエラー表示
以下エラーが出るが、動作に問題ない。
The JavaScript function 'Pointer_stringify(ptrToSomeCString)' is obsoleted and will be removed in a future Unity version. Please call 'UTF8ToString(ptrToSomeCString)' instead. printErr @ webgl_project_audio.loader.js:1
デモから音声通話サンプル作成
AudioScene.unityを追加して、AudioScene.csを作成して、AudioScene.unityのMainCameraへ追加
using UnityEngine;
public class AudioScene : MonoBehaviour
{
void Start()
{
#if !UNITY_EDITOR && UNITY_WEBGL
string AppID = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
TestHelloUnityVideo app = null;
// create app if nonexistent
if (ReferenceEquals(app, null))
{
app = new TestHelloUnityVideo(); // create app
app.loadEngine(AppID); // load engine
}
string ChannelName = "testchannel";
bool enableVideo = false;
bool muted = false;
app.join(ChannelName, enableVideo, muted);
#endif
}
}
Assets/AgoraEngine/Demo/AudioVideoState.csのフラグを追加
public class AudioVideoStates
{
public bool subAudio = true;
public bool subVideo = false;
public bool pubAudio = true;
public bool pubVideo = false;
}
- Assets/AgoraEngine/Demo/TestHelloUnityVideo.csのjoin()内の、SetupInitState();を削除
- AssetsAgoraEngine/Prefabs/AgoraEventHandlerを、ロードSceneに追加しておく。
切断処理
public void Disconnect()
{
if (!ReferenceEquals(app, null))
{
app.leave(); // leave channel
app.unloadEngine(); // delete engine
app = null; // delete app
}
}
ビルド後html表示時に"NullReferenceException"エラーとなる場合
エラー詳細
webgl_project_audio.framework.js:3 NullReferenceException: Object reference not set to an instance of an object.
Assets/AgoraEngine/Demo/TestHelloUnityVideo.csのjoin()内の、SetupInitState();を削除
AgoraTemplate2020が適用されない
- Assets/WebGLTemplates/AgoraTemplate2020があるか確認する。
- PCを再起動する
