ドキュメント

​
​

Development

User Acquisition

Monetization

産業

Vivox Unity SDK

Vivox Unity SDK

Vivox
​
​
Vivox Unity SDK
  • Overview
  • Get started
  • Release notes
  • Developer guide
    • Set up your project
    • Create voice and text channels
      • Channel management
      • Channel name criteria
      • Channel types
      • Positional channels
      • Channel identifiers for large scale games
      • Participant management
      • Join a channel
      • Leave a channel
      • Channel webhooks
      • Automatic connection recovery
    • Messaging
    • Player management
    • Device management
    • Audio management
    • Mobile development
    • Text-to-speech
    • Speech-to-text
    • Real-time recording
    • Server-side-recording
    • Troubleshooting
  • Tutorials
  • Reference
  1. Vivox Unity SDK のドキュメント
  2. Vivox Unity 開発者ガイド
  3. チャンネル

参加者の管理

Manage participant events when users join or leave channels.
読み終わるまでの所要時間 5 分
最終更新 8ヶ月前

Vivox SDK は他のすべての参加者に表示されるチャンネル内の個別の参加に関する情報を送ります。これには以下の情報が含まれます。
  • ユーザーがチャンネルに参加するとき。
  • ユーザーがチャンネルから退出するとき。
  • ユーザーの状態に関する重要な変更があるとき (ユーザーが話しているまたは入力しているかどうかなど)。
参加者イベントの処理は省略可能です。ユーザーの状態を視覚的に表示しない場合 (例えば誰の音声が有効になっているかを表示するなど)、ゲームではそれらのイベントを無視できます。
ユーザー状態情報を可視化するには、ゲームで以下のメッセージを処理する必要があります。
  • VivoxService.Instance.ParticipantAddedToChannel
  • VivoxService.Instance.ParticipantRemovedFromChannel
  • VivoxParticipant.ParticipantMuteStateChanged
  • VivoxParticipant.ParticipantSpeechDetected
  • VivoxParticipant.ParticipantAudioEnergyChanged

VivoxParticipant

ParticipantAddedToChannel
と
ParticipantRemovedFromChannel
はいずれも VivoxParticipant に付属します。VivoxParticipant には、以下のような、追加された参加者に関する情報が含まれます。
  • PlayerId
  • DisplayName
  • その VivoxParticipant が参加しているチャンネルの ChannelName。
  • その VivoxParticipant が IsSelf (チャンネル内のローカルプレイヤーを表す参加者) かどうか。
VivoxParticipant には、以下のような、その参加者の現在の状態も含まれます。
  • IsMuted 状態
  • AudioEnergy
  • SpeechDetected (そのプレイヤーの AudioEnergy が Vivox によって話し声と認識されるレベルに到達しているかどうか)。
VivoxParticipants は、ローカルプレイヤーがその参加者をミュートしているか、またはその参加者が現在チャンネル内で発話中かどうかを伝えるために、
VivoxParticipant.ParticipantMuteStateChanged
と
VivoxParticipant.ParticipantSpeechDetected
によって参加者の UI 表示と緊密に結び付ける必要があります。
VivoxParticipant.ParticipantAudioEnergyChanged
を使用すると、SpeechDetected よりも正確な音量単位 (VU) メーターを作成できます。
以下のコードは、Vivox ChatChannelSample からの簡略化されたセグメントであり、これらのシステムの例です。
public class RosterManager : MonoBehaviour{ private const string LobbyChannelName = "lobbyChannel"; private Dictionary<string, List<RosterItem>> rosterObjects = new Dictionary<string, List<RosterItem>>(); public GameObject rosterItemPrefab; private void Start() { VivoxService.Instance.ParticipantAddedToChannel += OnParticipantAdded; VivoxService.Instance.ParticipantRemovedFromChannel += OnParticipantRemoved; } public void ClearAllRosters() { foreach(List<RosterItem> rosterList in rosterObjects.Values) { foreach(RosterItem item in rosterList) { Destroy(item.gameObject); } rosterList.Clear(); } rosterObjects.Clear(); } public void ClearChannelRoster(string channelName) { List<RosterItem> rosterList = rosterObjects[channelName]; foreach(RosterItem item in rosterList) { Destroy(item.gameObject); } rosterList.Clear(); rosterObjects.Remove(channelName); } private void CleanRoster(string channelName) { RectTransform rt = this.gameObject.GetComponent<RectTransform>(); rt.sizeDelta = new Vector2(0, rosterObjects[channelName].Count * 50); } void UpdateParticipantRoster(VivoxParticipant participant, bool isAddParticipant) { if (isAddParticipant) { GameObject newRosterObject = GameObject.Instantiate(rosterItemPrefab, this.gameObject.transform); RosterItem newRosterItem = newRosterObject.GetComponent<RosterItem>(); List<RosterItem> thisChannelList; if (rosterObjects.ContainsKey(participant.ChannelName)) { //Add this object to an existing roster rosterObjects.TryGetValue(participant.ChannelName, out thisChannelList); newRosterItem.SetupRosterItem(participant); thisChannelList.Add(newRosterItem); rosterObjects[participant.ChannelName] = thisChannelList; } else { //Create a new roster to add this object to thisChannelList = new List<RosterItem>(); thisChannelList.Add(newRosterItem); newRosterItem.SetupRosterItem(participant); rosterObjects.Add(participant.ChannelName, thisChannelList); } CleanRoster(participant.ChannelName); } else { if (rosterObjects.ContainsKey(participant.ChannelName)) { RosterItem removedItem = rosterObjects[participant.ChannelName].FirstOrDefault(p => p.Participant.PlayerId == participant.PlayerId); if (removedItem != null) { rosterObjects[participant.ChannelName].Remove(removedItem); Destroy(removedItem.gameObject); CleanRoster(participant.ChannelName); } else { Debug.LogError("Trying to remove a participant that has no roster item."); } } } } void OnParticipantAdded(VivoxParticipant participant) { UpdateParticipantRoster(participant, true); } void OnParticipantRemoved(VivoxParticipant participant) { UpdateParticipantRoster(participant, false); }}public class RosterItem : MonoBehaviour{ // Player specific items. public VivoxParticipant Participant; public Text PlayerNameText; public Image ChatStateImage; public Sprite MutedImage; public Sprite SpeakingImage; public Sprite NotSpeakingImage; Button m_muteButton; private void UpdateChatStateImage() { if (Participant.IsMuted) { ChatStateImage.sprite = MutedImage; } else { if (Participant.SpeechDetected) { ChatStateImage.sprite = SpeakingImage; } else { ChatStateImage.sprite = NotSpeakingImage; } } } public void SetupRosterItem(VivoxParticipant participant) { //Set the Participant variable of this RosterItem to the VivoxParticipant added in the RosterManager Participant = participant; PlayerNameText.text = Participant.DisplayName; // Update the image to the active state of the user (either the SpeakingImage, the MutedImage, or the NotSpeakingImage) and then attach // the function to run if an event is fired denoting a change to that users state UpdateChatStateImage(); Participant.ParticipantMuteStateChanged += UpdateChatStateImage; Participant.ParticipantSpeechDetected += UpdateChatStateImage; //A button on the UI element itself is implemented to handle muting on the participant represented by the UI element m_muteButton = gameObject.GetComponent<Button>(); m_muteButton.onClick.AddListener(() => { // If already muted, unmute, and vice versa. if (Participant.IsMuted) { Participant.UnmutePlayerLocally(); } else { Participant.MutePlayerLocally(); } }); } void OnDestroy() { Participant.ParticipantMuteStateChanged -= UpdateChatStateImage; Participant.ParticipantSpeechDetected -= UpdateChatStateImage; m_muteButton.onClick.RemoveAllListeners(); }}

Copyright © 2026 Unity Technologies
法規事項プライバシーポリシークッキーDocumentation Terms of Use私の個人情報を販売または共有しないプライバシーに関する選択 (クッキー設定)

"Unity" の名称、Unity のロゴ、およびその他の Unity の商標は、米国およびその他の国における Unity Technologies またはその関係会社の商標または登録商標です (詳しくはこちら)。その他の名称またはブランドは該当する所有者の商標です。

一部のページは利便性向上のため機械翻訳を使用しており、内容に不正確な表現が含まれる場合があります。内容に齟齬または不一致が生じた場合は、英語版を正本とします。

  • このページ
    • VivoxParticipant


このページの問題を報告する