working on actors
This commit is contained in:
@@ -1,47 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using RebootKit.Engine.Main;
|
||||
using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RebootReality.jelycho.Beacons {
|
||||
public class BaseManager : NetworkBehaviour {
|
||||
[SerializeField] Beacon m_BeaconPrefab;
|
||||
[SerializeField] float m_ConnectionRopeLength = 10.0f;
|
||||
[SerializeField] float m_BeaconSpawnRadius = 15.0f;
|
||||
|
||||
readonly List<Beacon> m_Beacons = new List<Beacon>();
|
||||
|
||||
public IReadOnlyList<Beacon> Beacons => m_Beacons;
|
||||
|
||||
[ServerRpc(RequireOwnership = false)]
|
||||
public void SpawnBeaconServerRpc(Vector3 position) {
|
||||
if (!IsServer) {
|
||||
Debug.LogWarning("Only the server can spawn beacons.");
|
||||
return;
|
||||
}
|
||||
|
||||
Beacon beacon = Instantiate(m_BeaconPrefab, position, Quaternion.identity);
|
||||
beacon.NetworkObject.Spawn();
|
||||
beacon.GrowClientRpc();
|
||||
|
||||
foreach (Beacon otherBeacon in m_Beacons) {
|
||||
if ((otherBeacon.transform.position - beacon.transform.position).sqrMagnitude <
|
||||
m_BeaconSpawnRadius * m_BeaconSpawnRadius) {
|
||||
|
||||
Vector3 startPosition = otherBeacon.RopeConnectionPoint.position;
|
||||
Vector3 endPosition = beacon.RopeConnectionPoint.position;
|
||||
SpawnRopeRpc(startPosition, endPosition);
|
||||
}
|
||||
}
|
||||
|
||||
m_Beacons.Add(beacon);
|
||||
}
|
||||
|
||||
[Rpc(SendTo.Everyone)]
|
||||
void SpawnRopeRpc(Vector3 startPosition, Vector3 endPosition) {
|
||||
if (RR.World.Context is WorldContext worldContext) {
|
||||
worldContext.RopesManager.SpawnLockedRope(m_ConnectionRopeLength, startPosition, endPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
58
Assets/jelycho/Code/Beacons/BaseManagerActor.cs
Normal file
58
Assets/jelycho/Code/Beacons/BaseManagerActor.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,17 @@
|
||||
using Unity.Netcode;
|
||||
using RebootKit.Engine.Simulation;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RebootReality.jelycho.Beacons {
|
||||
public class Beacon : NetworkBehaviour {
|
||||
public class Beacon : Actor {
|
||||
[SerializeField] BeaconGraphics m_Graphics;
|
||||
[field: SerializeField] public Transform RopeConnectionPoint { get; private set; }
|
||||
|
||||
[ClientRpc]
|
||||
public void GrowClientRpc() {
|
||||
void Start() {
|
||||
m_Graphics.Grow();
|
||||
}
|
||||
|
||||
protected override IActorData CreateActorData() {
|
||||
return new NoActorData();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user