2022-05-28 19:39:42 +00:00
using Cysharp.Threading.Tasks ;
using Mirror ;
using OWML.Common ;
using QSB.ModelShip.TransformSync ;
using QSB.Utility ;
using QSB.WorldSync ;
using System.Threading ;
namespace QSB.ModelShip ;
2023-07-28 18:30:57 +00:00
public class ModelShipManager : WorldObjectManager
2022-05-28 19:39:42 +00:00
{
public override WorldObjectScene WorldObjectScene = > WorldObjectScene . SolarSystem ;
public override bool DlcOnly = > false ;
2022-08-28 05:44:40 +00:00
public static ModelShipManager Instance ;
public uint CurrentFlyer
{
get = > _currentFlyer ;
set
{
if ( _currentFlyer ! = uint . MaxValue & & value ! = uint . MaxValue )
{
DebugLog . ToConsole ( $"Warning - Trying to set current model ship flyer while someone is still flying? Current:{_currentFlyer}, New:{value}" , MessageType . Warning ) ;
}
_currentFlyer = value ;
}
}
private uint _currentFlyer = uint . MaxValue ;
public void Start ( )
{
Instance = this ;
}
2022-05-28 19:39:42 +00:00
public override async UniTask BuildWorldObjects ( OWScene scene , CancellationToken ct )
2022-08-05 05:21:46 +00:00
{
if ( QSBCore . IsHost )
{
2023-05-08 18:38:24 +00:00
Instantiate ( QSBNetworkManager . singleton . ModelShipPrefab ) . SpawnWithServerOwnership ( ) ;
2022-08-05 05:21:46 +00:00
}
2022-08-28 04:56:18 +00:00
2022-08-28 05:44:40 +00:00
// Is 0 by default -> 2D (bad)
2022-08-28 04:56:18 +00:00
QSBWorldSync . GetUnityObject < RemoteFlightConsole > ( ) . _consoleAudio . spatialBlend = 1 ;
2022-08-05 05:21:46 +00:00
}
public override void UnbuildWorldObjects ( )
2022-05-28 19:39:42 +00:00
{
if ( QSBCore . IsHost )
{
if ( ModelShipTransformSync . LocalInstance ! = null )
{
if ( ModelShipTransformSync . LocalInstance . gameObject = = null )
{
DebugLog . ToConsole ( $"Warning - ShipTransformSync's LocalInstance is not null, but it's gameobject is null!" , MessageType . Warning ) ;
return ;
}
NetworkServer . Destroy ( ModelShipTransformSync . LocalInstance . gameObject ) ;
}
}
}
2022-08-05 05:21:46 +00:00
}