2020-08-07 20:39:07 +01:00
using QSB.Tools ;
using UnityEngine ;
namespace QSB.TransformSync
{
public class PlayerProbeSync : TransformSync
{
public static PlayerProbeSync LocalInstance { get ; private set ; }
2020-08-18 21:31:14 +02:00
protected override uint PlayerIdOffset = > 3 ;
2020-08-20 19:31:10 +01:00
2020-08-07 20:39:07 +01:00
public Transform bodyTransform ;
public override void OnStartLocalPlayer ( )
{
LocalInstance = this ;
}
private Transform GetProbe ( )
{
return Locator . GetProbe ( ) . transform . Find ( "CameraPivot" ) . Find ( "Geometry" ) ;
}
protected override Transform InitLocalTransform ( )
{
var body = GetProbe ( ) ;
bodyTransform = body ;
Player . ProbeBody = body . gameObject ;
return body ;
}
protected override Transform InitRemoteTransform ( )
{
2020-08-07 22:39:50 +02:00
var probe = GetProbe ( ) ;
probe . gameObject . SetActive ( false ) ;
var body = Instantiate ( probe ) ;
probe . gameObject . SetActive ( true ) ;
Destroy ( body . GetComponentInChildren < ProbeAnimatorController > ( ) ) ;
2020-08-07 20:39:07 +01:00
2020-08-08 12:25:09 +02:00
PlayerToolsManager . CreateProbe ( body , Player ) ;
2020-08-07 20:39:07 +01:00
bodyTransform = body ;
Player . ProbeBody = body . gameObject ;
return body ;
}
protected override void UpdateTransform ( )
{
base . UpdateTransform ( ) ;
if ( Player . GetState ( State . ProbeActive ) )
{
return ;
}
if ( hasAuthority )
{
2020-08-21 14:01:31 +01:00
transform . position = ReferenceSector . Transform . InverseTransformPoint ( Player . Camera . transform . position ) ; // this looks shitty, but fixes the NRE from ProbeLauncher
2020-08-07 20:39:07 +01:00
return ;
}
if ( SyncedTransform . position = = Vector3 . zero | |
SyncedTransform . position = = Locator . GetAstroObject ( AstroObject . Name . Sun ) . transform . position )
{
return ;
}
2020-08-21 14:01:31 +01:00
SyncedTransform . localPosition = ReferenceSector . Transform . InverseTransformPoint ( Player . Camera . transform . position ) ; // this looks shitty, but fixes the NRE from ProbeLauncher
2020-08-07 20:39:07 +01:00
}
2020-08-18 21:29:31 +01:00
public override bool IsReady = > Locator . GetProbe ( ) ! = null & & PlayerRegistry . PlayerExists ( PlayerId ) & & Player . IsReady ;
2020-08-07 20:39:07 +01:00
}
}