quantum-space-buddies/QSB/PoolSync/CustomNomaiRemoteCameraStreaming.cs

68 lines
1.8 KiB
C#
Raw Normal View History

2021-03-06 23:59:44 +00:00
using OWML.Utils;
namespace QSB.PoolSync
2021-03-06 23:59:44 +00:00
{
2021-03-07 09:27:23 +00:00
internal class CustomNomaiRemoteCameraStreaming : SectoredMonoBehaviour
2021-03-06 23:59:44 +00:00
{
public CustomNomaiRemoteCameraPlatform _remoteCameraPlatform
{
get => _oldStreaming.GetValue<NomaiRemoteCameraPlatform>("_remoteCameraPlatform").GetComponent<CustomNomaiRemoteCameraPlatform>();
set => _oldStreaming.SetValue("_remoteCameraPlatform", value.GetComponent<NomaiRemoteCameraStreaming>());
}
private StreamingGroup _streamingGroup;
private NomaiRemoteCameraStreaming _oldStreaming;
2021-03-07 20:12:38 +00:00
private bool _hasLoadedAssets;
2021-03-06 23:59:44 +00:00
protected override void Awake()
{
base.Awake();
_oldStreaming = GetComponent<NomaiRemoteCameraStreaming>();
SetSector(_oldStreaming.GetSector());
}
2021-03-07 20:13:59 +00:00
private void Start()
2021-03-07 20:12:38 +00:00
=> enabled = false;
2021-03-06 23:59:44 +00:00
private void FixedUpdate()
{
2021-03-07 20:12:38 +00:00
var stone = _remoteCameraPlatform.GetSocketedStone();
if (stone == null)
2021-03-06 23:59:44 +00:00
{
2021-03-07 20:12:38 +00:00
if (_hasLoadedAssets)
2021-03-06 23:59:44 +00:00
{
2021-03-07 20:12:38 +00:00
_hasLoadedAssets = false;
_streamingGroup.ReleaseRequiredAssets();
_streamingGroup.ReleaseGeneralAssets();
_streamingGroup = null;
2021-03-06 23:59:44 +00:00
}
}
2021-03-07 20:12:38 +00:00
else
2021-03-06 23:59:44 +00:00
{
2021-03-07 20:12:38 +00:00
if (!_hasLoadedAssets)
{
_hasLoadedAssets = true;
_streamingGroup = StreamingGroup.GetStreamingGroup(NomaiRemoteCameraStreaming.NomaiRemoteCameraPlatformIDToSceneName(stone.GetRemoteCameraID()));
_streamingGroup.RequestRequiredAssets(0);
_streamingGroup.RequestGeneralAssets(0);
}
2021-03-06 23:59:44 +00:00
}
}
protected override void OnSectorOccupantAdded(SectorDetector sectorDetector)
{
if (sectorDetector.GetOccupantType() == DynamicOccupant.Player && StreamingManager.isStreamingEnabled)
{
enabled = true;
}
}
protected override void OnSectorOccupantRemoved(SectorDetector sectorDetector)
{
if (sectorDetector.GetOccupantType() == DynamicOccupant.Player)
{
enabled = false;
}
}
}
}