mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-20 15:41:01 +00:00
Probe + Launcher (with associated events/transformsync changes) (#117)
* Added probe + probe launcher, with general event/transformsync/player refactors and improvements
This commit is contained in:
parent
c05e47637a
commit
5dce7a8a03
@ -3,7 +3,7 @@ CRC: 1039691058
|
||||
Hashes:
|
||||
AssetFileHash:
|
||||
serializedVersion: 2
|
||||
Hash: 00a2687e5663952c31bb8ecde86d6102
|
||||
Hash: 09f9f4f247158b6c3e422fc20dae56a0
|
||||
TypeTreeHash:
|
||||
serializedVersion: 2
|
||||
Hash: 737950008f8470fd33adbb15e41f47ec
|
||||
|
Binary file not shown.
@ -1,9 +1,9 @@
|
||||
ManifestFileVersion: 0
|
||||
CRC: 365022443
|
||||
CRC: 561788810
|
||||
Hashes:
|
||||
AssetFileHash:
|
||||
serializedVersion: 2
|
||||
Hash: c63039edb46f956040503af13cba1820
|
||||
Hash: bde832827d2a891a56083d4ec38bfb92
|
||||
TypeTreeHash:
|
||||
serializedVersion: 2
|
||||
Hash: 47ee499ae8022a6b96ca6a5fd541f154
|
||||
@ -26,6 +26,7 @@ ClassTypes:
|
||||
Assets:
|
||||
- Assets/NetworkPlayer.prefab
|
||||
- Assets/NetworkCameraRoot.prefab
|
||||
- Assets/NetworkProbe.prefab
|
||||
- Assets/NetworkManager.prefab
|
||||
- Assets/NetworkShip.prefab
|
||||
Dependencies: []
|
||||
|
@ -44,20 +44,20 @@ namespace QSB.Events
|
||||
|
||||
private void OnClientReceiveMessage(EventMessage message)
|
||||
{
|
||||
var player = PlayerRegistry.GetPlayer(message.SenderId);
|
||||
if (message.SenderId == PlayerRegistry.LocalPlayer.NetId)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var player = PlayerRegistry.GetPlayer(message.SenderId);
|
||||
switch ((EventType)message.EventType)
|
||||
{
|
||||
case EventType.TurnOnFlashlight:
|
||||
player.FlashLight.TurnOn();
|
||||
player.UpdateState(State.Flashlight, true);
|
||||
player.FlashLight.TurnOn();
|
||||
break;
|
||||
case EventType.TurnOffFlashlight:
|
||||
player.FlashLight.TurnOff();
|
||||
player.UpdateState(State.Flashlight, false);
|
||||
player.FlashLight.TurnOff();
|
||||
break;
|
||||
case EventType.SuitUp:
|
||||
player.UpdateState(State.Suit, true);
|
||||
@ -81,6 +81,22 @@ namespace QSB.Events
|
||||
player.UpdateState(State.Translator, false);
|
||||
player.Translator.UnequipTool();
|
||||
break;
|
||||
case EventType.ProbeLauncherEquipped:
|
||||
player.UpdateState(State.ProbeLauncher, true);
|
||||
player.ProbeLauncher.EquipTool();
|
||||
break;
|
||||
case EventType.ProbeLauncherUnequipped:
|
||||
player.UpdateState(State.ProbeLauncher, false);
|
||||
player.ProbeLauncher.UnequipTool();
|
||||
break;
|
||||
case EventType.RetrieveProbe:
|
||||
player.UpdateState(State.ProbeActive, false);
|
||||
player.Probe.Deactivate();
|
||||
break;
|
||||
case EventType.LaunchProbe:
|
||||
player.UpdateState(State.ProbeActive, true);
|
||||
player.Probe.Activate();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,40 +1,112 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.Events
|
||||
{
|
||||
public class EventListener : MonoBehaviour
|
||||
{
|
||||
public static EventListener LocalInstance;
|
||||
|
||||
public List<EventType> ExclusionList = new List<EventType>
|
||||
private readonly Dictionary<EventType, List<Type>> _typedList = new Dictionary<EventType, List<Type>>
|
||||
{
|
||||
EventType.EquipSignalscope
|
||||
{ EventType.EquipSignalscope, new List<Type> { typeof(Signalscope)} },
|
||||
{ EventType.ProbeLauncherEquipped, new List<Type> { typeof(ProbeLauncher) } },
|
||||
{ EventType.ProbeLauncherUnequipped, new List<Type> { typeof(ProbeLauncher) } },
|
||||
{ EventType.RetrieveProbe, new List<Type> { typeof(SurveyorProbe) } },
|
||||
{ EventType.LaunchProbe, new List<Type> { typeof(SurveyorProbe) } }
|
||||
};
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
LocalInstance = this;
|
||||
foreach (var item in Enum.GetNames(typeof(EventType)))
|
||||
{
|
||||
if (!ExclusionList.Contains((EventType)Enum.Parse(typeof(EventType), item)))
|
||||
if (!_typedList.Keys.Contains((EventType)Enum.Parse(typeof(EventType), item)))
|
||||
{
|
||||
GlobalMessenger.AddListener(item, () => SendEvent(item));
|
||||
}
|
||||
}
|
||||
EquipSignalscope();
|
||||
|
||||
foreach (var item in _typedList)
|
||||
{
|
||||
InvokeGenericMethod(item.Key, item.Value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void InvokeGenericMethod(EventType eventType, List<Type> items)
|
||||
{
|
||||
var oldMethod = GetGenericMethod(typeof(EventListener), "Listen", items.Count);
|
||||
var newMethod = oldMethod.MakeGenericMethod(items.ToArray());
|
||||
newMethod.Invoke(this, new[] { (object)Enum.GetName(typeof(EventType), eventType) });
|
||||
}
|
||||
|
||||
private void SendEvent(string eventName)
|
||||
{
|
||||
EventHandler.LocalInstance.Send((EventType)Enum.Parse(typeof(EventType), eventName));
|
||||
var eventType = (EventType)Enum.Parse(typeof(EventType), eventName);
|
||||
var player = PlayerRegistry.LocalPlayer;
|
||||
EventHandler.LocalInstance.Send(eventType);
|
||||
switch (eventType)
|
||||
{
|
||||
case EventType.TurnOnFlashlight:
|
||||
player.UpdateState(State.Flashlight, true);
|
||||
break;
|
||||
case EventType.TurnOffFlashlight:
|
||||
player.UpdateState(State.Flashlight, false);
|
||||
break;
|
||||
case EventType.SuitUp:
|
||||
player.UpdateState(State.Suit, true);
|
||||
break;
|
||||
case EventType.RemoveSuit:
|
||||
player.UpdateState(State.Suit, false);
|
||||
break;
|
||||
case EventType.EquipSignalscope:
|
||||
player.UpdateState(State.Signalscope, true);
|
||||
break;
|
||||
case EventType.UnequipSignalscope:
|
||||
player.UpdateState(State.Signalscope, false);
|
||||
break;
|
||||
case EventType.EquipTranslator:
|
||||
player.UpdateState(State.Translator, true);
|
||||
break;
|
||||
case EventType.UnequipTranslator:
|
||||
player.UpdateState(State.Translator, false);
|
||||
break;
|
||||
case EventType.ProbeLauncherEquipped:
|
||||
player.UpdateState(State.ProbeLauncher, true);
|
||||
break;
|
||||
case EventType.ProbeLauncherUnequipped:
|
||||
player.UpdateState(State.ProbeLauncher, false);
|
||||
break;
|
||||
case EventType.RetrieveProbe:
|
||||
player.UpdateState(State.ProbeActive, false);
|
||||
break;
|
||||
case EventType.LaunchProbe:
|
||||
player.UpdateState(State.ProbeActive, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void EquipSignalscope()
|
||||
public void Listen<T>(string eventName)
|
||||
{
|
||||
GlobalMessenger<Signalscope>.AddListener("EquipSignalscope", (Signalscope scope) => SendEvent("EquipSignalscope"));
|
||||
GlobalMessenger<T>.AddListener(eventName, var => SendEvent(eventName));
|
||||
}
|
||||
|
||||
public void Listen<T, TU>(string eventName)
|
||||
{
|
||||
GlobalMessenger<T, TU>.AddListener(eventName, (var, var2) => SendEvent(eventName));
|
||||
}
|
||||
|
||||
private MethodInfo GetGenericMethod(Type type, string methodName, int typeCount)
|
||||
{
|
||||
var methods = type.GetMethods()
|
||||
.Where(m => m.Name == methodName && m.IsGenericMethodDefinition)
|
||||
.Select(m => new { m, typeParams = m.GetGenericArguments() })
|
||||
.Select(t => new { t, normalParams = t.m.GetParameters() })
|
||||
.Where(t => t.t.typeParams.Length == typeCount)
|
||||
.Select(t => t.t.m);
|
||||
|
||||
return methods.Single();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,12 @@
|
||||
EquipSignalscope,
|
||||
UnequipSignalscope,
|
||||
EquipTranslator,
|
||||
UnequipTranslator
|
||||
UnequipTranslator,
|
||||
ProbeLauncherEquipped,
|
||||
ProbeLauncherUnequipped,
|
||||
RetrieveProbe,
|
||||
LaunchProbe,
|
||||
QSBOnProbeWarp,
|
||||
QSBOnProbeAnchor
|
||||
}
|
||||
}
|
||||
|
@ -10,9 +10,12 @@ namespace QSB
|
||||
public uint NetId { get; }
|
||||
public GameObject Body { get; set; }
|
||||
public GameObject Camera { get; set; }
|
||||
public GameObject ProbeBody { get; set; }
|
||||
public QSBProbe Probe { get; set; }
|
||||
public QSBFlashlight FlashLight => Camera.GetComponentInChildren<QSBFlashlight>();
|
||||
public QSBTool Signalscope => GetToolByType(ToolType.Signalscope);
|
||||
public QSBTool Translator => GetToolByType(ToolType.Translator);
|
||||
public QSBTool ProbeLauncher => GetToolByType(ToolType.ProbeLauncher);
|
||||
public string Name { get; set; }
|
||||
public bool IsReady { get; set; }
|
||||
public State State { get; private set; }
|
||||
@ -36,10 +39,14 @@ namespace QSB
|
||||
State = states;
|
||||
}
|
||||
|
||||
public bool GetState(State state)
|
||||
{
|
||||
return FlagsHelper.IsSet(State, state);
|
||||
}
|
||||
|
||||
private QSBTool GetToolByType(ToolType type)
|
||||
{
|
||||
return Camera.GetComponentsInChildren<QSBTool>().First(x => x.Type == type);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -114,8 +114,10 @@
|
||||
<Compile Include="Animation\AnimTriggerMessage.cs" />
|
||||
<Compile Include="Animation\AnimTrigger.cs" />
|
||||
<Compile Include="Tools\QSBFlashlight.cs" />
|
||||
<Compile Include="Tools\QSBProbe.cs" />
|
||||
<Compile Include="Tools\QSBTool.cs" />
|
||||
<Compile Include="Tools\ToolType.cs" />
|
||||
<Compile Include="TransformSync\PlayerProbeSync.cs" />
|
||||
<Compile Include="Utility\DebugActions.cs" />
|
||||
<Compile Include="Events\EventListener.cs" />
|
||||
<Compile Include="Events\EventType.cs" />
|
||||
@ -145,6 +147,7 @@
|
||||
<Compile Include="Utility\FlagsHelper.cs" />
|
||||
<Compile Include="TransformSync\PlayerHUDMarker.cs" />
|
||||
<Compile Include="Tools\PlayerToolsManager.cs" />
|
||||
<Compile Include="Utility\Patches.cs" />
|
||||
<Compile Include="Utility\QuaternionHelper.cs" />
|
||||
<Compile Include="TimeSync\PreserveTimeScale.cs" />
|
||||
<Compile Include="TransformSync\ShipTransformSync.cs" />
|
||||
|
@ -22,6 +22,7 @@ namespace QSB
|
||||
private AssetBundle _assetBundle;
|
||||
private GameObject _shipPrefab;
|
||||
private GameObject _cameraPrefab;
|
||||
private GameObject _probePrefab;
|
||||
|
||||
private readonly string[] _defaultNames = {
|
||||
"Arkose",
|
||||
@ -66,6 +67,10 @@ namespace QSB
|
||||
_cameraPrefab.AddComponent<PlayerCameraSync>();
|
||||
spawnPrefabs.Add(_cameraPrefab);
|
||||
|
||||
_probePrefab = _assetBundle.LoadAsset<GameObject>("assets/networkprobe.prefab");
|
||||
_probePrefab.AddComponent<PlayerProbeSync>();
|
||||
spawnPrefabs.Add(_probePrefab);
|
||||
|
||||
ConfigureNetworkManager();
|
||||
|
||||
_playerName = GetPlayerName();
|
||||
@ -103,6 +108,7 @@ namespace QSB
|
||||
// These have to be in a constant order (for now, until I get a better netId getting system...)
|
||||
NetworkServer.SpawnWithClientAuthority(Instantiate(_shipPrefab), connection);
|
||||
NetworkServer.SpawnWithClientAuthority(Instantiate(_cameraPrefab), connection);
|
||||
NetworkServer.SpawnWithClientAuthority(Instantiate(_probePrefab), connection);
|
||||
|
||||
var gameState = gameObject.AddComponent<GameState>();
|
||||
gameState.Send();
|
||||
|
@ -9,7 +9,8 @@ namespace QSB
|
||||
Suit = 1,
|
||||
ProbeLauncher = 2,
|
||||
Signalscope = 4,
|
||||
Translator = 8
|
||||
Translator = 8,
|
||||
ProbeActive = 16
|
||||
//Increment these in binary to add more states
|
||||
}
|
||||
}
|
@ -13,6 +13,7 @@ namespace QSB.Tools
|
||||
private static Material _lightbulbMaterial;
|
||||
|
||||
private static readonly Vector3 FlashlightOffset = new Vector3(0.7196316f, -0.2697681f, 0.3769455f);
|
||||
private static readonly Vector3 ProbeLauncherOffset = new Vector3(0.5745087f, -0.26f, 0.4453125f);
|
||||
private static readonly Vector3 SignalscopeScale = new Vector3(1.5f, 1.5f, 1.5f);
|
||||
private static readonly Vector3 TranslatorScale = new Vector3(0.75f, 0.75f, 0.75f);
|
||||
|
||||
@ -26,6 +27,7 @@ namespace QSB.Tools
|
||||
|
||||
CreateFlashlight();
|
||||
CreateSignalscope();
|
||||
CreateProbeLauncher();
|
||||
|
||||
QSB.Helper.Events.Subscribe<NomaiTranslatorProp>(OWML.Common.Events.AfterStart);
|
||||
QSB.Helper.Events.OnEvent += OnEvent;
|
||||
@ -39,6 +41,14 @@ namespace QSB.Tools
|
||||
}
|
||||
}
|
||||
|
||||
public static void CreateProbe(Transform body, uint id)
|
||||
{
|
||||
var newProbe = body.gameObject.AddComponent<QSBProbe>();
|
||||
newProbe.Init(id);
|
||||
|
||||
PlayerRegistry.GetPlayer(id).Probe = newProbe;
|
||||
}
|
||||
|
||||
private static void CreateStowTransforms()
|
||||
{
|
||||
var stow = new GameObject("ToolStowTransform");
|
||||
@ -56,12 +66,14 @@ namespace QSB.Tools
|
||||
|
||||
private static void CreateFlashlight()
|
||||
{
|
||||
var flashlightRoot = GameObject.Instantiate(GameObject.Find("FlashlightRoot"));
|
||||
var flashlightRoot = Object.Instantiate(GameObject.Find("FlashlightRoot"));
|
||||
flashlightRoot.SetActive(false);
|
||||
var oldComponent = flashlightRoot.GetComponent<Flashlight>();
|
||||
var component = flashlightRoot.AddComponent<QSBFlashlight>();
|
||||
|
||||
component.Init(oldComponent);
|
||||
oldComponent.enabled = false;
|
||||
|
||||
flashlightRoot.transform.parent = _cameraBody;
|
||||
flashlightRoot.transform.localPosition = FlashlightOffset;
|
||||
flashlightRoot.SetActive(true);
|
||||
@ -69,7 +81,7 @@ namespace QSB.Tools
|
||||
|
||||
private static void CreateSignalscope()
|
||||
{
|
||||
var signalscopeRoot = GameObject.Instantiate(GameObject.Find("Signalscope"));
|
||||
var signalscopeRoot = Object.Instantiate(GameObject.Find("Signalscope"));
|
||||
signalscopeRoot.SetActive(false);
|
||||
|
||||
Object.Destroy(signalscopeRoot.GetComponent<SignalscopePromptController>());
|
||||
@ -96,7 +108,7 @@ namespace QSB.Tools
|
||||
|
||||
private static void CreateTranslator(NomaiTranslatorProp translatorProp)
|
||||
{
|
||||
var translatorRoot = GameObject.Instantiate(translatorProp.gameObject);
|
||||
var translatorRoot = Object.Instantiate(translatorProp.gameObject);
|
||||
translatorRoot.SetActive(false);
|
||||
|
||||
var group = translatorRoot.transform.Find("TranslatorGroup");
|
||||
@ -132,9 +144,43 @@ namespace QSB.Tools
|
||||
translatorRoot.SetActive(true);
|
||||
}
|
||||
|
||||
private static void CreateProbeLauncher()
|
||||
{
|
||||
var launcherRoot = Object.Instantiate(GameObject.Find("PlayerCamera/ProbeLauncher"));
|
||||
launcherRoot.SetActive(false);
|
||||
|
||||
var launcher = launcherRoot.transform.Find("Props_HEA_ProbeLauncher");
|
||||
|
||||
Object.Destroy(launcherRoot.GetComponent<ProbePromptController>());
|
||||
Object.Destroy(launcherRoot.GetComponent<ProbeLauncherEffects>());
|
||||
Object.Destroy(launcherRoot.transform.Find("Props_HEA_ProbeLauncher_ProbeCamera").gameObject);
|
||||
Object.Destroy(launcherRoot.transform.Find("preLaunchCamera").gameObject);
|
||||
Object.Destroy(launcherRoot.transform.Find("LaunchParticleEffect_Underwater").gameObject);
|
||||
Object.Destroy(launcherRoot.transform.Find("LaunchParticleEffect").gameObject);
|
||||
Object.Destroy(launcher.Find("Props_HEA_ProbeLauncher_Prepass").gameObject);
|
||||
Object.Destroy(launcher.Find("Props_HEA_Probe_Prelaunch").Find("Props_HEA_Probe_Prelaunch_Prepass").gameObject);
|
||||
|
||||
var oldLauncher = launcherRoot.GetComponent<PlayerProbeLauncher>();
|
||||
var tool = launcherRoot.AddComponent<QSBTool>();
|
||||
tool.MoveSpring = oldLauncher.GetValue<DampedSpringQuat>("_moveSpring");
|
||||
tool.StowTransform = _toolStowTransform;
|
||||
tool.HoldTransform = _toolHoldTransform;
|
||||
tool.ArrivalDegrees = 5f;
|
||||
tool.Type = ToolType.ProbeLauncher;
|
||||
tool.ToolGameObject = launcher.gameObject;
|
||||
oldLauncher.enabled = false;
|
||||
|
||||
GetRenderer(launcherRoot, "PressureGauge_Arrow").material = _playerToolsMaterial;
|
||||
GetRenderer(launcherRoot, "ProbeLauncherChassis").material = _playerToolsMaterial;
|
||||
|
||||
launcherRoot.transform.parent = _cameraBody;
|
||||
launcherRoot.transform.localPosition = ProbeLauncherOffset;
|
||||
launcherRoot.SetActive(true);
|
||||
}
|
||||
|
||||
private static MeshRenderer GetRenderer(GameObject root, string gameobjectName)
|
||||
{
|
||||
return root.GetComponentsInChildren<MeshRenderer>(true).First(x => x.name == gameobjectName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
33
QSB/Tools/QSBProbe.cs
Normal file
33
QSB/Tools/QSBProbe.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using OWML.Common;
|
||||
using QSB.Utility;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.Tools
|
||||
{
|
||||
public class QSBProbe : MonoBehaviour
|
||||
{
|
||||
private uint _attachedNetId;
|
||||
|
||||
public void Init(uint netid)
|
||||
{
|
||||
_attachedNetId = netid;
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void Activate()
|
||||
{
|
||||
DebugLog.ToConsole($"Activating player {_attachedNetId}'s probe.", MessageType.Info);
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public void Deactivate()
|
||||
{
|
||||
DebugLog.ToConsole($"Deactivating player {_attachedNetId}'s probe.", MessageType.Info);
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
@ -12,17 +12,7 @@ namespace QSB.TransformSync
|
||||
LocalInstance = this;
|
||||
}
|
||||
|
||||
private uint GetAttachedNetId()
|
||||
{
|
||||
/*
|
||||
Players are stored in PlayerRegistry using a specific ID. This ID has to remain the same
|
||||
for all components of a player, so I've chosen to used the netId of PlayerTransformSync.
|
||||
Since every networkbehaviour has it's own ascending netId, and we know that PlayerCameraSync
|
||||
is the 3rd network transform to be loaded (After PlayerTransformSync and ShipTransformSync),
|
||||
we can just minus 2 from PlayerCameraSync's netId to get PlayerTransformSyncs's netId.
|
||||
*/
|
||||
return netId.Value - 2;
|
||||
}
|
||||
protected override uint PlayerId => netId.Value - 2;
|
||||
|
||||
protected override Transform InitLocalTransform()
|
||||
{
|
||||
@ -30,7 +20,7 @@ namespace QSB.TransformSync
|
||||
|
||||
PlayerToolsManager.Init(body);
|
||||
|
||||
PlayerRegistry.GetPlayer(GetAttachedNetId()).Camera = body.gameObject;
|
||||
Player.Camera = body.gameObject;
|
||||
|
||||
return body;
|
||||
}
|
||||
@ -41,14 +31,11 @@ namespace QSB.TransformSync
|
||||
|
||||
PlayerToolsManager.Init(body.transform);
|
||||
|
||||
PlayerRegistry.GetPlayer(GetAttachedNetId()).Camera = body;
|
||||
Player.Camera = body;
|
||||
|
||||
return body.transform;
|
||||
}
|
||||
|
||||
protected override bool IsReady()
|
||||
{
|
||||
return Locator.GetPlayerTransform() != null && PlayerRegistry.PlayerExists(GetAttachedNetId());
|
||||
}
|
||||
protected override bool IsReady => Locator.GetPlayerTransform() != null && Player != null;
|
||||
}
|
||||
}
|
||||
|
70
QSB/TransformSync/PlayerProbeSync.cs
Normal file
70
QSB/TransformSync/PlayerProbeSync.cs
Normal file
@ -0,0 +1,70 @@
|
||||
using QSB.Tools;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.TransformSync
|
||||
{
|
||||
public class PlayerProbeSync : TransformSync
|
||||
{
|
||||
public static PlayerProbeSync LocalInstance { get; private set; }
|
||||
|
||||
public Transform bodyTransform;
|
||||
|
||||
public override void OnStartLocalPlayer()
|
||||
{
|
||||
LocalInstance = this;
|
||||
}
|
||||
|
||||
protected override uint PlayerId => netId.Value - 3;
|
||||
|
||||
private Transform GetProbe()
|
||||
{
|
||||
return Locator.GetProbe().transform.Find("CameraPivot").Find("Geometry");
|
||||
}
|
||||
|
||||
protected override Transform InitLocalTransform()
|
||||
{
|
||||
var body = GetProbe();
|
||||
|
||||
bodyTransform = body;
|
||||
|
||||
Player.ProbeBody = body.gameObject;
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
protected override Transform InitRemoteTransform()
|
||||
{
|
||||
var body = Instantiate(GetProbe());
|
||||
|
||||
PlayerToolsManager.CreateProbe(body, PlayerId);
|
||||
|
||||
bodyTransform = body;
|
||||
|
||||
Player.ProbeBody = body.gameObject;
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
protected override void UpdateTransform()
|
||||
{
|
||||
base.UpdateTransform();
|
||||
if (Player.GetState(State.ProbeActive))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (hasAuthority)
|
||||
{
|
||||
transform.position = ReferenceTransform.InverseTransformPoint(Player.ProbeLauncher.ToolGameObject.transform.position);
|
||||
return;
|
||||
}
|
||||
if (SyncedTransform.position == Vector3.zero ||
|
||||
SyncedTransform.position == Locator.GetAstroObject(AstroObject.Name.Sun).transform.position)
|
||||
{
|
||||
return;
|
||||
}
|
||||
SyncedTransform.localPosition = ReferenceTransform.InverseTransformPoint(Player.ProbeLauncher.ToolGameObject.transform.position);
|
||||
}
|
||||
|
||||
protected override bool IsReady => Locator.GetProbe() != null && Player != null;
|
||||
}
|
||||
}
|
@ -14,15 +14,7 @@ namespace QSB.TransformSync
|
||||
LocalInstance = this;
|
||||
}
|
||||
|
||||
private uint GetAttachedNetId()
|
||||
{
|
||||
/*
|
||||
Players are stored in PlayerRegistry using a specific ID. This ID has to remain the same
|
||||
for all components of a player, so I've chosen to used the netId of PlayerTransformSync.
|
||||
This is minus 0 so all transformsyncs follow the same template.
|
||||
*/
|
||||
return netId.Value - 0;
|
||||
}
|
||||
protected override uint PlayerId => netId.Value - 0;
|
||||
|
||||
private Transform GetPlayerModel()
|
||||
{
|
||||
@ -37,7 +29,7 @@ namespace QSB.TransformSync
|
||||
|
||||
GetComponent<AnimationSync>().InitLocal(body);
|
||||
|
||||
PlayerRegistry.GetPlayer(GetAttachedNetId()).Body = body.gameObject;
|
||||
Player.Body = body.gameObject;
|
||||
|
||||
return body;
|
||||
}
|
||||
@ -51,16 +43,13 @@ namespace QSB.TransformSync
|
||||
GetComponent<AnimationSync>().InitRemote(body);
|
||||
|
||||
var marker = body.gameObject.AddComponent<PlayerHUDMarker>();
|
||||
marker.SetId(netId.Value);
|
||||
marker.SetId(PlayerId);
|
||||
|
||||
PlayerRegistry.GetPlayer(GetAttachedNetId()).Body = body.gameObject;
|
||||
Player.Body = body.gameObject;
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
protected override bool IsReady()
|
||||
{
|
||||
return Locator.GetPlayerTransform() != null && PlayerRegistry.PlayerExists(GetAttachedNetId());
|
||||
}
|
||||
protected override bool IsReady => Locator.GetPlayerTransform() != null && Player != null;
|
||||
}
|
||||
}
|
||||
|
@ -11,17 +11,7 @@ namespace QSB.TransformSync
|
||||
LocalInstance = this;
|
||||
}
|
||||
|
||||
uint GetAttachedNetId()
|
||||
{
|
||||
/*
|
||||
Players are stored in PlayerRegistry using a specific ID. This ID has to remain the same
|
||||
for all components of a player, so I've chosen to used the netId of PlayerTransformSync.
|
||||
Since every networkbehaviour has it's own ascending netId, and we know that PlayerCameraSync
|
||||
is the 2nd network transform to be loaded (After PlayerTransformSync), we can just
|
||||
minus 1 from ShipTransformSync's netId to get PlayerTransformSyncs's netId.
|
||||
*/
|
||||
return netId.Value - 1;
|
||||
}
|
||||
protected override uint PlayerId => netId.Value - 1;
|
||||
|
||||
private Transform GetShipModel()
|
||||
{
|
||||
@ -61,9 +51,6 @@ namespace QSB.TransformSync
|
||||
return remoteTransform;
|
||||
}
|
||||
|
||||
protected override bool IsReady()
|
||||
{
|
||||
return GetShipModel() != null;
|
||||
}
|
||||
protected override bool IsReady => GetShipModel() != null;
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,8 @@ namespace QSB.TransformSync
|
||||
{
|
||||
public abstract class TransformSync : NetworkBehaviour
|
||||
{
|
||||
public PlayerInfo Player => PlayerRegistry.GetPlayer(PlayerId);
|
||||
|
||||
private const float SmoothTime = 0.1f;
|
||||
private bool _isInitialized;
|
||||
|
||||
@ -36,7 +38,8 @@ namespace QSB.TransformSync
|
||||
|
||||
protected abstract Transform InitLocalTransform();
|
||||
protected abstract Transform InitRemoteTransform();
|
||||
protected abstract bool IsReady();
|
||||
protected abstract bool IsReady { get; }
|
||||
protected abstract uint PlayerId { get; }
|
||||
|
||||
protected void Init()
|
||||
{
|
||||
@ -63,11 +66,11 @@ namespace QSB.TransformSync
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!_isInitialized && IsReady())
|
||||
if (!_isInitialized && IsReady)
|
||||
{
|
||||
Init();
|
||||
}
|
||||
else if (_isInitialized && !IsReady())
|
||||
else if (_isInitialized && !IsReady)
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
@ -84,28 +87,34 @@ namespace QSB.TransformSync
|
||||
DebugLog.ToConsole($"Error - TransformSync with id {netId.Value} doesn't have a reference sector", MessageType.Error);
|
||||
}
|
||||
|
||||
UpdateTransform();
|
||||
}
|
||||
|
||||
protected virtual void UpdateTransform()
|
||||
{
|
||||
if (hasAuthority) // If this script is attached to the client's own body on the client's side.
|
||||
{
|
||||
transform.position = ReferenceTransform.InverseTransformPoint(SyncedTransform.position);
|
||||
transform.rotation = ReferenceTransform.InverseTransformRotation(SyncedTransform.rotation);
|
||||
return;
|
||||
}
|
||||
else // If this script is attached to any other body, eg the representations of other players
|
||||
|
||||
// If this script is attached to any other body, eg the representations of other players
|
||||
if (SyncedTransform.position == Vector3.zero)
|
||||
{
|
||||
if (SyncedTransform.position == Vector3.zero)
|
||||
{
|
||||
// Fix bodies staying at 0,0,0 by chucking them into the sun
|
||||
SyncedTransform.position = Locator.GetAstroObject(AstroObject.Name.Sun).transform.position;
|
||||
// Fix bodies staying at 0,0,0 by chucking them into the sun
|
||||
SyncedTransform.position = Locator.GetAstroObject(AstroObject.Name.Sun).transform.position;
|
||||
|
||||
FullStateRequest.LocalInstance.Request();
|
||||
}
|
||||
else
|
||||
{
|
||||
SyncedTransform.parent = ReferenceTransform;
|
||||
DebugLog.ToConsole("Warning - TransformSync at (0,0,0)!", MessageType.Warning);
|
||||
|
||||
SyncedTransform.localPosition = Vector3.SmoothDamp(SyncedTransform.localPosition, transform.position, ref _positionSmoothVelocity, SmoothTime);
|
||||
SyncedTransform.localRotation = QuaternionHelper.SmoothDamp(SyncedTransform.localRotation, transform.rotation, ref _rotationSmoothVelocity, Time.deltaTime);
|
||||
}
|
||||
FullStateRequest.LocalInstance.Request();
|
||||
return;
|
||||
}
|
||||
|
||||
SyncedTransform.parent = ReferenceTransform;
|
||||
|
||||
SyncedTransform.localPosition = Vector3.SmoothDamp(SyncedTransform.localPosition, transform.position, ref _positionSmoothVelocity, SmoothTime);
|
||||
SyncedTransform.localRotation = QuaternionHelper.SmoothDamp(SyncedTransform.localRotation, transform.rotation, ref _rotationSmoothVelocity, Time.deltaTime);
|
||||
}
|
||||
|
||||
}
|
||||
|
32
QSB/Utility/Patches.cs
Normal file
32
QSB/Utility/Patches.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using OWML.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.Utility
|
||||
{
|
||||
public static class Patches
|
||||
{
|
||||
private static void ProbeAnchor()
|
||||
{
|
||||
GlobalMessenger.FireEvent("QSBOnProbeAnchor");
|
||||
}
|
||||
|
||||
private static bool ProbeWarp(ref bool ____isRetrieving)
|
||||
{
|
||||
if (!____isRetrieving)
|
||||
{
|
||||
GlobalMessenger.FireEvent("QSBOnProbeWarp");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void DoPatches(IHarmonyHelper helper)
|
||||
{
|
||||
helper.AddPostfix<SurveyorProbe>("OnAnchor", typeof(Patches), nameof(ProbeAnchor));
|
||||
helper.AddPrefix<SurveyorProbe>("Retrieve", typeof(Patches), nameof(ProbeWarp));
|
||||
}
|
||||
}
|
||||
}
|
96
UnityProject/Assets/NetworkProbe.prefab
Normal file
96
UnityProject/Assets/NetworkProbe.prefab
Normal file
@ -0,0 +1,96 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!1001 &100100000
|
||||
Prefab:
|
||||
m_ObjectHideFlags: 1
|
||||
serializedVersion: 2
|
||||
m_Modification:
|
||||
m_TransformParent: {fileID: 0}
|
||||
m_Modifications: []
|
||||
m_RemovedComponents: []
|
||||
m_ParentPrefab: {fileID: 0}
|
||||
m_RootGameObject: {fileID: 1858162522537180}
|
||||
m_IsPrefabParent: 1
|
||||
--- !u!1 &1858162522537180
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 100100000}
|
||||
serializedVersion: 5
|
||||
m_Component:
|
||||
- component: {fileID: 4383151934826088}
|
||||
- component: {fileID: 114893399387826744}
|
||||
- component: {fileID: 114960003525639280}
|
||||
m_Layer: 0
|
||||
m_Name: NetworkProbe
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &4383151934826088
|
||||
Transform:
|
||||
m_ObjectHideFlags: 1
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 100100000}
|
||||
m_GameObject: {fileID: 1858162522537180}
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &114893399387826744
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 1
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 100100000}
|
||||
m_GameObject: {fileID: 1858162522537180}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 372142912, guid: dc443db3e92b4983b9738c1131f555cb, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_SceneId:
|
||||
m_Value: 0
|
||||
m_AssetId:
|
||||
i0: 50
|
||||
i1: 8
|
||||
i2: 170
|
||||
i3: 6
|
||||
i4: 228
|
||||
i5: 100
|
||||
i6: 140
|
||||
i7: 212
|
||||
i8: 139
|
||||
i9: 151
|
||||
i10: 254
|
||||
i11: 0
|
||||
i12: 186
|
||||
i13: 221
|
||||
i14: 21
|
||||
i15: 2
|
||||
m_ServerOnly: 0
|
||||
m_LocalPlayerAuthority: 1
|
||||
--- !u!114 &114960003525639280
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 1
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 100100000}
|
||||
m_GameObject: {fileID: 1858162522537180}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: -1768714887, guid: dc443db3e92b4983b9738c1131f555cb, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_TransformSyncMode: 1
|
||||
m_SendInterval: 0.09090909
|
||||
m_SyncRotationAxis: 7
|
||||
m_RotationSyncCompression: 0
|
||||
m_SyncSpin: 0
|
||||
m_MovementTheshold: 0.001
|
||||
m_VelocityThreshold: 0.0001
|
||||
m_SnapThreshold: 5
|
||||
m_InterpolateRotation: 1
|
||||
m_InterpolateMovement: 1
|
8
UnityProject/Assets/NetworkProbe.prefab.meta
Normal file
8
UnityProject/Assets/NetworkProbe.prefab.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3208aa06e4648cd48b97fe00badd1502
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 100100000
|
||||
userData:
|
||||
assetBundleName: network
|
||||
assetBundleVariant:
|
Loading…
x
Reference in New Issue
Block a user