2020-12-11 23:13:32 +00:00
|
|
|
|
using QSB.EventsCore;
|
2020-11-03 21:33:48 +00:00
|
|
|
|
using QSB.Player;
|
2020-08-10 17:24:28 +00:00
|
|
|
|
using QSB.Tools;
|
2020-08-24 14:51:12 +00:00
|
|
|
|
using QSB.Utility;
|
2020-12-12 18:14:04 +00:00
|
|
|
|
using System.Linq;
|
2020-07-27 23:13:43 +00:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace QSB.TransformSync
|
|
|
|
|
{
|
2020-12-02 21:29:53 +00:00
|
|
|
|
public class PlayerCameraSync : TransformSync
|
|
|
|
|
{
|
2020-12-12 18:14:04 +00:00
|
|
|
|
protected void Start()
|
|
|
|
|
{
|
|
|
|
|
var lowestBound = QSBPlayerManager.GetSyncObjects<PlayerTransformSync>().Where(x => x.NetId.Value < NetId.Value).OrderBy(x => x.NetId.Value).Last();
|
|
|
|
|
NetIdentity.SetRootIdentity(lowestBound.NetIdentity);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-02 21:29:53 +00:00
|
|
|
|
protected override Transform InitLocalTransform()
|
|
|
|
|
{
|
|
|
|
|
var body = Locator.GetPlayerCamera().gameObject.transform;
|
2020-07-27 23:13:43 +00:00
|
|
|
|
|
2020-12-02 21:29:53 +00:00
|
|
|
|
Player.Camera = body.gameObject;
|
2020-07-27 23:13:43 +00:00
|
|
|
|
|
2020-12-02 21:29:53 +00:00
|
|
|
|
Player.IsReady = true;
|
|
|
|
|
GlobalMessenger<bool>.FireEvent(EventNames.QSBPlayerReady, true);
|
|
|
|
|
DebugLog.DebugWrite("PlayerCameraSync init done - Request state!");
|
|
|
|
|
GlobalMessenger.FireEvent(EventNames.QSBPlayerStatesRequest);
|
2020-08-10 10:45:24 +00:00
|
|
|
|
|
2020-12-02 21:29:53 +00:00
|
|
|
|
return body;
|
|
|
|
|
}
|
2020-07-27 23:13:43 +00:00
|
|
|
|
|
2020-12-02 21:29:53 +00:00
|
|
|
|
protected override Transform InitRemoteTransform()
|
|
|
|
|
{
|
|
|
|
|
var body = new GameObject("RemotePlayerCamera");
|
2020-07-27 23:13:43 +00:00
|
|
|
|
|
2020-12-02 21:29:53 +00:00
|
|
|
|
PlayerToolsManager.Init(body.transform);
|
2020-07-27 23:13:43 +00:00
|
|
|
|
|
2020-12-02 21:29:53 +00:00
|
|
|
|
Player.Camera = body;
|
2020-07-27 23:13:43 +00:00
|
|
|
|
|
2020-12-02 21:29:53 +00:00
|
|
|
|
return body.transform;
|
|
|
|
|
}
|
2020-07-27 23:13:43 +00:00
|
|
|
|
|
2020-12-02 21:29:53 +00:00
|
|
|
|
public override bool IsReady => Locator.GetPlayerTransform() != null
|
|
|
|
|
&& Player != null
|
|
|
|
|
&& QSBPlayerManager.PlayerExists(Player.PlayerId)
|
|
|
|
|
&& NetId.Value != uint.MaxValue
|
|
|
|
|
&& NetId.Value != 0U;
|
|
|
|
|
}
|
2020-12-03 08:28:05 +00:00
|
|
|
|
}
|