Skip to content

Commit

Permalink
feat(vhf): elec support
Browse files Browse the repository at this point in the history
  • Loading branch information
Misaka-L committed Nov 10, 2024
1 parent 817f9cd commit 4599a91
Show file tree
Hide file tree
Showing 4 changed files with 611 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public void _OnFirstInit() {
isReceiveBool.subscribe(this, nameof(_OnAudioSourceStatusChange));
}

foreach (var isReceiveBool in _isTransmit) {
isReceiveBool.subscribe(this, nameof(_OnAudioSourceStatusChange));
foreach (var isTransmitBool in _isTransmit) {
isTransmitBool.subscribe(this, nameof(_OnAudioSourceStatusChange));
}

foreach (var frequencyFloat in _frequency) {
Expand All @@ -31,7 +31,7 @@ public void _OnFirstInit() {
}

[PublicAPI]
public void _OnFInit() {
public void _OnInit() {
_OnAudioSourceStatusChange();
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using JetBrains.Annotations;
using tech.gyoku.FDMi.core;
using UdonSharp;
using UnityEngine;
using URC;
using VRC.SDKBase;

namespace VRChatAerospaceUniversity.V320.Avionics.Communication.AudioSource {
[UdonBehaviourSyncMode(BehaviourSyncMode.None)]
[UdonBehaviourSyncMode(BehaviourSyncMode.Manual)]
[AircraftLifecycleReceiver]
public class UdonRadioCommunicationAudioSource : UdonSharpBehaviour {
public float defaultFrequency = 118.0f;
Expand All @@ -15,29 +17,68 @@ public float Frequency {
set => _transceiver._SetFrequency(value);
}

[UdonSynced] [SerializeField] [HideInInspector] private bool _receive;
[PublicAPI]
public bool Receive {
get => _transceiver._GetReceive();
set => _transceiver._SetReceive(value);
get => _receive;
set {
TakeOwnership();

_receive = value;
_UpdateReceiveTransmit();

RequestSerialization();
}
}

[UdonSynced] [SerializeField] [HideInInspector] private bool _transmit;
[PublicAPI]
public bool Transmit {
get => _transceiver._GetTransmit();
set => _transceiver._SetTransmit(value);
get => _transmit;
set {
TakeOwnership();

_transmit = value;
_UpdateReceiveTransmit();

RequestSerialization();
}
}

[SerializeField] private Transceiver _transceiver;
[SerializeField] private FDMiBool _isPowered;

public void _UpdateReceiveTransmit() {
var isPowered = !_isPowered || _isPowered.Data;

_transceiver._SetTransmit(isPowered && _transmit);
_transceiver._SetReceive(isPowered && _receive);
}

[PublicAPI]
private void _OnPowerStateChanged() => _UpdateReceiveTransmit();
public override void OnDeserialization() => _UpdateReceiveTransmit();

[PublicAPI]
public void _OnInit() {
if (_isPowered) {
_isPowered.subscribe(this, nameof(_UpdateReceiveTransmit));
}

// Delay 4s due to
// https://github.com/esnya/UdonRadioCommunications/blob/v5.0.0/Packages/com.nekometer.esnya.udon-radio-communications/Scripts/UdonRadioCommunication.cs#L63
SendCustomEventDelayedSeconds(nameof(_SetDefaultFrequency), 4);
_UpdateReceiveTransmit();
}

public void _SetDefaultFrequency() {
_transceiver.Frequency = defaultFrequency;
}

private void TakeOwnership() {
if (Networking.IsOwner(gameObject)) return;

Networking.SetOwner(Networking.LocalPlayer, gameObject);
}
}
}
Loading

0 comments on commit 4599a91

Please sign in to comment.