mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2024-12-29 12:21:25 +00:00
IQSBDropTarget
This commit is contained in:
parent
b6e9c33d2d
commit
61d51b109a
@ -2,6 +2,7 @@
|
||||
using QSB.AuthoritySync;
|
||||
using QSB.EchoesOfTheEye.LightSensorSync.WorldObjects;
|
||||
using QSB.EchoesOfTheEye.RaftSync.TransformSync;
|
||||
using QSB.ItemSync.WorldObjects;
|
||||
using QSB.Utility.LinkedWorldObject;
|
||||
using QSB.WorldSync;
|
||||
using System.Linq;
|
||||
@ -10,8 +11,10 @@ using UnityEngine;
|
||||
|
||||
namespace QSB.EchoesOfTheEye.RaftSync.WorldObjects;
|
||||
|
||||
public class QSBRaft : LinkedWorldObject<RaftController, RaftTransformSync>
|
||||
public class QSBRaft : LinkedWorldObject<RaftController, RaftTransformSync>, IQSBDropTarget
|
||||
{
|
||||
IItemDropTarget IQSBDropTarget.AttachedObject => AttachedObject;
|
||||
|
||||
public override bool ShouldDisplayDebug() => false;
|
||||
|
||||
protected override GameObject NetworkObjectPrefab => QSBNetworkManager.singleton.RaftPrefab;
|
||||
|
@ -1,10 +1,13 @@
|
||||
using QSB.Patches;
|
||||
using QSB.ItemSync.WorldObjects;
|
||||
using QSB.Patches;
|
||||
using QSB.WorldSync;
|
||||
|
||||
namespace QSB.EchoesOfTheEye.RaftSync.WorldObjects;
|
||||
|
||||
public class QSBRaftDock : WorldObject<RaftDock>
|
||||
public class QSBRaftDock : WorldObject<RaftDock>, IQSBDropTarget
|
||||
{
|
||||
IItemDropTarget IQSBDropTarget.AttachedObject => AttachedObject;
|
||||
|
||||
public override void SendInitialState(uint to) { }
|
||||
|
||||
public void OnPressInteract() =>
|
||||
|
@ -33,10 +33,10 @@ internal class ItemManager : WorldObjectManager
|
||||
// Sockets
|
||||
QSBWorldSync.Init<QSBItemSocket, OWItemSocket>();
|
||||
|
||||
// drop targets
|
||||
// other drop targets that don't already have world objects
|
||||
var listToInitFrom = QSBWorldSync.GetUnityObjects<MonoBehaviour>()
|
||||
.Where(x => x is IItemDropTarget and not (RaftDock or RaftController))
|
||||
.SortDeterministic();
|
||||
QSBWorldSync.Init<QSBDropTarget, MonoBehaviour>(listToInitFrom);
|
||||
QSBWorldSync.Init<QSBOtherDropTarget, MonoBehaviour>(listToInitFrom);
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ internal class DropItemMessage : QSBWorldObjectMessage<IQSBItem,
|
||||
else
|
||||
{
|
||||
tuple.rigidBodyId = -1;
|
||||
tuple.dropTargetId = ((MonoBehaviour)customDropTarget).GetWorldObject<QSBDropTarget>().ObjectId;
|
||||
tuple.dropTargetId = ((MonoBehaviour)customDropTarget).GetWorldObject<IQSBDropTarget>().ObjectId;
|
||||
}
|
||||
|
||||
tuple.sectorId = sector.GetWorldObject<QSBSector>().ObjectId;
|
||||
@ -46,7 +46,7 @@ internal class DropItemMessage : QSBWorldObjectMessage<IQSBItem,
|
||||
{
|
||||
var customDropTarget = Data.dropTargetId == -1
|
||||
? null
|
||||
: Data.dropTargetId.GetWorldObject<QSBDropTarget>().AttachedObject;
|
||||
: Data.dropTargetId.GetWorldObject<IQSBDropTarget>().AttachedObject;
|
||||
|
||||
var parent = customDropTarget == null
|
||||
? Data.rigidBodyId.GetWorldObject<QSBOWRigidbody>().AttachedObject.transform
|
||||
|
8
QSB/ItemSync/WorldObjects/IQSBDropTarget.cs
Normal file
8
QSB/ItemSync/WorldObjects/IQSBDropTarget.cs
Normal file
@ -0,0 +1,8 @@
|
||||
using QSB.WorldSync;
|
||||
|
||||
namespace QSB.ItemSync.WorldObjects;
|
||||
|
||||
public interface IQSBDropTarget : IWorldObject
|
||||
{
|
||||
new IItemDropTarget AttachedObject { get; }
|
||||
}
|
@ -6,13 +6,13 @@ using UnityEngine;
|
||||
|
||||
namespace QSB.ItemSync.WorldObjects;
|
||||
|
||||
public class QSBDropTarget : WorldObject<MonoBehaviour>
|
||||
public class QSBOtherDropTarget : WorldObject<MonoBehaviour>, IQSBDropTarget
|
||||
{
|
||||
public new IItemDropTarget AttachedObject => (IItemDropTarget)base.AttachedObject;
|
||||
IItemDropTarget IQSBDropTarget.AttachedObject => (IItemDropTarget)AttachedObject;
|
||||
|
||||
public override async UniTask Init(CancellationToken ct)
|
||||
{
|
||||
if (base.AttachedObject is not IItemDropTarget)
|
||||
if (AttachedObject is not IItemDropTarget)
|
||||
{
|
||||
throw new ArgumentException("QSBDropTarget.AttachedObject is not an IItemDropTarget!");
|
||||
}
|
Loading…
Reference in New Issue
Block a user