1
This commit is contained in:
43
Unity/Scripts/AudioSystem/NetworkAudioSource.cs
Normal file
43
Unity/Scripts/AudioSystem/NetworkAudioSource.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
#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
|
Reference in New Issue
Block a user