111 lines
2.6 KiB
C#
111 lines
2.6 KiB
C#
|
|
using UdonSharp;
|
|
using UnityEngine;
|
|
using VRC.SDKBase;
|
|
using VRC.Udon.Common;
|
|
|
|
|
|
public enum LightningRoundEffect
|
|
{
|
|
Thunder,
|
|
LightningStrike,
|
|
ThunderAndRain,
|
|
|
|
MAX_EFFECTS
|
|
}
|
|
|
|
|
|
[UdonBehaviourSyncMode(BehaviourSyncMode.Manual)]
|
|
public class LightningRoundEffectsController : UdonSharpBehaviour
|
|
{
|
|
[SerializeField] private AudioManager _AudioManager;
|
|
[SerializeField] private Animator _Animator;
|
|
[Space]
|
|
[SerializeField] private GameObject _LightningBolt;
|
|
[SerializeField] private ParticleSystem _PersonalRaincloud;
|
|
[SerializeField] private Umbrella _Umbrella;
|
|
|
|
[UdonSynced] private LightningRoundEffect _Effect = LightningRoundEffect.MAX_EFFECTS;
|
|
private LightningRoundEffect _Effect_Cached = LightningRoundEffect.MAX_EFFECTS;
|
|
|
|
|
|
public override void OnOwnershipTransferred(VRCPlayerApi Player)
|
|
{
|
|
Networking.SetOwner(Player, _LightningBolt.gameObject);
|
|
Networking.SetOwner(Player, _Umbrella.gameObject);
|
|
|
|
base.OnOwnershipTransferred(Player);
|
|
}
|
|
|
|
public override void OnDeserialization(DeserializationResult Result)
|
|
{
|
|
_PlayLightningRoundAnimation_Synced();
|
|
|
|
base.OnDeserialization(Result);
|
|
}
|
|
|
|
|
|
public void Initialise()
|
|
{
|
|
_Effect = LightningRoundEffect.MAX_EFFECTS;
|
|
_PlayLightningRoundAnimation_Synced();
|
|
RequestSerialization();
|
|
}
|
|
|
|
public void PlayLightningRoundAnimation()
|
|
{
|
|
_Effect = (LightningRoundEffect)Random.Range(0, (int)LightningRoundEffect.MAX_EFFECTS);
|
|
_PlayLightningRoundAnimation_Synced();
|
|
RequestSerialization();
|
|
}
|
|
private void _PlayLightningRoundAnimation_Synced()
|
|
{
|
|
if (_Effect != _Effect_Cached)
|
|
{
|
|
_Effect_Cached = _Effect;
|
|
|
|
switch (_Effect)
|
|
{
|
|
case LightningRoundEffect.Thunder:
|
|
_LightningBolt.SetActive(false);
|
|
break;
|
|
case LightningRoundEffect.LightningStrike:
|
|
_LightningBolt.SetActive(true);
|
|
break;
|
|
case LightningRoundEffect.ThunderAndRain:
|
|
_LightningBolt.SetActive(false);
|
|
_ActivateRain();
|
|
break;
|
|
default: // Deactivate everything and leave
|
|
_Animator.SetBool("Lightning", false);
|
|
_LightningBolt.SetActive(false);
|
|
_DeactivateRain();
|
|
return;
|
|
}
|
|
|
|
_AudioManager.PlayMusic(MusicEventType.LightningRound);
|
|
_Animator.SetBool("Lightning", true);
|
|
|
|
SendCustomEventDelayedSeconds(nameof(ResetLightningRoundAnimation), 2.0f);
|
|
}
|
|
}
|
|
public void ResetLightningRoundAnimation()
|
|
{
|
|
_LightningBolt.SetActive(false);
|
|
_Animator.SetBool("Lightning", false);
|
|
}
|
|
|
|
|
|
private void _ActivateRain()
|
|
{
|
|
_Umbrella.gameObject.SetActive(true);
|
|
_Umbrella.Respawn();
|
|
_PersonalRaincloud.Play();
|
|
}
|
|
private void _DeactivateRain()
|
|
{
|
|
_Umbrella.gameObject.SetActive(false);
|
|
_PersonalRaincloud.Stop();
|
|
}
|
|
}
|