43 lines
1.0 KiB
C#
43 lines
1.0 KiB
C#
#if MIRROR
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using Mirror;
|
|
namespace BITKit
|
|
{
|
|
public class NetworkAudioSource : NetworkBehaviour
|
|
{
|
|
[Header(Constant.Header.Components)]
|
|
public AudioSource audioSource;
|
|
[Header(Constant.Header.InternalVariables)]
|
|
IGenericEvent<string> genericEvent;
|
|
public void Play(AudioSO so)
|
|
{
|
|
if (isOwned)
|
|
CmdPlay(so);
|
|
else if (isServer)
|
|
RpcPlay(so);
|
|
}
|
|
void Start()
|
|
{
|
|
TryGetComponent<IGenericEvent<string>>(out genericEvent);
|
|
}
|
|
[Command]
|
|
void CmdPlay(AudioSO so)
|
|
{
|
|
RpcPlay(so);
|
|
}
|
|
[ClientRpc]
|
|
void RpcPlay(AudioSO so)
|
|
{
|
|
audioSource.loop = so.loop;
|
|
audioSource.clip = so.Get();
|
|
audioSource.Play();
|
|
if (genericEvent is not null)
|
|
{
|
|
genericEvent.Invoke(so);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endif |