54 lines
2.2 KiB
C#
Raw Normal View History

2020-12-11 23:13:32 +00:00
using QSB.Player;
2021-04-11 17:05:02 +01:00
using QSB.TransformSync;
2020-11-03 21:33:48 +00:00
using UnityEngine;
2021-04-11 17:05:02 +01:00
namespace QSB.ShipSync.TransformSync
{
2021-04-21 11:02:17 +01:00
public class ShipTransformSync : QSBNetworkTransform
2020-12-02 21:29:53 +00:00
{
2021-04-21 19:06:00 +01:00
protected override float DistanceLeeway => 20f;
2020-12-11 23:13:13 +00:00
private Transform GetShipModel() => Locator.GetShipTransform();
2020-12-02 21:29:53 +00:00
2021-04-21 11:02:17 +01:00
protected override GameObject InitLocalTransform()
2021-03-09 19:45:00 +00:00
{
SectorSync.SetSectorDetector(Locator.GetShipDetector().GetComponent<SectorDetector>());
2021-04-21 11:02:17 +01:00
return GetShipModel().Find("Module_Cockpit/Geo_Cockpit/Cockpit_Geometry/Cockpit_Exterior").gameObject;
2021-03-09 19:45:00 +00:00
}
2020-12-02 21:29:53 +00:00
2021-04-21 11:02:17 +01:00
protected override GameObject InitRemoteTransform()
2020-12-02 21:29:53 +00:00
{
var shipModel = GetShipModel();
var remoteTransform = new GameObject("RemoteShipTransform").transform;
Instantiate(shipModel.Find("Module_Cockpit/Geo_Cockpit/Cockpit_Geometry/Cockpit_Exterior"), remoteTransform);
Instantiate(shipModel.Find("Module_Cabin/Geo_Cabin/Cabin_Geometry/Cabin_Exterior"), remoteTransform);
Instantiate(shipModel.Find("Module_Cabin/Geo_Cabin/Cabin_Tech/Cabin_Tech_Exterior"), remoteTransform);
Instantiate(shipModel.Find("Module_Supplies/Geo_Supplies/Supplies_Geometry/Supplies_Exterior"), remoteTransform);
Instantiate(shipModel.Find("Module_Engine/Geo_Engine/Engine_Geometry/Engine_Exterior"), remoteTransform);
var landingGearFront = Instantiate(shipModel.Find("Module_LandingGear/LandingGear_Front/Geo_LandingGear_Front"), remoteTransform);
var landingGearLeft = Instantiate(shipModel.Find("Module_LandingGear/LandingGear_Left/Geo_LandingGear_Left"), remoteTransform);
var landingGearRight = Instantiate(shipModel.Find("Module_LandingGear/LandingGear_Right/Geo_LandingGear_Right"), remoteTransform);
Destroy(landingGearFront.Find("LandingGear_FrontCollision").gameObject);
Destroy(landingGearLeft.Find("LandingGear_LeftCollision").gameObject);
Destroy(landingGearRight.Find("LandingGear_RightCollision").gameObject);
landingGearFront.localPosition
= landingGearLeft.localPosition
= landingGearRight.localPosition
+= Vector3.up * 3.762f;
2021-04-21 11:02:17 +01:00
return remoteTransform.gameObject;
2020-12-02 21:29:53 +00:00
}
public override bool IsReady => GetShipModel() != null
&& Player != null
&& QSBPlayerManager.PlayerExists(Player.PlayerId)
2021-04-18 18:46:55 +01:00
&& Player.PlayerStates.IsReady
2020-12-02 21:29:53 +00:00
&& NetId.Value != uint.MaxValue
&& NetId.Value != 0U;
}
2020-12-03 08:28:05 +00:00
}