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

@@ -9,7 +9,7 @@ using RebootKit.Engine.Main;
using UnityEngine;
using Logger = RebootKit.Engine.Foundation.Logger;
namespace RebootKit.Engine.Services.Console {
namespace RebootKit.Engine.Console {
[AttributeUsage(AttributeTargets.Method)]
public class RCCMD : Attribute {
public string name;

View File

@@ -2,7 +2,7 @@
using UnityEngine;
using Logger = RebootKit.Engine.Foundation.Logger;
namespace RebootKit.Engine.Services.Console {
namespace RebootKit.Engine.Console {
[CreateAssetMenu(menuName = RConsts.k_ServiceAssetMenu + "Console")]
public class ConsoleServiceAsset : ServiceAsset<ConsoleService> {
static readonly Logger s_logger = new Logger(nameof(ConsoleServiceAsset));

View File

@@ -1,8 +1,7 @@
using System.Text;
using RebootKit.Engine.Foundation;
using RebootKit.Engine.Input;
using RebootKit.Engine.Main;
using RebootKit.Engine.Services.ConsoleUI;
using RebootKit.Engine.Services.Input;
using UnityEngine;
using UnityEngine.InputSystem;
using Logger = RebootKit.Engine.Foundation.Logger;

View File

@@ -3,7 +3,7 @@ using UnityEngine;
using UnityEngine.UIElements;
using Logger = RebootKit.Engine.Foundation.Logger;
namespace RebootKit.Engine.Services.ConsoleUI {
namespace RebootKit.Engine.ConsoleUI {
public class ConsoleVC : MonoBehaviour {
static readonly Logger s_logger = new Logger(nameof(ConsoleVC));

View File

@@ -1,12 +1,10 @@
using System.Text;
using RebootKit.Engine.Main;
using RebootKit.Engine.UI;
using Unity.Netcode;
using Unity.Netcode.Transports.UTP;
using UnityEngine;
using UnityEngine.UIElements;
namespace RebootKit.Engine.Services.Development {
namespace RebootKit.Engine.Development {
public class DebugOverlayView : UIDocumentView {
const string k_DebugLabelClassName = "rr__debug-label";

View File

@@ -1,10 +1,9 @@
using System;
using RebootKit.Engine.Foundation;
using RebootKit.Engine.Services.Console;
using UnityEngine;
using UnityEngine.InputSystem;
namespace RebootKit.Engine.Services.Development {
namespace RebootKit.Engine.Development {
static class DebugConfig {
[ConfigVar("debug.overlay", 0, "Controls overlay visibility. 0 - hidden, 1 - visible")] public static ConfigVar s_OverlayMode;
}

View File

@@ -1,4 +1,5 @@
using RebootKit.Engine.Main;
using RebootKit.Engine.Input;
using RebootKit.Engine.Main;
using UnityEngine;
using UnityEngine.AddressableAssets;
@@ -7,8 +8,7 @@ namespace RebootKit.Engine {
fileName = RConsts.k_EngineConfigAssetName)]
public class EngineConfigAsset : ScriptableObject {
[Header("Core")]
public bool initializeOnLoad = true;
public EngineCoreServicesAsset coreServices;
public InputService.Config inputConfig;
[Header("Game")]
public Game gamePrefab;

View File

@@ -1,16 +0,0 @@
using RebootKit.Engine.Foundation;
using RebootKit.Engine.Input;
using RebootKit.Engine.Services.Console;
using RebootKit.Engine.Services.Input;
using RebootKit.Engine.Services.Simulation;
using RebootKit.Engine.Simulation;
using UnityEngine;
namespace RebootKit.Engine {
[CreateAssetMenu(menuName = RConsts.k_AddComponentMenu + "Engine Core Services", fileName = "Engine Core Services")]
public class EngineCoreServicesAsset : ScriptableObject {
public ServiceAsset<ConsoleService> consoleService;
public ServiceAsset<InputService> inputService;
public ServiceAsset<WorldService> worldService;
}
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 2762a1b645374b79a34aad7b8066bb9b
timeCreated: 1743173984

View File

@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
using RebootKit.Engine.Services.Console;
using UnityEngine;
using ZLinq;

View File

@@ -1,29 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using RebootKit.Engine.Foundation;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Assertions;
using UnityEngine.InputSystem;
using UnityEngine.ResourceManagement.AsyncOperations;
using Logger = RebootKit.Engine.Foundation.Logger;
namespace RebootKit.Engine.Input {
public class InputState {
public string Name { get; private set; }
public bool HideCursor { get; private set; }
public bool LockCursor { get; private set; }
public InputState(string name, bool hideCursor = false, bool lockCursor = false) {
Name = name;
HideCursor = hideCursor;
LockCursor = lockCursor;
}
}
public class InputService : IService {
static readonly Logger s_Logger = new Logger(nameof(InputService));
readonly Config m_Config;
AsyncOperationHandle<InputActionAsset> m_Handle;
InputActionAsset m_InputActionAsset;
List<InputState> m_States = new List<InputState>(16);
public InputService(Config config) {
m_Config = config;
// m_Handle = Addressables.LoadAssetAsync<InputActionAsset>(m_Config.inputAssetReference);
m_InputActionAsset = config.inputActionAsset;
}
public void Dispose() {
m_InputActionAsset = null;
}
public void AddState(InputState state) {
Assert.IsFalse(m_States.Contains(state), "State already exists in the input service.");
Assert.IsNotNull(state, "Input state cannot be null.");
Assert.IsNull(m_States.FirstOrDefault(t => t.Name.Equals(state.Name, StringComparison.Ordinal)),
$"State with name '{state.Name}' already exists in the input service.");
// Addressables.Release(m_Handle);
m_Handle = default;
m_States.Add(state);
}
public void EnableControls() {
@@ -54,7 +76,6 @@ namespace RebootKit.Engine.Input {
[Serializable]
public class Config {
public AssetReferenceT<InputActionAsset> inputAssetReference;
public InputActionAsset inputActionAsset;
}
}

View File

@@ -1,15 +0,0 @@
using RebootKit.Engine.Foundation;
using RebootKit.Engine.Input;
using UnityEngine;
namespace RebootKit.Engine.Services.Input {
[CreateAssetMenu(menuName = RConsts.k_ServiceAssetMenu + "Input")]
public class InputServiceAsset : ServiceAsset<InputService> {
[SerializeField] InputService.Config m_Config;
public override InputService Create() {
InputService instance = new InputService(m_Config);
return instance;
}
}
}

View File

@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 8fcf71fe79ef1ed4cbfdefde09e708d9

View File

@@ -1,7 +1,7 @@
using UnityEngine;
using UnityEngine.InputSystem;
namespace RebootKit.Engine.Services.Input {
namespace RebootKit.Engine.Input {
[CreateAssetMenu(menuName = RConsts.k_AddComponentMenu + "Input Action", fileName = "Input Action")]
public class ScriptableInputAction : ScriptableObject {
[field: SerializeField]

View File

@@ -49,10 +49,6 @@ namespace RebootKit.Engine.Main {
return;
}
if (!configAsset.initializeOnLoad) {
return;
}
s_logger.Info("Initializing RR");
await RR.InitAsync(configAsset, cancellationToken);

View File

@@ -1,6 +1,5 @@
using System;
using Cysharp.Threading.Tasks;
using RebootKit.Engine.Services.Simulation;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;

View File

@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Threading;
using Cysharp.Threading.Tasks;
using RebootKit.Engine.Services.Simulation;
using RebootKit.Engine.Simulation;
using Unity.Collections;
using Unity.Netcode;

View File

@@ -3,11 +3,9 @@ using System.Collections.Generic;
using System.Threading;
using Cysharp.Threading.Tasks;
using R3;
using RebootKit.Engine.Console;
using RebootKit.Engine.Foundation;
using RebootKit.Engine.Input;
using RebootKit.Engine.Services.Console;
using RebootKit.Engine.Services.Input;
using RebootKit.Engine.Services.Simulation;
using RebootKit.Engine.Simulation;
using RebootKit.Engine.Steam;
using Unity.Netcode;
@@ -65,9 +63,10 @@ namespace RebootKit.Engine.Main {
s_disposableBag = new DisposableBag();
s_Logger.Info("Registering core services");
Console = CreateService(EngineConfig.coreServices.consoleService);
Input = CreateService(EngineConfig.coreServices.inputService);
World = CreateService(EngineConfig.coreServices.worldService);
Console = CreateService<ConsoleService>();
Input = new InputService(EngineConfig.inputConfig);
s_servicesBag.Add(Input);
World = CreateService<WorldService>();
await InitializeAssetsAsync(cancellationToken);
@@ -217,6 +216,20 @@ namespace RebootKit.Engine.Main {
s_Logger.Info($"Spawning actor from asset reference: {assetReference.RuntimeKey}");
NetworkSystemInstance.Actors.SpawnActor(assetReference, position, rotation);
}
public static Actor FindSpawnedActor(ulong actorID) {
if (NetworkSystemInstance is null) {
s_Logger.Error("NetworkSystemInstance is not initialized. Cannot find actor.");
return null;
}
Actor actor = NetworkSystemInstance.Actors.FindActorByID(actorID);
if (actor is null) {
s_Logger.Error($"Actor with ID {actorID} not found");
}
return actor;
}
// Service API
public static TService CreateService<TService>(ServiceAsset<TService> asset) where TService : class, IService {
@@ -235,7 +248,7 @@ namespace RebootKit.Engine.Main {
return service;
}
// Logging API
// Logging API
public static void Log(string message) {
Debug.Log(message);
Console?.WriteToOutput(message);
@@ -396,7 +409,10 @@ namespace RebootKit.Engine.Main {
}
if (NetworkSystemInstance is not null) {
NetworkSystemInstance.NetworkObject.Despawn();
if (NetworkSystemInstance.NetworkObject is not null && NetworkSystemInstance.NetworkObject.IsSpawned) {
NetworkSystemInstance.NetworkObject.Despawn();
}
NetworkSystemInstance = null;
}
}

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