This commit is contained in:
2025-07-11 14:40:42 +02:00
parent c39b87ed44
commit 0da6f275c0
42 changed files with 756 additions and 226 deletions

View File

@@ -29,7 +29,7 @@ namespace RebootKit.Engine.Simulation {
public const int k_DefaultMessageSize = 256;
public static NativeArray<byte> Serialize<TEntity>(TEntity entity,
Allocator allocator = Allocator.Temp)
Allocator allocator = Allocator.Temp)
where TEntity : ISerializableEntity {
int size = entity.MinimumSizeInBytes();
if (size < 0) {
@@ -130,10 +130,42 @@ namespace RebootKit.Engine.Simulation {
[NonSerialized] internal IActorData Data;
[SerializeField] string m_ActorName = "";
public string ActorName {
get {
return m_ActorName;
}
}
[Serializable]
public struct AttachmentSocket {
public string socketName;
public Transform root;
public Vector3 localPosition;
public Quaternion localRotation;
}
[SerializeField] AttachmentSocket[] m_AttachmentSockets;
public bool IsDataDirty { get; protected internal set; }
internal ActorsManager Manager;
public bool IsHidden() {
return !gameObject.activeSelf;
}
public void SetHidden(bool hidden) {
if (!RR.IsServer()) {
s_ActorLogger.Error($"Only the server can set actor visibility. Actor: {name} (ID: {ActorID})");
return;
}
Manager.SetActorHidden(ActorID, hidden);
}
internal IActorData InternalCreateActorData() {
return CreateActorData();
}

View File

@@ -8,7 +8,6 @@ using UnityEngine.AddressableAssets;
using Logger = RebootKit.Engine.Foundation.Logger;
namespace RebootKit.Engine.Simulation {
// @TODO:
// - Actors States might be packed into chunks to reduce the number of RPCs sent.
public class ActorsManager : NetworkBehaviour {
@@ -270,6 +269,7 @@ namespace RebootKit.Engine.Simulation {
return;
}
actor.Manager = this;
actor.SourceActorPath = assetReference.AssetGUID;
actor.ActorID = UniqueID.NewULongFromGuid();
actor.Data = actor.InternalCreateActorData();
@@ -307,6 +307,7 @@ namespace RebootKit.Engine.Simulation {
return;
}
actor.Manager = this;
actor.SourceActorPath = guid;
actor.ActorID = actorID;
actor.Data = actor.InternalCreateActorData();
@@ -334,5 +335,39 @@ namespace RebootKit.Engine.Simulation {
Destroy(actor.gameObject);
}
public bool IsActorHidden(ulong actorID) {
Actor actor = FindActorByID(actorID);
if (actor is null) {
s_Logger.Error($"Actor with ID {actorID} not found.");
return false;
}
return !actor.gameObject.activeSelf;
}
public void SetActorHidden(ulong actorID, bool hidden) {
if (!IsServer) {
s_Logger.Error("Only the server can set actor visibility.");
return;
}
SetActorHiddenRpc(actorID, hidden, RpcTarget.Everyone);
}
[Rpc(SendTo.SpecifiedInParams)]
void SetActorHiddenRpc(ulong actorID, bool hidden, RpcParams rpcParams) {
Actor actor = FindActorByID(actorID);
if (actor is null) {
s_Logger.Error($"Actor with ID {actorID} not found.");
return;
}
if (hidden) {
actor.gameObject.SetActive(false);
} else {
actor.gameObject.SetActive(true);
}
}
}
}

View File

@@ -1,6 +1,6 @@
using UnityEngine;
namespace RebootKit.Engine.Services.Simulation.Characters {
namespace RebootKit.Engine.Simulation.Characters {
public class CharacterLocomotion : MonoBehaviour {
[SerializeField] CharacterController m_CharacterController;

View File

@@ -2,7 +2,7 @@
using System.Threading;
using Cysharp.Threading.Tasks;
namespace RebootKit.Engine.Services.Simulation.Interactors {
namespace RebootKit.Engine.Simulation.Interactors {
public interface IInteractorAsync<in TInteractable> {
UniTask Interact(TInteractable target, CancellationToken cancellationToken);
}

View File

@@ -1,8 +1,7 @@
using System;
using RebootKit.Engine.Extensions;
using RebootKit.Engine.Extensions;
using UnityEngine;
namespace RebootKit.Engine.Services.Simulation {
namespace RebootKit.Engine.Simulation {
public class PhysicsObjectDragger : MonoBehaviour {
[field: SerializeField]
public float DampingFactor { get; private set; } = 1.0f;

View File

@@ -1,7 +1,6 @@
using RebootKit.Engine.Simulation.Sensors;
using UnityEngine;
using UnityEngine;
namespace RebootKit.Engine.Services.Simulation.Sensors {
namespace RebootKit.Engine.Simulation.Sensors {
public class RaycastSensor : ISensor {
public LayerMask layerMask;
public float maxDistance;

View File

@@ -2,7 +2,7 @@
using UnityEngine;
using UnityEngine.AddressableAssets;
namespace RebootKit.Engine.Services.Simulation {
namespace RebootKit.Engine.Simulation {
[Serializable]
public struct WorldConfig {
public string name;

View File

@@ -3,7 +3,6 @@ using System.Threading;
using Cysharp.Threading.Tasks;
using RebootKit.Engine.Foundation;
using RebootKit.Engine.Main;
using RebootKit.Engine.Services.Simulation;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AddressableAssets;

View File

@@ -1,12 +0,0 @@
using RebootKit.Engine.Foundation;
using RebootKit.Engine.Simulation;
using UnityEngine;
namespace RebootKit.Engine.Services.Simulation {
[CreateAssetMenu(menuName = RConsts.k_ServiceAssetMenu + "World")]
public class WorldServiceAsset : ServiceAsset<WorldService> {
public override WorldService Create() {
return new WorldService();
}
}
}

View File

@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 3f449396a11e05e41990dbddfb992815