58 lines
1.9 KiB
C#
58 lines
1.9 KiB
C#
using RebootKit.Engine.Main;
|
|
using RebootKit.Engine.Simulation;
|
|
using Unity.Netcode;
|
|
using UnityEngine;
|
|
using UnityEngine.AddressableAssets;
|
|
|
|
namespace RebootReality.jelycho.Beacons {
|
|
public class BaseManagerActorData : IActorData {
|
|
public void Serialize(FastBufferWriter writer) {
|
|
}
|
|
|
|
public void Deserialize(FastBufferReader reader) {
|
|
}
|
|
}
|
|
|
|
public enum BaseManagerActorCommands : ushort {
|
|
None = 0x0000,
|
|
SpawnBeacon = 0x0001,
|
|
}
|
|
|
|
public struct SpawnBeaconCommandData : ISerializableEntity {
|
|
public Vector3 Position;
|
|
|
|
public void Serialize(FastBufferWriter writer) {
|
|
writer.WriteValue(Position);
|
|
}
|
|
|
|
public void Deserialize(FastBufferReader reader) {
|
|
reader.ReadValue(out Position);
|
|
}
|
|
}
|
|
|
|
public class BaseManagerActor : Actor {
|
|
[SerializeField] AssetReferenceGameObject m_BeaconPrefab;
|
|
[SerializeField] float m_ConnectionRopeLength = 10.0f;
|
|
[SerializeField] float m_BeaconSpawnRadius = 15.0f;
|
|
|
|
protected override IActorData CreateActorData() {
|
|
return new BaseManagerActorData();
|
|
}
|
|
|
|
protected override void OnActorCommandServer(ActorCommand actorCommand) {
|
|
if (actorCommand.CommandID == (ushort)BaseManagerActorCommands.SpawnBeacon) {
|
|
SpawnBeaconCommandData commandData = new SpawnBeaconCommandData();
|
|
DataSerializationUtils.Deserialize(actorCommand.Data, ref commandData);
|
|
RR.SpawnActor(m_BeaconPrefab, commandData.Position, Quaternion.identity);
|
|
}
|
|
}
|
|
|
|
public void TrySpawnBeacon(Vector3 position) {
|
|
SpawnBeaconCommandData commandData = new SpawnBeaconCommandData {
|
|
Position = position
|
|
};
|
|
|
|
SendActorCommand((ushort)BaseManagerActorCommands.SpawnBeacon, ref commandData);
|
|
}
|
|
}
|
|
} |