From dce6dd8302c61255c55c4185291f917874e3149b Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 12 May 2023 00:09:27 -0400 Subject: [PATCH] I think this works --- .../BaseSync/TransformSync.cs | 23 ++++++++++--------- .../Debugging/Patches/DebugLogPatches.cs | 2 -- .../NetworkHarvestPOIManager.cs | 2 +- .../PlayerSync/PlayerTransformSync.cs | 15 +++++++++--- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/CosmicHorrorFishingBuddies/BaseSync/TransformSync.cs b/CosmicHorrorFishingBuddies/BaseSync/TransformSync.cs index 286d405..1edb681 100644 --- a/CosmicHorrorFishingBuddies/BaseSync/TransformSync.cs +++ b/CosmicHorrorFishingBuddies/BaseSync/TransformSync.cs @@ -11,23 +11,24 @@ internal abstract class TransformSync : NetworkBehaviour private Transform _syncedTransform; - private void Start() + private NetworkTransform _networkTransform; + + public void Awake() + { + _networkTransform = gameObject.GetComponent(); + _networkTransform.target = transform; + } + + public void Start() { CFBCore.LogInfo($"Start TransformSync: {netId}"); _syncedTransform = isOwned ? InitLocalTransform() : InitRemoteTransform(); - var networkTransform = gameObject.GetComponent(); - networkTransform.target = transform; - } + _networkTransform.transform.position = Vector3.zero; + _networkTransform.transform.rotation = Quaternion.identity; - private void Update() - { - if (isOwned) - { - transform.position = GameManager.Instance.Player.transform.position; - transform.rotation = GameManager.Instance.Player.transform.rotation; - } + _networkTransform.target = _syncedTransform; } } } diff --git a/CosmicHorrorFishingBuddies/Debugging/Patches/DebugLogPatches.cs b/CosmicHorrorFishingBuddies/Debugging/Patches/DebugLogPatches.cs index 4f66650..d04d9c7 100644 --- a/CosmicHorrorFishingBuddies/Debugging/Patches/DebugLogPatches.cs +++ b/CosmicHorrorFishingBuddies/Debugging/Patches/DebugLogPatches.cs @@ -12,7 +12,6 @@ namespace CosmicHorrorFishingBuddies.Debugging.Patches [HarmonyPatch(typeof(Debug))] internal static class DebugLogPatches { - /* [HarmonyPostfix] [HarmonyPatch(nameof(Debug.Log), new Type[] { typeof(object) })] public static void Debug_Log(object message) => CFBCore.LogInfo($"[UnityEngine.Debug.Log] {message}"); @@ -20,7 +19,6 @@ internal static class DebugLogPatches [HarmonyPostfix] [HarmonyPatch(nameof(Debug.LogWarning), new Type[] { typeof(object) })] public static void Debug_LogWarning(object message) => CFBCore.LogWarning($"[UnityEngine.Debug.Log] {message}"); - */ [HarmonyPostfix] [HarmonyPatch(nameof(Debug.LogError), new Type[] { typeof(object) })] diff --git a/CosmicHorrorFishingBuddies/HarvestPOISync/NetworkHarvestPOIManager.cs b/CosmicHorrorFishingBuddies/HarvestPOISync/NetworkHarvestPOIManager.cs index 6e73b03..73c7283 100644 --- a/CosmicHorrorFishingBuddies/HarvestPOISync/NetworkHarvestPOIManager.cs +++ b/CosmicHorrorFishingBuddies/HarvestPOISync/NetworkHarvestPOIManager.cs @@ -97,7 +97,7 @@ public NetworkHarvestPOI GetNetworkObject(HarvestPOI harvestPOI) } else { - CFBCore.LogError($"Untracked HarvestPOI {harvestPOI.name} on {NetworkPlayer.LocalPlayer.netId}"); + CFBCore.LogError($"Untracked HarvestPOI {harvestPOI?.name} on {NetworkPlayer.LocalPlayer?.netId}"); return null; } } diff --git a/CosmicHorrorFishingBuddies/PlayerSync/PlayerTransformSync.cs b/CosmicHorrorFishingBuddies/PlayerSync/PlayerTransformSync.cs index fcb217d..8629ab7 100644 --- a/CosmicHorrorFishingBuddies/PlayerSync/PlayerTransformSync.cs +++ b/CosmicHorrorFishingBuddies/PlayerSync/PlayerTransformSync.cs @@ -81,7 +81,7 @@ protected override Transform InitLocalTransform() GameManager.Instance.Player.gameObject.AddComponent(); - return GameManager.Instance.Player.transform; + return transform; } protected override Transform InitRemoteTransform() @@ -97,7 +97,7 @@ protected override Transform InitRemoteTransform() remotePlayer.transform.localRotation = Quaternion.identity; var networkPlayer = GetComponent(); - + networkPlayer.remotePlayerBoatGraphics.boatSubModelTogglers = remotePlayer.GetComponentsInChildren(); networkPlayer.remotePlayerBoatGraphics.boatModelProxies = remotePlayer.GetComponentsInChildren(); networkPlayer.remotePlayerBoatGraphics.wake = remotePlayer.Find("BoatTrailParticles").gameObject; @@ -116,7 +116,16 @@ protected override Transform InitRemoteTransform() networkPlayer.remoteAtrophyAbility.loopAudio.minDistance = 5; networkPlayer.remoteAtrophyAbility.loopAudio.clip = atrophy.loopAudioSource.clip; - return remotePlayer; + return transform; + } + + private void Update() + { + if (isOwned) + { + transform.position = GameManager.Instance.Player.transform.position; + transform.rotation = GameManager.Instance.Player.transform.rotation; + } } } }