Redid vent code to work better and like work in general. Knight animation now pauses for a second. Knights no longer trigger the default scarlet vent animation. Revenants now spawn at a vent if no knights exist.
146 lines
4.4 KiB
C#
146 lines
4.4 KiB
C#
using ScarletMansion.GamePatch.Components.TreasureRoom;
|
|
using ScarletMansion.GamePatch.Managers;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Unity.Netcode;
|
|
using UnityEngine;
|
|
|
|
namespace ScarletMansion.GamePatch.Components {
|
|
public class ScarletRadio : NetworkBehaviour{
|
|
|
|
public TreasureRoomRadioEvent treasureRoomEvent;
|
|
|
|
[Header("Networked Values")]
|
|
public int volume;
|
|
public bool playing;
|
|
public int audioIndex;
|
|
|
|
[Header("Songs")]
|
|
public AudioClip[] audioClips;
|
|
|
|
[Header("References")]
|
|
public AudioSource audioSource;
|
|
public float maxVolume = 1f;
|
|
public Transform onOffSwitchTransform;
|
|
public Transform volumeSwitchTransform;
|
|
public Transform volumeDialTransform;
|
|
public Transform tuneSwitchTransform;
|
|
private float onOffSwitchTransformX;
|
|
private float volumeSwitchTransformX;
|
|
private float volumeDialTransformX;
|
|
private float onOffSwitchTransforX;
|
|
|
|
[Header("Switch Values")]
|
|
public Vector2 onOffSwitchRotation;
|
|
public Vector2 volumeSwitchRotation;
|
|
public Vector2 volumeDialRotation;
|
|
public Vector2 tuneSwitchRotation;
|
|
|
|
void Start() {
|
|
audioSource.volume = maxVolume * (volume * 0.1f);
|
|
|
|
var inst = ScarletGenericManager.Instance;
|
|
if (inst) {
|
|
audioClips = inst.radioAudioClips;
|
|
}
|
|
}
|
|
|
|
public override void OnNetworkSpawn() {
|
|
if (IsOwner) {
|
|
ToggleOnOffSwitchClientRpc(UnityEngine.Random.value > 0.9f);
|
|
ToggleVolumeSwitchClientRpc(UnityEngine.Random.Range(3, 7));
|
|
|
|
if (audioClips.Length == 0) return;
|
|
ToggleSongSwitchClientRpc(UnityEngine.Random.Range(0, audioClips.Length));
|
|
}
|
|
}
|
|
|
|
void RotateTransformTo(Transform dial, ref float current, float towards){
|
|
current = Mathf.Lerp(current, towards, Time.deltaTime * 2f);
|
|
var v = new Vector3(current, 0f, 0f);
|
|
dial.localEulerAngles = v;
|
|
}
|
|
|
|
void RotateTransformTo(Transform dial, ref float current, Vector2 lerpVector, float lerp){
|
|
RotateTransformTo(dial, ref current, Mathf.Lerp(lerpVector.x, lerpVector.y, lerp));
|
|
}
|
|
|
|
void Update(){
|
|
RotateTransformTo(onOffSwitchTransform, ref onOffSwitchTransformX, playing ? onOffSwitchRotation.y : onOffSwitchRotation.x);
|
|
RotateTransformTo(volumeSwitchTransform, ref volumeSwitchTransformX, volumeSwitchRotation, volume * 0.1f);
|
|
RotateTransformTo(volumeDialTransform, ref volumeDialTransformX, volumeDialRotation, volume * 0.1f);
|
|
RotateTransformTo(tuneSwitchTransform, ref onOffSwitchTransforX, tuneSwitchRotation, (float)audioIndex / (audioClips.Length - 1));
|
|
}
|
|
|
|
public void ToggleOnOffSwitch(){
|
|
ToggleOnOffSwitchServerRpc();
|
|
}
|
|
|
|
public void ToggleVolumeSwitchLeft() {
|
|
ToggleVolumeSwitchServerRpc(-1);
|
|
}
|
|
|
|
public void ToggleVolumeSwitchRight() {
|
|
ToggleVolumeSwitchServerRpc(1);
|
|
}
|
|
|
|
public void ToggleSongSwitch(){
|
|
ToggleSongSwitchServerRpc();
|
|
}
|
|
|
|
[ServerRpc(RequireOwnership = false)]
|
|
public void ToggleOnOffSwitchServerRpc(){
|
|
ToggleOnOffSwitchClientRpc(!playing);
|
|
treasureRoomEvent?.UpdateTreasureDoorStatus();
|
|
}
|
|
|
|
[ClientRpc]
|
|
public void ToggleOnOffSwitchClientRpc(bool playing){
|
|
this.playing = playing;
|
|
if (playing) AttemptTurnOn();
|
|
else AttemptTurnOff();
|
|
|
|
}
|
|
|
|
[ServerRpc(RequireOwnership = false)]
|
|
public void ToggleVolumeSwitchServerRpc(int count){
|
|
ToggleVolumeSwitchClientRpc(Mathf.Clamp(volume + count, 0, 10));
|
|
treasureRoomEvent?.UpdateTreasureDoorStatus();
|
|
}
|
|
|
|
[ClientRpc]
|
|
public void ToggleVolumeSwitchClientRpc(int volume){
|
|
this.volume = volume;
|
|
audioSource.volume = maxVolume * (volume * 0.1f);
|
|
}
|
|
|
|
[ServerRpc(RequireOwnership = false)]
|
|
public void ToggleSongSwitchServerRpc(){
|
|
if (audioClips.Length == 0) return;
|
|
|
|
ToggleSongSwitchClientRpc((audioIndex + 1) % audioClips.Length);
|
|
treasureRoomEvent?.UpdateTreasureDoorStatus();
|
|
}
|
|
|
|
[ClientRpc]
|
|
public void ToggleSongSwitchClientRpc(int audioIndex){
|
|
this.audioIndex = audioIndex;
|
|
|
|
if (playing && audioSource.isPlaying) audioSource.Stop();
|
|
audioSource.clip = audioClips[audioIndex];
|
|
AttemptTurnOn();
|
|
}
|
|
|
|
public void AttemptTurnOff(){
|
|
if (!playing && audioSource.isPlaying) audioSource.Stop();
|
|
}
|
|
|
|
public void AttemptTurnOn(){
|
|
if (playing && !audioSource.isPlaying) audioSource.Play();
|
|
}
|
|
|
|
}
|
|
}
|