facebook twitter hatena line email

「Unity/Agora/voicechat community」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(デモから音声通話サンプル作成)
行119: 行119:
 
*Assets/WebGLTemplates/AgoraTemplate2020があるか確認する。
 
*Assets/WebGLTemplates/AgoraTemplate2020があるか確認する。
 
*PCを再起動する
 
*PCを再起動する
 +
 +
==デモから画面共有サンプル作成==
 +
===サンプルソース解析===
 +
*SceneFuncTests.unityのApi_testHelperのGameObjectのFunctionalTest/DevDemo/Test/DVC_ShareScreen.csが、画面共有ソース
 +
*TestHome.csのonJoinButtonClicked()からシーン移動している
 +
*FunctionalTest/DevDemo/SceneHome2のボタンで、移動できる。
 +
 +
===以下"SceneFuncTests"がロードできないというエラーとなる場合===
 +
以下エラーとなる場合
 +
'SceneFuncTests' couldn't be loaded because it has not been added to the build settings or the AssetBundle has not been loaded.
 +
To add a scene to the build settings use the menu File->Build Settings...
 +
PlayerSettingのSceneInBuildにSceneFuncTests.unityを追加すると良い。

2022年10月31日 (月) 16:55時点における版

agoraコミュニティ側

sdkはどれを使っている

unitysdkではなく、websdkを使ってる。

Assets/WebGLTemplates/AgoraTemplate2020/AgoraWebSDK

agoraインストール

  1. https://github.com/AgoraIO-Community/Agora_Unity_WebGL をDL
  2. Assets/AgoraEngine/Demo/SceneHomeを開く
  3. GameControllerのInspectorを開きAppIDを入力する
  4. Unityメインメニュー/File/BuildSettings/PlayerSetttings/WebGL/WebGLTemplateをAgoraTemplete2020
  5. Unityメインメニュー/File/BuildSettings/PlayerSetttings/SceneInBuildのSceneHomeとSceneHellowVideoに、チェックを追加
  6. 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;
}
  1. Assets/AgoraEngine/Demo/TestHelloUnityVideo.csのjoin()内の、SetupInitState();を削除
  2. 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を再起動する

デモから画面共有サンプル作成

サンプルソース解析

  • SceneFuncTests.unityのApi_testHelperのGameObjectのFunctionalTest/DevDemo/Test/DVC_ShareScreen.csが、画面共有ソース
  • TestHome.csのonJoinButtonClicked()からシーン移動している
  • FunctionalTest/DevDemo/SceneHome2のボタンで、移動できる。

以下"SceneFuncTests"がロードできないというエラーとなる場合

以下エラーとなる場合

'SceneFuncTests' couldn't be loaded because it has not been added to the build settings or the AssetBundle has not been loaded.

To add a scene to the build settings use the menu File->Build Settings... PlayerSettingのSceneInBuildにSceneFuncTests.unityを追加すると良い。