Skip to content

Instantly share code, notes, and snippets.

@khlizard
Last active September 28, 2022 07:06
Show Gist options
  • Save khlizard/40c3915fb7dc12ec6210035ee1844886 to your computer and use it in GitHub Desktop.
Save khlizard/40c3915fb7dc12ec6210035ee1844886 to your computer and use it in GitHub Desktop.
using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;
[UdonBehaviourSyncMode(BehaviourSyncMode.Manual)]
public class TopazChatVRCDN : UdonSharpBehaviour
{
[Header("PlayerとAnimator (両方VideoPlayer自身)")]
[SerializeField] private VRC.SDK3.Video.Components.Base.BaseVRCVideoPlayer TopazVideoPlayer;
[SerializeField] private Animator TopazAnimator;
[Header("ストリーム用URL PC用とQuest用")]
[SerializeField] private VRCUrl _streamUrlPC;
[SerializeField] private VRCUrl _streamUrlQuest;
private int _resyncParameterHash;
private int _videoStartParameterHash;
private VRCUrl _streamURL;
// Quest Check
#if !UNITY_EDITOR && UNITY_ANDROID
const bool _isQuest = true;
#else
const bool _isQuest = false;
#endif
void Start()
{
if (_isQuest) {
_streamURL = _streamUrlQuest;
} else {
_streamURL = _streamUrlPC;
}
_resyncParameterHash = Animator.StringToHash("Resync");
_videoStartParameterHash = Animator.StringToHash("VideoStart");
this.Resync();
}
public void GlobalSync()
{
SendCustomNetworkEvent(VRC.Udon.Common.Interfaces.NetworkEventTarget.All, "Resync");
this.Resync();
}
public void Resync()
{
TopazAnimator.ResetTrigger(_videoStartParameterHash);
TopazAnimator.SetTrigger(_resyncParameterHash);
}
public void Play()
{
TopazVideoPlayer.PlayURL(_streamURL);
}
public void Stop()
{
TopazVideoPlayer.Stop();
}
public override void OnVideoStart()
{
TopazAnimator.SetTrigger(_videoStartParameterHash);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment