//tips
//unitapp方向性模索
unityappの方向性を模索。
https://forum.unity.com/threads/health-app.406176/
結局のところcomplex real-time visualisationsに対しての解決策であり、できないことはないが医療機器との接続およびosとの連携はあまり得意分野ではないとのこと。
Unity is not overly suited for health care apps. Unity is best for things that require complex real-time visualisations. Health care apps also tend to use a bunch of native device functionality that requires jumping through hoops in Unity. Unity is great for games, but struggles to schedule an appointment on the users calendar. (One of my freelance projects involved a healthcare app in Unity.
なので、リアルタイムの映像に付随する音声情報の機能をまずは実装し、理解していくことにする。リアルタイムのコミュニケーションでは通話およびチャットがマストなので。
Unityでのボイスチャットについて複数の案が見つかった。VIVOX,photonボイスチャット,WebRTCのDataChannelなどである。
参考を下記にはる。
https://qiita.com/tangotarou2/items/50fa578d81b66f036732
https://qiita.com/aKuad/items/6cbd3cf76e4a0f0cc84c
https://akihiro-document.azurewebsites.net/post/hololens2_azureremoterendering_sharing/
https://zenn.dev/5ena/articles/184f208f7a1d03e1d876
https://qiita.com/kina-churapps/items/ea45e483f2367c69c006
https://qiita.com/CST_negi/items/bf3bc0ede34bbcd2f7b2
今回はその中でも最新と見受けられるVIVOXでのunityボイスチャット機能の実装を行なっていく。
早速こちらから
https://developer.vivox.com/
アカウントを作成。
メール認証後にすぐにアカウントを作成できた。
ここからアプリケーションの作成に進み、必要情報を入力し、アプリを作成すると、VIVOX API 情報を入手できるようになる。これをunityに読み込ませて使用することでvoicechatを実行することになるので重要。
さらに同サイトからunity用のSDKをダウンロードし、ダウンロードしたものをunityにて展開、インストールする。
ここからは下記の手中に沿って準備。
https://qiita.com/Cova8bitdot/items/1c4288485a13e54b513f
Assets/Vivox/Samples/TanksUnityGameSample/Scenes/MainScene.unity を開き、vivoxvoicemanagerオブジェクトを選択。
インスペクターでserverにAPI エンドポイント、domainにドメイン、Token issuerに発行者、Token keyにシークレットキーを貼り付ける。
Buildsettingのsceneにこのシーンを追加。実行ボタンを押すと
“libVivoxNative.bundle”が悪質なソフトウェアかどうかをAppleでは確認できないため、このソフトウェアは開けません。
複数個エラーが発生するのでappleのセキュリティの部分で許可をする。
一旦事項はできたもののその他のオブジェクトに下記のようなエラー発生。
NullReferenceException: Object reference not set to an instance of an object
LoginScreenUI.Awake () (at Assets/Vivox/Samples/TanksUnityGameSample/Scripts/Vivox/UI/LoginScreenUI.cs:31)
これらに対応するUIを作成していく必要がある。
CanvasでUIを確認していくと該当オブジェクトのスクリプトが全てインポート時に外れてしまっているためエラーになっているよう。
The associated script cannot be loaded…という風に表示されコンポーネントへのオブジェクトのアタッチができなくなっている。
一旦saveして再起動してみるもサンプルでインポートしたものは使えない。
Canvasを自作して、その子要素にloginscreenUIscriptを設置し、そちらの子にbuttonを持たせるとアタッチが可能となったので抜本的に作り直すことで問題は解決しそう。
新たなシーンとしてUI部分を全削除した分岐版を作成した。
下記にも同様に導入動画があったのでこちらも詰まった際に参考になりそう。
canavasのscalemodeをscalewithscreensizeに変更。
Vivoxmanagerオブジェクトを作成し、下記をアタッチ。
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using VivoxUnity;
public class VivoxManager : MonoBehaviour
{
VivoxVoiceManager vivox;
VivoxUnity.Client client= new Client();
[Header("Login UI")]
[SerializeField] InputField input_Username;
[SerializeField] InputField input_ChannelName;
[SerializeField] Text txt_Username;
[SerializeField] Text txt_ChannelName;
void Awake()
{
vivox = VivoxVoiceManager.Instance;
client.Uninitialize();
client.Initialize();
vivox.OnUserLoggedInEvent += LoggedIn;
}
private void OnApplicationQuit()
{
if (vivox.LoginState == LoginState.LoggedIn)
{
vivox.Logout();
}
client.Uninitialize();
}
public void Login()
{
if (!string.IsNullOrEmpty(input_Username.text))
{
vivox.Login(input_Username.text);
}
}
private void LoggedIn()
{
txt_Username.text = vivox.LoginSession.LoginSessionId.DisplayName;
}
public void Logout()
{
if (vivox.LoginState == LoginState.LoggedIn)
{
vivox.Logout();
}
}
public void JoinChannel()
{
if (!string.IsNullOrEmpty(input_ChannelName.text))
{
vivox.JoinChannel(input_ChannelName.text,ChannelType.NonPositional,VivoxVoiceManager.ChatCapability.AudioOnly);
txt_ChannelName.text = input_ChannelName.text;
}
}
}
さらにここから作成したUIをvivoxManagerにアタッチ。
実行すると、これにて通話が可能になった。
すごい簡単。
もう少し理解を深めるためにVivoxvoicemanagerのスクリプトの中身を確認していく。