66 lines
2.1 KiB
C#
66 lines
2.1 KiB
C#
using RebootKit.Engine.Main;
|
|
using RebootKit.Engine.Network;
|
|
using RebootKit.Engine.Simulation;
|
|
using UnityEngine;
|
|
using UnityEngine.AddressableAssets;
|
|
|
|
namespace RebootReality.jelycho.Beacons {
|
|
public class BaseManagerActorData : IActorData {
|
|
public void Serialize(NetworkBufferWriter writer) {
|
|
}
|
|
|
|
public void Deserialize(NetworkBufferReader reader) {
|
|
}
|
|
|
|
public int GetMaxBytes() {
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
public enum BaseManagerActorCommands : byte {
|
|
None = 0x00,
|
|
SpawnBeacon = 0x01,
|
|
}
|
|
|
|
public struct SpawnBeaconCommandData : ISerializableEntity {
|
|
public Vector3 Position;
|
|
|
|
public void Serialize(NetworkBufferWriter writer) {
|
|
writer.Write(Position);
|
|
}
|
|
|
|
public void Deserialize(NetworkBufferReader reader) {
|
|
reader.Read(out Position);
|
|
}
|
|
|
|
public int GetMaxBytes() {
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
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(ulong senderID, ActorCommand actorCommand) {
|
|
if (actorCommand.CommandID == (byte)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((byte)BaseManagerActorCommands.SpawnBeacon, ref commandData);
|
|
}
|
|
}
|
|
} |