add remote ruleset detector

This commit is contained in:
_nebula 2023-03-04 13:30:33 +00:00
parent 6dcb938ad5
commit 94e47a692c
4 changed files with 78 additions and 0 deletions

Binary file not shown.

View File

@ -41,6 +41,7 @@ public partial class PlayerInfo
public ThrusterLightTracker ThrusterLightTracker;
public bool FlyingShip => ShipManager.Instance.CurrentFlyer == PlayerId;
public bool FlyingModelShip => ModelShipManager.Instance.CurrentFlyer == PlayerId;
public RemotePlayerRulesetDetector RulesetDetector { get; set; }
public PlayerInfo(PlayerTransformSync transformSync)
{

View File

@ -0,0 +1,76 @@
using QSB.Utility;
using System.Collections.Generic;
using UnityEngine;
namespace QSB.Player;
[UsedInUnityProject]
public class RemotePlayerRulesetDetector : Detector
{
private PlanetoidRuleset _closestPlanetoidRuleset;
private List<PlanetoidRuleset> _planetoidRulesets;
public override void Awake()
{
base.Awake();
_planetoidRulesets = new List<PlanetoidRuleset>(8);
}
public override void AddVolume(EffectVolume volume)
{
if ((volume as RulesetVolume) == null)
{
return;
}
base.AddVolume(volume);
if (volume.GetType() == typeof(PlanetoidRuleset))
{
DebugLog.DebugWrite($"ADD TO {volume.name}");
_planetoidRulesets.Add((PlanetoidRuleset)volume);
UpdateClosestPlanetoidRuleset();
}
}
public override void RemoveVolume(EffectVolume volume)
{
if ((volume as RulesetVolume) == null)
{
return;
}
base.RemoveVolume(volume);
if (volume.GetType() == typeof(PlanetoidRuleset))
{
DebugLog.DebugWrite($"REMOVE FROM {volume.name}");
_planetoidRulesets.Remove((PlanetoidRuleset)volume);
UpdateClosestPlanetoidRuleset();
}
}
public PlanetoidRuleset GetPlanetoidRuleset() => _closestPlanetoidRuleset;
private void Update()
{
if (_planetoidRulesets.Count > 1)
{
UpdateClosestPlanetoidRuleset();
}
}
private void UpdateClosestPlanetoidRuleset()
{
DebugLog.DebugWrite($"UpdateClosetPlanetoidRuleset - count:{_planetoidRulesets.Count}");
_closestPlanetoidRuleset = null;
var num = float.PositiveInfinity;
for (var i = 0; i < _planetoidRulesets.Count; i++)
{
var num2 = Vector3.SqrMagnitude(_planetoidRulesets[i].transform.position - transform.position);
if (num2 < num)
{
_closestPlanetoidRuleset = _planetoidRulesets[i];
num = num2;
}
}
}
}

View File

@ -53,6 +53,7 @@ public static class RemotePlayerCreation
player.Body = REMOTE_Player_Body;
player.ThrusterLightTracker = player.Body.GetComponentInChildren<ThrusterLightTracker>();
player.FluidDetector = REMOTE_PlayerDetector.GetComponent<RemotePlayerFluidDetector>();
player.RulesetDetector = REMOTE_PlayerDetector.GetComponent<RemotePlayerRulesetDetector>();
player.AnimationSync.InitRemote(REMOTE_Traveller_HEA_Player_v2.transform);