mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-01 03:32:38 +00:00
Move remaining sector logic to SectorSync
This commit is contained in:
parent
2c1d0b1ea5
commit
22b6692642
@ -3,7 +3,7 @@ using UnityEngine.Networking;
|
||||
|
||||
namespace QSB {
|
||||
public abstract class MessageHandler: MonoBehaviour {
|
||||
public abstract short type { get; }
|
||||
protected abstract short type { get; }
|
||||
|
||||
public MessageHandler () {
|
||||
NetworkServer.RegisterHandler(SectorMessage.Type, OnReceiveMessage);
|
||||
|
@ -10,7 +10,7 @@ namespace QSB {
|
||||
|
||||
void Start () {
|
||||
QSB.Log("Start NetworkPlayer", netId.Value);
|
||||
SectorSync.playerSectors[netId.Value] = Locator.GetAstroObject(AstroObject.Name.TimberHearth).transform;
|
||||
SectorSync.SetSector(netId, Sector.Name.TimberHearth);
|
||||
|
||||
transform.parent = Locator.GetRootTransform();
|
||||
|
||||
@ -29,8 +29,7 @@ namespace QSB {
|
||||
public void EnterSector (Sector sector) {
|
||||
var name = sector.GetName();
|
||||
if (name != Sector.Name.Unnamed && name != Sector.Name.Ship && name != Sector.Name.Sun) {
|
||||
SectorSync.playerSectors[netId.Value] = SectorSync.GetSectorByName(sector.GetName());
|
||||
|
||||
SectorSync.SetSector(netId, sector.GetName());
|
||||
SectorMessage msg = new SectorMessage();
|
||||
msg.sectorId = (int) sector.GetName();
|
||||
msg.senderId = netId.Value;
|
||||
@ -47,7 +46,7 @@ namespace QSB {
|
||||
return;
|
||||
}
|
||||
|
||||
var sectorTransform = SectorSync.playerSectors[netId.Value];
|
||||
var sectorTransform = SectorSync.GetSector(netId);
|
||||
if (isLocalPlayer) {
|
||||
transform.position = sectorTransform.InverseTransformPoint(_body.position);
|
||||
transform.rotation = sectorTransform.InverseTransformRotation(_body.rotation);
|
||||
|
@ -4,16 +4,25 @@ using UnityEngine.Networking;
|
||||
|
||||
namespace QSB {
|
||||
public class SectorSync: MessageHandler {
|
||||
public override short type { get => MessageType.Sector; }
|
||||
public static Dictionary<uint, Transform> playerSectors;
|
||||
protected override short type { get => MessageType.Sector; }
|
||||
static Dictionary<uint, Transform> playerSectors;
|
||||
static Sector[] _allSectors;
|
||||
|
||||
void Awake () {
|
||||
playerSectors = new Dictionary<uint, Transform>();
|
||||
_allSectors = FindObjectsOfType<Sector>();
|
||||
}
|
||||
|
||||
public static Transform GetSectorByName (Sector.Name sectorName) {
|
||||
var sectors = FindObjectsOfType<Sector>();
|
||||
foreach (var sector in sectors) {
|
||||
public static void SetSector (NetworkInstanceId netId, Sector.Name sectorName) {
|
||||
playerSectors[netId.Value] = GetSectorByName(sectorName);
|
||||
}
|
||||
|
||||
public static Transform GetSector (NetworkInstanceId netId) {
|
||||
return playerSectors[netId.Value];
|
||||
}
|
||||
|
||||
static Transform GetSectorByName (Sector.Name sectorName) {
|
||||
foreach (var sector in _allSectors) {
|
||||
if (sectorName == sector.GetName()) {
|
||||
return sector.transform;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user