Compare commits
2 Commits
d1583c9f58
...
40e2236f12
| Author | SHA1 | Date | |
|---|---|---|---|
| 40e2236f12 | |||
| 00b33af98b |
18
README.md
18
README.md
@@ -1,13 +1,6 @@
|
|||||||
# RebootKit
|
# RebootKit
|
||||||
|
|
||||||
# Installationa (WIP)
|
# Installation (WIP)
|
||||||
|
|
||||||
### nuget
|
|
||||||
|
|
||||||
Install nuget package manager for unity from the unity package manager.
|
|
||||||
And install the following packages:
|
|
||||||
- **R3** by Cysharp
|
|
||||||
- **ZLinq** by Cysharp
|
|
||||||
|
|
||||||
### manifest.json
|
### manifest.json
|
||||||
Ensure you have the following dependencies in your `Packages/manifest.json` file:
|
Ensure you have the following dependencies in your `Packages/manifest.json` file:
|
||||||
@@ -15,17 +8,8 @@ Ensure you have the following dependencies in your `Packages/manifest.json` file
|
|||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"com.cysharp.r3": "https://github.com/Cysharp/R3.git?path=src/R3.Unity/Assets/R3.Unity",
|
|
||||||
"com.cysharp.unitask": "https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask",
|
"com.cysharp.unitask": "https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask",
|
||||||
"com.cysharp.zlinq": "https://github.com/Cysharp/ZLinq.git?path=src/ZLinq.Unity/Assets/ZLinq.Unity",
|
|
||||||
"com.github-glitchenzo.nugetforunity": "https://github.com/GlitchEnzo/NuGetForUnity.git?path=/src/NuGetForUnity",
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
# TODO
|
|
||||||
- [ ] Save system
|
|
||||||
- [ ] Built in main menu
|
|
||||||
- [ ] Generic settings ui based on Config Variables
|
|
||||||
- [ ] Extendable FPP Controller
|
|
||||||
- [ ] UI System
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using RebootKit.Engine.Simulation;
|
||||||
|
|
||||||
namespace RebootKit.Engine.AI {
|
namespace RebootKit.Engine.AI {
|
||||||
public class BehaviourNode {
|
public class BehaviourNode {
|
||||||
@@ -23,8 +24,8 @@ namespace RebootKit.Engine.AI {
|
|||||||
Children.Add(child);
|
Children.Add(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual Status Process(float dt) {
|
public virtual Status Process(Actor target, float dt) {
|
||||||
return Children[m_CurrentChild].Process(dt);
|
return Children[m_CurrentChild].Process(target, dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Reset() {
|
public virtual void Reset() {
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
namespace RebootKit.Engine.AI {
|
using RebootKit.Engine.Simulation;
|
||||||
|
|
||||||
|
namespace RebootKit.Engine.AI {
|
||||||
public class BehaviourTree : BehaviourNode {
|
public class BehaviourTree : BehaviourNode {
|
||||||
public BehaviourTree(string name) : base(name) {
|
public BehaviourTree(string name) : base(name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Status Process(float dt) {
|
public override Status Process(Actor target, float dt) {
|
||||||
while (m_CurrentChild < Children.Count) {
|
while (m_CurrentChild < Children.Count) {
|
||||||
Status status = Children[m_CurrentChild].Process(dt);
|
Status status = Children[m_CurrentChild].Process(target, dt);
|
||||||
if (status != Status.Success) {
|
if (status != Status.Success) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using RebootKit.Engine.Simulation;
|
||||||
|
|
||||||
namespace RebootKit.Engine.AI {
|
namespace RebootKit.Engine.AI {
|
||||||
public interface IStrategy {
|
public interface IStrategy {
|
||||||
BehaviourNode.Status Process(float dt);
|
BehaviourNode.Status Process(Actor target, float dt);
|
||||||
void Reset() {
|
void Reset() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,7 +15,7 @@ namespace RebootKit.Engine.AI {
|
|||||||
m_Predicate = predicate;
|
m_Predicate = predicate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BehaviourNode.Status Process(float dt) {
|
public BehaviourNode.Status Process(Actor target, float dt) {
|
||||||
if (m_Predicate()) {
|
if (m_Predicate()) {
|
||||||
return BehaviourNode.Status.Success;
|
return BehaviourNode.Status.Success;
|
||||||
}
|
}
|
||||||
@@ -30,7 +31,7 @@ namespace RebootKit.Engine.AI {
|
|||||||
m_Action = action;
|
m_Action = action;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BehaviourNode.Status Process(float dt) {
|
public BehaviourNode.Status Process(Actor target, float dt) {
|
||||||
m_Action();
|
m_Action();
|
||||||
return BehaviourNode.Status.Success;
|
return BehaviourNode.Status.Success;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
namespace RebootKit.Engine.AI {
|
using RebootKit.Engine.Simulation;
|
||||||
|
|
||||||
|
namespace RebootKit.Engine.AI {
|
||||||
public class Leaf : BehaviourNode {
|
public class Leaf : BehaviourNode {
|
||||||
readonly IStrategy m_Strategy;
|
readonly IStrategy m_Strategy;
|
||||||
|
|
||||||
@@ -6,8 +8,8 @@
|
|||||||
m_Strategy = strategy;
|
m_Strategy = strategy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Status Process(float dt) {
|
public override Status Process(Actor target, float dt) {
|
||||||
return m_Strategy.Process(dt);
|
return m_Strategy.Process(target, dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Reset() {
|
public override void Reset() {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using RebootKit.Engine.Simulation;
|
||||||
|
|
||||||
namespace RebootKit.Engine.AI {
|
namespace RebootKit.Engine.AI {
|
||||||
public class Selector : BehaviourNode {
|
public class Selector : BehaviourNode {
|
||||||
@@ -8,13 +9,13 @@ namespace RebootKit.Engine.AI {
|
|||||||
m_Condition = condition;
|
m_Condition = condition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Status Process(float dt) {
|
public override Status Process(Actor target, float dt) {
|
||||||
if (m_Condition != null && !m_Condition()) {
|
if (m_Condition != null && !m_Condition()) {
|
||||||
return Status.Failure;
|
return Status.Failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_CurrentChild < Children.Count) {
|
if (m_CurrentChild < Children.Count) {
|
||||||
Status status = Children[m_CurrentChild].Process(dt);
|
Status status = Children[m_CurrentChild].Process(target, dt);
|
||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case Status.Success:
|
case Status.Success:
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using RebootKit.Engine.Simulation;
|
||||||
|
|
||||||
namespace RebootKit.Engine.AI {
|
namespace RebootKit.Engine.AI {
|
||||||
public class Sequence : BehaviourNode {
|
public class Sequence : BehaviourNode {
|
||||||
@@ -8,13 +9,13 @@ namespace RebootKit.Engine.AI {
|
|||||||
m_Condition = condition;
|
m_Condition = condition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Status Process(float dt) {
|
public override Status Process(Actor target, float dt) {
|
||||||
if (m_Condition != null && !m_Condition()) {
|
if (m_Condition != null && !m_Condition()) {
|
||||||
return Status.Failure;
|
return Status.Failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_CurrentChild < Children.Count) {
|
if (m_CurrentChild < Children.Count) {
|
||||||
Status status = Children[m_CurrentChild].Process(dt);
|
Status status = Children[m_CurrentChild].Process(target, dt);
|
||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case Status.Success:
|
case Status.Success:
|
||||||
|
|||||||
@@ -12,15 +12,28 @@ namespace RebootKit.Engine.ConsoleUI {
|
|||||||
|
|
||||||
[SerializeField] ConsoleVC m_ConsoleVC;
|
[SerializeField] ConsoleVC m_ConsoleVC;
|
||||||
[SerializeField] ScriptableInputAction m_ToggleAction;
|
[SerializeField] ScriptableInputAction m_ToggleAction;
|
||||||
|
|
||||||
|
InputState m_InputState;
|
||||||
|
|
||||||
readonly StringBuilder m_Content = new StringBuilder();
|
readonly StringBuilder m_Content = new StringBuilder();
|
||||||
|
|
||||||
public bool IsVisible => m_ConsoleVC.gameObject.activeSelf;
|
public bool IsVisible => m_ConsoleVC.gameObject.activeSelf;
|
||||||
|
|
||||||
void Awake() {
|
void Awake() {
|
||||||
|
m_InputState = RR.Input.NewInputState("ConsoleUI");
|
||||||
|
m_InputState.Priority = int.MaxValue;
|
||||||
|
m_InputState.LockCursor = false;
|
||||||
|
m_InputState.HideCursor = false;
|
||||||
|
m_InputState.IsActive = IsVisible;
|
||||||
|
|
||||||
SetVisibility(false);
|
SetVisibility(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OnDestroy() {
|
||||||
|
m_InputState?.Dispose();
|
||||||
|
m_InputState = null;
|
||||||
|
}
|
||||||
|
|
||||||
void OnEnable() {
|
void OnEnable() {
|
||||||
s_Logger.Info("OnEnable console");
|
s_Logger.Info("OnEnable console");
|
||||||
|
|
||||||
@@ -47,13 +60,7 @@ namespace RebootKit.Engine.ConsoleUI {
|
|||||||
SetVisibility(!IsVisible);
|
SetVisibility(!IsVisible);
|
||||||
|
|
||||||
if (IsVisible) {
|
if (IsVisible) {
|
||||||
RR.Input.DisableControls();
|
|
||||||
RR.Input.UnlockCursor();
|
|
||||||
|
|
||||||
m_ConsoleVC.SetMessageContent(m_Content.ToString());
|
m_ConsoleVC.SetMessageContent(m_Content.ToString());
|
||||||
} else {
|
|
||||||
RR.Input.EnableControls();
|
|
||||||
RR.Input.LockCursor();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,6 +71,7 @@ namespace RebootKit.Engine.ConsoleUI {
|
|||||||
|
|
||||||
public void SetVisibility(bool visible) {
|
public void SetVisibility(bool visible) {
|
||||||
m_ConsoleVC.gameObject.SetActive(visible);
|
m_ConsoleVC.gameObject.SetActive(visible);
|
||||||
|
m_InputState.IsActive = visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Write(string message) {
|
public void Write(string message) {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ using Logger = RebootKit.Engine.Foundation.Logger;
|
|||||||
|
|
||||||
namespace RebootKit.Engine.ConsoleUI {
|
namespace RebootKit.Engine.ConsoleUI {
|
||||||
public class ConsoleVC : MonoBehaviour {
|
public class ConsoleVC : MonoBehaviour {
|
||||||
static readonly Logger s_logger = new Logger(nameof(ConsoleVC));
|
static readonly Logger s_Logger = new Logger(nameof(ConsoleVC));
|
||||||
|
|
||||||
[SerializeField] UIDocument m_Document;
|
[SerializeField] UIDocument m_Document;
|
||||||
|
|
||||||
@@ -21,14 +21,13 @@ namespace RebootKit.Engine.ConsoleUI {
|
|||||||
m_LabelMessage = m_Root.Q<Label>("console-window-message");
|
m_LabelMessage = m_Root.Q<Label>("console-window-message");
|
||||||
|
|
||||||
m_TextField = m_Root.Q<TextField>("console-text-field");
|
m_TextField = m_Root.Q<TextField>("console-text-field");
|
||||||
m_TextField.value = string.Empty;
|
|
||||||
m_TextField.RegisterCallback<KeyUpEvent>(ev => {
|
m_TextField.RegisterCallback<KeyUpEvent>(ev => {
|
||||||
if (ev.keyCode == KeyCode.Return) {
|
if (ev.keyCode == KeyCode.Return) {
|
||||||
Submit();
|
Submit();
|
||||||
ev.StopPropagation();
|
ev.StopPropagation();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Button submitButton = m_Root.Q<Button>("console-btn-submit");
|
Button submitButton = m_Root.Q<Button>("console-btn-submit");
|
||||||
submitButton.RegisterCallback<ClickEvent>(_ => { Submit(); });
|
submitButton.RegisterCallback<ClickEvent>(_ => { Submit(); });
|
||||||
|
|
||||||
@@ -37,7 +36,13 @@ namespace RebootKit.Engine.ConsoleUI {
|
|||||||
|
|
||||||
m_ScrollView = m_Root.Q<ScrollView>("console-scrollview");
|
m_ScrollView = m_Root.Q<ScrollView>("console-scrollview");
|
||||||
|
|
||||||
m_TextField.schedule.Execute(() => m_TextField.Focus()).StartingIn(1);
|
m_TextField.schedule.Execute(() => {
|
||||||
|
m_TextField.Focus();
|
||||||
|
m_TextField.value = "";
|
||||||
|
}).StartingIn(16);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnDisable() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public event Action<string> InputSubmitted = _ => { };
|
public event Action<string> InputSubmitted = _ => { };
|
||||||
|
|||||||
@@ -5,18 +5,95 @@ using RebootKit.Engine.Foundation;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Assertions;
|
using UnityEngine.Assertions;
|
||||||
using UnityEngine.InputSystem;
|
using UnityEngine.InputSystem;
|
||||||
|
using UnityEngine.Profiling;
|
||||||
using Logger = RebootKit.Engine.Foundation.Logger;
|
using Logger = RebootKit.Engine.Foundation.Logger;
|
||||||
|
|
||||||
namespace RebootKit.Engine.Input {
|
namespace RebootKit.Engine.Input {
|
||||||
public class InputState {
|
public class InputState : IDisposable {
|
||||||
public string Name { get; private set; }
|
static readonly Logger s_Logger = new Logger(nameof(InputState));
|
||||||
public bool HideCursor { get; private set; }
|
|
||||||
public bool LockCursor { get; private set; }
|
|
||||||
|
|
||||||
public InputState(string name, bool hideCursor = false, bool lockCursor = false) {
|
public string Name { get; private set; }
|
||||||
|
|
||||||
|
bool m_IsActive;
|
||||||
|
public bool IsActive {
|
||||||
|
get {
|
||||||
|
return m_IsActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
set {
|
||||||
|
m_IsActive = value;
|
||||||
|
Service?.UpdateUnityInputState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int m_Priority;
|
||||||
|
public int Priority {
|
||||||
|
get {
|
||||||
|
return m_Priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
set {
|
||||||
|
m_Priority = value;
|
||||||
|
Service?.UpdateUnityInputState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool m_HideCursor;
|
||||||
|
public bool HideCursor {
|
||||||
|
get {
|
||||||
|
return m_HideCursor;
|
||||||
|
}
|
||||||
|
|
||||||
|
set {
|
||||||
|
m_HideCursor = value;
|
||||||
|
Service?.UpdateUnityInputState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool m_LockCursor;
|
||||||
|
public bool LockCursor {
|
||||||
|
get {
|
||||||
|
return m_LockCursor;
|
||||||
|
}
|
||||||
|
|
||||||
|
set {
|
||||||
|
m_LockCursor = value;
|
||||||
|
Service?.UpdateUnityInputState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal List<string> ActiveMaps = new List<string>(4);
|
||||||
|
internal InputService Service;
|
||||||
|
|
||||||
|
internal InputState(string name, InputService service) {
|
||||||
|
IsActive = true;
|
||||||
Name = name;
|
Name = name;
|
||||||
HideCursor = hideCursor;
|
Service = service;
|
||||||
LockCursor = lockCursor;
|
}
|
||||||
|
|
||||||
|
public void Dispose() {
|
||||||
|
Service.UnregisterInputState(this);
|
||||||
|
Service = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddActiveMap(string mapName) {
|
||||||
|
if (ActiveMaps.Contains(mapName)) {
|
||||||
|
s_Logger.Warning($"Action Map '{mapName}' is already active in InputState '{Name}'");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ActiveMaps.Add(mapName);
|
||||||
|
Service.UpdateUnityInputState();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveActiveMap(string mapName) {
|
||||||
|
ActiveMaps.Remove(mapName);
|
||||||
|
Service.UpdateUnityInputState();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsMapActive(string mapName) {
|
||||||
|
return ActiveMaps.Contains(mapName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,7 +104,7 @@ namespace RebootKit.Engine.Input {
|
|||||||
|
|
||||||
InputActionAsset m_InputActionAsset;
|
InputActionAsset m_InputActionAsset;
|
||||||
|
|
||||||
List<InputState> m_States = new List<InputState>(16);
|
readonly List<InputState> m_States = new List<InputState>(16);
|
||||||
|
|
||||||
public InputService(Config config) {
|
public InputService(Config config) {
|
||||||
m_Config = config;
|
m_Config = config;
|
||||||
@@ -39,41 +116,59 @@ namespace RebootKit.Engine.Input {
|
|||||||
m_InputActionAsset = null;
|
m_InputActionAsset = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddState(InputState state) {
|
public InputState NewInputState(string name) {
|
||||||
Assert.IsFalse(m_States.Contains(state), "State already exists in the input service.");
|
Assert.IsNull(m_States.FirstOrDefault(t => t.Name.Equals(name, StringComparison.Ordinal)),
|
||||||
Assert.IsNotNull(state, "Input state cannot be null.");
|
$"State with name '{name}' already exists in the input service.");
|
||||||
Assert.IsNull(m_States.FirstOrDefault(t => t.Name.Equals(state.Name, StringComparison.Ordinal)),
|
|
||||||
$"State with name '{state.Name}' already exists in the input service.");
|
|
||||||
|
|
||||||
m_States.Add(state);
|
var inputState = new InputState(name, this);
|
||||||
|
m_States.Add(inputState);
|
||||||
|
return inputState;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void UnregisterInputState(InputState state) {
|
||||||
|
m_States.Remove(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void UpdateUnityInputState() {
|
||||||
|
Profiler.BeginSample("Find Active State");
|
||||||
|
InputState activeState = m_States.Where(t => t.IsActive)
|
||||||
|
.OrderByDescending(t => t.Priority)
|
||||||
|
.FirstOrDefault();
|
||||||
|
Profiler.EndSample();
|
||||||
|
|
||||||
|
if (activeState == null) {
|
||||||
|
s_Logger.Warning("No Active input state found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Cursor.visible = !activeState.HideCursor;
|
||||||
|
Cursor.lockState = activeState.LockCursor ? CursorLockMode.Locked : CursorLockMode.None;
|
||||||
|
|
||||||
|
foreach (InputActionMap inputActionMap in m_InputActionAsset.actionMaps) {
|
||||||
|
if (activeState.IsMapActive(inputActionMap.name)) {
|
||||||
|
inputActionMap.Enable();
|
||||||
|
} else {
|
||||||
|
inputActionMap.Disable();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void EnableControls() {
|
public void EnableControls() {
|
||||||
|
if (m_InputActionAsset == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_InputActionAsset.Enable();
|
m_InputActionAsset.Enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DisableControls() {
|
public void DisableControls() {
|
||||||
|
if (m_InputActionAsset == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_InputActionAsset.Disable();
|
m_InputActionAsset.Disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool AreControlsEnabled() {
|
|
||||||
return m_InputActionAsset.enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public InputAction FindInputAction(string path) {
|
|
||||||
return m_InputActionAsset.FindAction(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void LockCursor() {
|
|
||||||
Cursor.lockState = CursorLockMode.Locked;
|
|
||||||
Cursor.visible = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UnlockCursor() {
|
|
||||||
Cursor.lockState = CursorLockMode.None;
|
|
||||||
Cursor.visible = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class Config {
|
public class Config {
|
||||||
public InputActionAsset inputActionAsset;
|
public InputActionAsset inputActionAsset;
|
||||||
|
|||||||
Reference in New Issue
Block a user