mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-30 03:32:47 +00:00
add remote ruleset detector
This commit is contained in:
parent
6dcb938ad5
commit
94e47a692c
Binary file not shown.
@ -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)
|
||||
{
|
||||
|
76
QSB/Player/RemotePlayerRulesetDetector.cs
Normal file
76
QSB/Player/RemotePlayerRulesetDetector.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user