quantum-space-buddies/QSB/NetworkPlayer.cs

50 lines
1.8 KiB
C#
Raw Normal View History

using System;
using System.Linq;
using UnityEngine;
2020-02-10 23:03:28 +01:00
using UnityEngine.Networking;
namespace QSB {
public class NetworkPlayer: NetworkBehaviour {
Transform _body;
public static NetworkPlayer localInstance { get; private set; }
2020-02-10 23:03:28 +01:00
void Start () {
2020-02-13 20:23:26 +01:00
QSB.Log("Start NetworkPlayer", netId.Value);
2020-02-13 22:11:20 +01:00
SectorSync.SetSector(netId, Sector.Name.TimberHearth, true);
2020-02-10 23:03:28 +01:00
2020-02-12 22:32:16 +01:00
transform.parent = Locator.GetRootTransform();
2020-02-10 23:03:28 +01:00
var player = Locator.GetPlayerBody().transform.Find("Traveller_HEA_Player_v2");
if (isLocalPlayer) {
localInstance = this;
2020-02-10 23:03:28 +01:00
_body = player;
} else {
_body = Instantiate(player);
2020-02-11 14:38:08 +01:00
_body.GetComponent<PlayerAnimController>().enabled = false;
2020-02-11 14:14:17 +01:00
_body.Find("player_mesh_noSuit:Traveller_HEA_Player/player_mesh_noSuit:Player_Head").gameObject.layer = 0;
2020-02-12 22:42:42 +01:00
_body.Find("Traveller_Mesh_v01:Traveller_Geo/Traveller_Mesh_v01:PlayerSuit_Helmet").gameObject.layer = 0;
2020-02-10 23:03:28 +01:00
}
}
2020-02-12 20:05:08 +01:00
public void EnterSector (Sector sector) {
2020-02-13 22:18:41 +01:00
SectorSync.SetSector(netId, sector.GetName());
2020-02-12 20:05:08 +01:00
}
2020-02-10 23:03:28 +01:00
void Update () {
if (!_body) {
return;
}
var sectorTransform = SectorSync.GetSector(netId);
2020-02-10 23:03:28 +01:00
if (isLocalPlayer) {
2020-02-12 22:20:28 +01:00
transform.position = sectorTransform.InverseTransformPoint(_body.position);
transform.rotation = sectorTransform.InverseTransformRotation(_body.rotation);
2020-02-10 23:03:28 +01:00
} else {
2020-02-12 22:32:16 +01:00
_body.parent = sectorTransform;
2020-02-12 22:20:28 +01:00
_body.position = sectorTransform.TransformPoint(transform.position);
_body.rotation = sectorTransform.rotation * transform.rotation;
2020-02-10 23:03:28 +01:00
}
}
}
}