This commit is contained in:
JohnCorby 2022-03-25 19:22:57 -07:00
parent 2cc3e54386
commit b072895958
3 changed files with 41 additions and 45 deletions

View File

@ -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<EnableDisableDetector>()._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");
}

View File

@ -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<DreamRaftController>
public override async UniTask Init(CancellationToken ct) =>
EnableDisableDetector.Add(AttachedObject.gameObject, this);
}
public class QSBSealRaftController : WorldObject<SealRaftController>
{
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<EnableDisableDetector>()._linkedObject = linkedObject;
go.SetActive(true);
}
else
{
go.AddComponent<EnableDisableDetector>()._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");
}
}

View File

@ -0,0 +1,13 @@
using Cysharp.Threading.Tasks;
using QSB.WorldSync;
using System.Threading;
namespace QSB.EchoesOfTheEye.DreamRafts.WorldObjects;
public class QSBSealRaftController : WorldObject<SealRaftController>
{
public override void SendInitialState(uint to) { }
public override async UniTask Init(CancellationToken ct) =>
EnableDisableDetector.Add(AttachedObject.gameObject, this);
}