diff --git a/QSB/EchoesOfTheEye/DreamRafts/WorldObjects/EnableDisableDetector.cs b/QSB/EchoesOfTheEye/DreamRafts/WorldObjects/EnableDisableDetector.cs new file mode 100644 index 00000000..27c95d5e --- /dev/null +++ b/QSB/EchoesOfTheEye/DreamRafts/WorldObjects/EnableDisableDetector.cs @@ -0,0 +1,27 @@ +using QSB.Utility; +using System; +using UnityEngine; + +namespace QSB.EchoesOfTheEye.DreamRafts.WorldObjects; + +public class EnableDisableDetector : MonoBehaviour +{ + public static void Add(GameObject go, object linkedObject) => + go.AddComponent()._linkedObject = linkedObject; + + private object _linkedObject; + + private void Start() + { + var body = this.GetAttachedOWRigidbody(); + if (body) + { + DebugLog.DebugWrite($"{_linkedObject} suspended = {body.IsSuspended()}"); + body.OnSuspendOWRigidbody += _ => DebugLog.DebugWrite($"{_linkedObject} suspend\n{Environment.StackTrace}"); + body.OnPreUnsuspendOWRigidbody += _ => DebugLog.DebugWrite($"{_linkedObject} unsuspend\n{Environment.StackTrace}"); + } + } + + private void OnEnable() => DebugLog.DebugWrite($"{_linkedObject} enable"); + private void OnDisable() => DebugLog.DebugWrite($"{_linkedObject} disable"); +} diff --git a/QSB/EchoesOfTheEye/DreamRafts/WorldObjects/QSBDreamRaftController.cs b/QSB/EchoesOfTheEye/DreamRafts/WorldObjects/QSBDreamRaftController.cs index 45f664ac..cfdbc319 100644 --- a/QSB/EchoesOfTheEye/DreamRafts/WorldObjects/QSBDreamRaftController.cs +++ b/QSB/EchoesOfTheEye/DreamRafts/WorldObjects/QSBDreamRaftController.cs @@ -1,9 +1,6 @@ using Cysharp.Threading.Tasks; -using QSB.Utility; using QSB.WorldSync; -using System; using System.Threading; -using UnityEngine; namespace QSB.EchoesOfTheEye.DreamRafts.WorldObjects; @@ -13,45 +10,4 @@ public class QSBDreamRaftController : WorldObject public override async UniTask Init(CancellationToken ct) => EnableDisableDetector.Add(AttachedObject.gameObject, this); -} - -public class QSBSealRaftController : WorldObject -{ - public override void SendInitialState(uint to) { } - - public override async UniTask Init(CancellationToken ct) => - EnableDisableDetector.Add(AttachedObject.gameObject, this); -} - -public class EnableDisableDetector : MonoBehaviour -{ - public static void Add(GameObject go, object linkedObject) - { - if (go.activeSelf) - { - go.SetActive(false); - go.AddComponent()._linkedObject = linkedObject; - go.SetActive(true); - } - else - { - go.AddComponent()._linkedObject = linkedObject; - } - } - - private object _linkedObject; - - private void Awake() - { - var body = this.GetAttachedOWRigidbody(); - if (body) - { - DebugLog.DebugWrite($"{_linkedObject} suspended = {body.IsSuspended()}"); - body.OnSuspendOWRigidbody += _ => DebugLog.DebugWrite($"{_linkedObject} suspend\n{Environment.StackTrace}"); - body.OnPreUnsuspendOWRigidbody += _ => DebugLog.DebugWrite($"{_linkedObject} unsuspend\n{Environment.StackTrace}"); - } - } - - private void OnEnable() => DebugLog.DebugWrite($"{_linkedObject} enable"); - private void OnDisable() => DebugLog.DebugWrite($"{_linkedObject} disable"); -} +} \ No newline at end of file diff --git a/QSB/EchoesOfTheEye/DreamRafts/WorldObjects/QSBSealRaftController.cs b/QSB/EchoesOfTheEye/DreamRafts/WorldObjects/QSBSealRaftController.cs new file mode 100644 index 00000000..9a90fb1a --- /dev/null +++ b/QSB/EchoesOfTheEye/DreamRafts/WorldObjects/QSBSealRaftController.cs @@ -0,0 +1,13 @@ +using Cysharp.Threading.Tasks; +using QSB.WorldSync; +using System.Threading; + +namespace QSB.EchoesOfTheEye.DreamRafts.WorldObjects; + +public class QSBSealRaftController : WorldObject +{ + public override void SendInitialState(uint to) { } + + public override async UniTask Init(CancellationToken ct) => + EnableDisableDetector.Add(AttachedObject.gameObject, this); +}