quantum-space-buddies/QSB/OrbSync/TransformSync/NomaiOrbTransformSync.cs

66 lines
1.9 KiB
C#
Raw Normal View History

2021-08-14 15:03:01 +01:00
using QSB.Syncs.Unsectored.Transforms;
2021-04-28 10:02:16 +01:00
using QSB.Utility;
using QSB.WorldSync;
using System.Collections.Generic;
using UnityEngine;
namespace QSB.OrbSync.TransformSync
{
2021-08-14 15:03:01 +01:00
internal class NomaiOrbTransformSync : UnsectoredTransformSync
2021-04-28 10:02:16 +01:00
{
2021-04-28 16:32:01 +01:00
public static List<NomaiOrbTransformSync> OrbTransformSyncs = new List<NomaiOrbTransformSync>();
2021-04-28 10:02:16 +01:00
private int _index => OrbTransformSyncs.IndexOf(this);
2021-05-19 11:52:39 +01:00
public override void OnStartClient() => OrbTransformSyncs.Add(this);
2021-04-28 10:02:16 +01:00
protected override void OnDestroy()
{
OrbTransformSyncs.Remove(this);
2021-04-29 23:57:55 +01:00
QSBSceneManager.OnSceneLoaded -= OnSceneLoaded;
2021-04-28 10:02:16 +01:00
}
protected override void Init()
{
base.Init();
2021-07-09 15:54:16 +01:00
var originalParent = AttachedObject.GetAttachedOWRigidbody().GetOrigParent();
if (originalParent == Locator.GetRootTransform())
{
DebugLog.DebugWrite($"{_logName} with AttachedObject {AttachedObject.name} had it's original parent as SolarSystemRoot - Destroying...");
Destroy(this);
}
SetReferenceTransform(originalParent);
2021-04-28 10:02:16 +01:00
}
private Transform GetTransform()
2021-05-08 12:53:09 +01:00
{
2021-05-18 15:22:21 +01:00
if (_index == -1)
{
DebugLog.ToConsole($"Error - Index cannot be found.", OWML.Common.MessageType.Error);
return null;
}
2021-06-18 22:38:32 +01:00
2021-05-08 12:53:09 +01:00
if (QSBWorldSync.OldOrbList == null || QSBWorldSync.OldOrbList.Count <= _index)
{
DebugLog.ToConsole($"Error - OldOrbList is null or does not contain index {_index}.", OWML.Common.MessageType.Error);
return null;
}
2021-06-18 22:38:32 +01:00
2021-05-08 16:57:01 +01:00
if (QSBWorldSync.OldOrbList[_index] == null)
{
DebugLog.ToConsole($"Error - OldOrbList index {_index} is null.", OWML.Common.MessageType.Error);
return null;
}
2021-06-18 22:38:32 +01:00
return QSBWorldSync.OldOrbList[_index].transform;
2021-05-08 12:53:09 +01:00
}
2021-07-07 23:54:09 +01:00
protected override Component InitLocalTransform() => GetTransform();
protected override Component InitRemoteTransform() => GetTransform();
2021-04-28 10:02:16 +01:00
2021-05-08 16:57:01 +01:00
public override bool IsReady => QSBCore.WorldObjectsReady;
2021-04-28 10:02:16 +01:00
public override bool UseInterpolation => false;
}
}