清理项目目录,引入 InputModule 做多平台输入适配

This commit is contained in:
SepComet
2026-06-06 16:35:39 +08:00
parent c8c26b8b2e
commit 5ede6846db
227 changed files with 16702 additions and 2059 deletions
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e2301393ca4a888488551e3dc377e410
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6799e9376c9328b4f83436698cca06d7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,78 @@
using NUnit.Framework;
using SepCore.InputModule.Runtime;
namespace SepCore.InputModule.Tests
{
public class BindingOverridePersistenceTests
{
[Test]
public void SerializeV2_WrapsPayload()
{
string payload = "[{\"test\":true}]";
string result = BindingOverridePersistence.Serialize(payload);
Assert.That(result, Does.Contain("\"version\":2"));
bool success = BindingOverridePersistence.TryDeserialize(result, out string deserialized);
Assert.That(success, Is.True);
Assert.That(deserialized, Is.EqualTo(payload));
}
[Test]
public void TryDeserialize_V1RawJson_ReturnsTrueWithOriginalString()
{
string v1 = "[{\"action\":\"test\"}]";
bool success = BindingOverridePersistence.TryDeserialize(v1, out string overridesJson);
Assert.That(success, Is.True);
Assert.That(overridesJson, Is.EqualTo(v1));
}
[Test]
public void TryDeserialize_V2Wrapped_ReturnsTrueWithPayload()
{
string payload = "[{\"action\":\"test\"}]";
string v2 = BindingOverridePersistence.Serialize(payload);
bool success = BindingOverridePersistence.TryDeserialize(v2, out string overridesJson);
Assert.That(success, Is.True);
Assert.That(overridesJson, Is.EqualTo(payload));
}
[Test]
public void TryDeserialize_CorruptedJson_ReturnsFalse()
{
bool success = BindingOverridePersistence.TryDeserialize("{not valid json", out _);
Assert.That(success, Is.False);
}
[Test]
public void TryDeserialize_FutureVersion_ReturnsFalse()
{
string future = "{\"version\":99,\"payload\":\"test\"}";
bool success = BindingOverridePersistence.TryDeserialize(future, out _);
Assert.That(success, Is.False);
}
[Test]
public void TryDeserialize_EmptyData_ReturnsFalse()
{
bool success = BindingOverridePersistence.TryDeserialize("", out _);
Assert.That(success, Is.False);
}
[Test]
public void TryDeserialize_NullData_ReturnsFalse()
{
bool success = BindingOverridePersistence.TryDeserialize(null, out _);
Assert.That(success, Is.False);
}
[Test]
public void TryDeserialize_Whitespace_ReturnsFalse()
{
bool success = BindingOverridePersistence.TryDeserialize(" ", out _);
Assert.That(success, Is.False);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 84df263f5b2439d4ea1eb44adab8f06a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,130 @@
using NUnit.Framework;
using SepCore.InputModule;
namespace SepCore.InputModule.Tests
{
public class InputContextStackTests
{
[Test]
public void PushPopMaintainsCurrentContext()
{
InputContextStack stack = new InputContextStack();
Assert.That(stack.Push(InputContextId.GameplayExplore), Is.True);
Assert.That(stack.Current, Is.EqualTo(InputContextId.GameplayExplore));
Assert.That(stack.Push(InputContextId.Dialog), Is.True);
Assert.That(stack.Current, Is.EqualTo(InputContextId.Dialog));
Assert.That(stack.Pop(out InputContextId poppedContext), Is.True);
Assert.That(poppedContext, Is.EqualTo(InputContextId.Dialog));
Assert.That(stack.Current, Is.EqualTo(InputContextId.GameplayExplore));
}
[Test]
public void SetClearsExistingStack()
{
InputContextStack stack = new InputContextStack();
stack.Push(InputContextId.GameplayExplore);
stack.Push(InputContextId.Dialog);
Assert.That(stack.Set(InputContextId.UI), Is.True);
Assert.That(stack.Count, Is.EqualTo(1));
Assert.That(stack.Current, Is.EqualTo(InputContextId.UI));
}
[Test]
public void ClearRejectsNonStackableContexts()
{
InputContextStack stack = new InputContextStack();
Assert.That(stack.Push(InputContextId.Global), Is.False);
Assert.That(stack.Push(InputContextId.None), Is.False);
Assert.That(stack.Count, Is.EqualTo(0));
}
[Test]
public void PushDuplicateReturnsFalse()
{
InputContextStack stack = new InputContextStack();
Assert.That(stack.Push(InputContextId.GameplayExplore), Is.True);
Assert.That(stack.Push(InputContextId.GameplayExplore), Is.False);
Assert.That(stack.Count, Is.EqualTo(1));
}
[Test]
public void PopEmptyStackReturnsFalse()
{
InputContextStack stack = new InputContextStack();
Assert.That(stack.Pop(out InputContextId context), Is.False);
Assert.That(context, Is.EqualTo(InputContextId.None));
}
[Test]
public void ClearOnEmptyStackReturnsFalse()
{
InputContextStack stack = new InputContextStack();
Assert.That(stack.Clear(), Is.False);
}
[Test]
public void ClearResetsCurrentToNone()
{
InputContextStack stack = new InputContextStack();
stack.Push(InputContextId.GameplayExplore);
stack.Push(InputContextId.Dialog);
Assert.That(stack.Clear(), Is.True);
Assert.That(stack.Current, Is.EqualTo(InputContextId.None));
Assert.That(stack.Count, Is.EqualTo(0));
}
[Test]
public void SetNonStackableCallsClear()
{
InputContextStack stack = new InputContextStack();
stack.Push(InputContextId.GameplayExplore);
Assert.That(stack.Set(InputContextId.None), Is.True);
Assert.That(stack.Count, Is.EqualTo(0));
}
[Test]
public void SetSameContextReturnsFalse()
{
InputContextStack stack = new InputContextStack();
stack.Set(InputContextId.UI);
Assert.That(stack.Set(InputContextId.UI), Is.False);
}
[Test]
public void PushReorderExistingToTop()
{
InputContextStack stack = new InputContextStack();
stack.Push(InputContextId.GameplayExplore);
stack.Push(InputContextId.Dialog);
stack.Push(InputContextId.UI);
Assert.That(stack.Push(InputContextId.GameplayExplore), Is.True);
Assert.That(stack.Current, Is.EqualTo(InputContextId.GameplayExplore));
Assert.That(stack.Count, Is.EqualTo(3));
}
[Test]
public void CurrentOnEmptyStackReturnsNone()
{
InputContextStack stack = new InputContextStack();
Assert.That(stack.Current, Is.EqualTo(InputContextId.None));
}
[Test]
public void PopRestoresPreviousContext()
{
InputContextStack stack = new InputContextStack();
stack.Push(InputContextId.GameplayExplore);
stack.Push(InputContextId.Dialog);
Assert.That(stack.Pop(out InputContextId popped), Is.True);
Assert.That(popped, Is.EqualTo(InputContextId.Dialog));
Assert.That(stack.Current, Is.EqualTo(InputContextId.GameplayExplore));
Assert.That(stack.Count, Is.EqualTo(1));
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2b8b50313d9e2d84da0c6ce522affafb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,265 @@
using NUnit.Framework;
using SepCore.InputModule;
using SepCore.InputModule.Runtime;
using UnityEngine;
using UnityEngine.InputSystem;
namespace SepCore.InputModule.Tests
{
public class InputModuleComponentContextTests
{
private GameObject _gameObject;
private InputModuleComponent _component;
private InputActionAsset _asset;
[SetUp]
public void SetUp()
{
_gameObject = new GameObject("InputModuleTest");
_component = _gameObject.AddComponent<InputModuleComponent>();
}
[TearDown]
public void TearDown()
{
Object.DestroyImmediate(_gameObject);
}
private void InitializeWithDefaultActions()
{
_component.OnInit();
_asset = _component.RuntimeActions;
}
private InputActionMap FindMap(InputContextId contextId)
{
return _asset.FindActionMap(contextId.ToString(), throwIfNotFound: false);
}
[Test]
public void AfterInitOnlyGlobalMapIsEnabled()
{
InitializeWithDefaultActions();
InputActionMap globalMap = FindMap(InputContextId.Global);
InputActionMap uiMap = FindMap(InputContextId.UI);
InputActionMap geMap = FindMap(InputContextId.GameplayExplore);
Assert.That(globalMap, Is.Not.Null);
Assert.That(uiMap, Is.Not.Null);
Assert.That(geMap, Is.Not.Null);
Assert.That(globalMap.enabled, Is.True);
Assert.That(uiMap.enabled, Is.False);
Assert.That(geMap.enabled, Is.False);
}
[Test]
public void SetContextEnablesTargetMapAndGlobal()
{
InitializeWithDefaultActions();
_component.SetContext(InputContextId.UI);
InputActionMap globalMap = FindMap(InputContextId.Global);
InputActionMap uiMap = FindMap(InputContextId.UI);
InputActionMap geMap = FindMap(InputContextId.GameplayExplore);
Assert.That(globalMap.enabled, Is.True);
Assert.That(uiMap.enabled, Is.True);
Assert.That(geMap.enabled, Is.False);
}
[Test]
public void SetContextSwitchDisablesPreviousMap()
{
InitializeWithDefaultActions();
_component.SetContext(InputContextId.UI);
InputActionMap uiMap = FindMap(InputContextId.UI);
Assert.That(uiMap.enabled, Is.True);
_component.SetContext(InputContextId.GameplayExplore);
InputActionMap geMap = FindMap(InputContextId.GameplayExplore);
Assert.That(uiMap.enabled, Is.False);
Assert.That(geMap.enabled, Is.True);
}
[Test]
public void PushContextOnlyEnablesTopmostMap()
{
InitializeWithDefaultActions();
_component.SetContext(InputContextId.UI);
_component.PushContext(InputContextId.GameplayExplore);
InputActionMap globalMap = FindMap(InputContextId.Global);
InputActionMap uiMap = FindMap(InputContextId.UI);
InputActionMap geMap = FindMap(InputContextId.GameplayExplore);
Assert.That(globalMap.enabled, Is.True);
Assert.That(uiMap.enabled, Is.False);
Assert.That(geMap.enabled, Is.True);
}
[Test]
public void PopContextRestoresPreviousMapState()
{
InitializeWithDefaultActions();
_component.SetContext(InputContextId.UI);
_component.PushContext(InputContextId.GameplayExplore);
InputActionMap geMap = FindMap(InputContextId.GameplayExplore);
Assert.That(geMap.enabled, Is.True);
_component.PopContext();
InputActionMap uiMap = FindMap(InputContextId.UI);
Assert.That(geMap.enabled, Is.False);
Assert.That(uiMap.enabled, Is.True);
}
[Test]
public void ClearContextsOnlyGlobalRemainsEnabled()
{
InitializeWithDefaultActions();
_component.SetContext(InputContextId.UI);
_component.PushContext(InputContextId.GameplayExplore);
_component.ClearContexts();
InputActionMap globalMap = FindMap(InputContextId.Global);
InputActionMap uiMap = FindMap(InputContextId.UI);
InputActionMap geMap = FindMap(InputContextId.GameplayExplore);
Assert.That(globalMap.enabled, Is.True);
Assert.That(uiMap.enabled, Is.False);
Assert.That(geMap.enabled, Is.False);
}
[Test]
public void OnDisableDisablesAllMaps()
{
InitializeWithDefaultActions();
_component.SetContext(InputContextId.UI);
_gameObject.SetActive(false);
InputActionMap globalMap = FindMap(InputContextId.Global);
InputActionMap uiMap = FindMap(InputContextId.UI);
Assert.That(globalMap.enabled, Is.False);
Assert.That(uiMap.enabled, Is.False);
}
[Test]
public void OnEnableRestoresContextState()
{
InitializeWithDefaultActions();
_component.SetContext(InputContextId.UI);
_gameObject.SetActive(false);
_gameObject.SetActive(true);
InputActionMap globalMap = FindMap(InputContextId.Global);
InputActionMap uiMap = FindMap(InputContextId.UI);
Assert.That(globalMap.enabled, Is.True);
Assert.That(uiMap.enabled, Is.True);
}
[Test]
public void DialogOverlayOnGameplayExplore_DisablesGameplayAndRestoresOnPop()
{
InitializeWithDefaultActions();
_component.SetContext(InputContextId.GameplayExplore);
InputActionMap globalMap = FindMap(InputContextId.Global);
InputActionMap geMap = FindMap(InputContextId.GameplayExplore);
InputActionMap dialogMap = FindMap(InputContextId.Dialog);
Assert.That(geMap.enabled, Is.True);
Assert.That(dialogMap.enabled, Is.False);
_component.PushContext(InputContextId.Dialog);
Assert.That(globalMap.enabled, Is.True);
Assert.That(geMap.enabled, Is.False);
Assert.That(dialogMap.enabled, Is.True);
_component.PopContext();
Assert.That(globalMap.enabled, Is.True);
Assert.That(geMap.enabled, Is.True);
Assert.That(dialogMap.enabled, Is.False);
}
[Test]
public void DialogOverlayOnUI_DisablesUIAndRestoresOnPop()
{
InitializeWithDefaultActions();
_component.SetContext(InputContextId.UI);
InputActionMap uiMap = FindMap(InputContextId.UI);
InputActionMap dialogMap = FindMap(InputContextId.Dialog);
Assert.That(uiMap.enabled, Is.True);
Assert.That(dialogMap.enabled, Is.False);
_component.PushContext(InputContextId.Dialog);
Assert.That(uiMap.enabled, Is.False);
Assert.That(dialogMap.enabled, Is.True);
_component.PopContext();
Assert.That(uiMap.enabled, Is.True);
Assert.That(dialogMap.enabled, Is.False);
}
[Test]
public void FullWorkflow_SetGameplay_PushDialog_Pop_SetUI_PushDialog_Clear()
{
InitializeWithDefaultActions();
InputActionMap globalMap = FindMap(InputContextId.Global);
InputActionMap geMap = FindMap(InputContextId.GameplayExplore);
InputActionMap uiMap = FindMap(InputContextId.UI);
InputActionMap dialogMap = FindMap(InputContextId.Dialog);
_component.SetContext(InputContextId.GameplayExplore);
Assert.That(geMap.enabled, Is.True);
Assert.That(uiMap.enabled, Is.False);
Assert.That(dialogMap.enabled, Is.False);
_component.PushContext(InputContextId.Dialog);
Assert.That(geMap.enabled, Is.False);
Assert.That(dialogMap.enabled, Is.True);
_component.PopContext();
Assert.That(geMap.enabled, Is.True);
Assert.That(dialogMap.enabled, Is.False);
_component.SetContext(InputContextId.UI);
Assert.That(geMap.enabled, Is.False);
Assert.That(uiMap.enabled, Is.True);
Assert.That(dialogMap.enabled, Is.False);
_component.PushContext(InputContextId.Dialog);
Assert.That(uiMap.enabled, Is.False);
Assert.That(dialogMap.enabled, Is.True);
_component.ClearContexts();
Assert.That(globalMap.enabled, Is.True);
Assert.That(geMap.enabled, Is.False);
Assert.That(uiMap.enabled, Is.False);
Assert.That(dialogMap.enabled, Is.False);
}
[Test]
public void PopEmptyStackReturnsFalse()
{
InitializeWithDefaultActions();
Assert.That(_component.PopContext(), Is.False);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c0d22ce7480ca4642ba4cc6620d22051
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,259 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using NUnit.Framework;
using SepCore.InputModule;
using SepCore.InputModule.Runtime;
using UnityEngine;
namespace SepCore.InputModule.Tests
{
public class InputModuleComponentEventTests
{
private GameObject _gameObject;
private InputModuleComponent _component;
[SetUp]
public void SetUp()
{
_gameObject = new GameObject("InputModuleEventTest");
_component = _gameObject.AddComponent<InputModuleComponent>();
_component.OnInit();
}
[TearDown]
public void TearDown()
{
UnityEngine.Object.DestroyImmediate(_gameObject);
}
[Test]
public void ContextChanged_FiresOnSetContext()
{
InputContextId receivedContext = InputContextId.None;
int fireCount = 0;
_component.ContextChanged += ctx =>
{
receivedContext = ctx;
fireCount++;
};
_component.SetContext(InputContextId.UI);
Assert.That(fireCount, Is.EqualTo(1));
Assert.That(receivedContext, Is.EqualTo(InputContextId.UI));
}
[Test]
public void ContextChanged_FiresOnPushContext()
{
InputContextId receivedContext = InputContextId.None;
_component.ContextChanged += ctx => receivedContext = ctx;
_component.PushContext(InputContextId.Dialog);
Assert.That(receivedContext, Is.EqualTo(InputContextId.Dialog));
}
[Test]
public void ContextChanged_FiresOnPopContext()
{
_component.PushContext(InputContextId.UI);
InputContextId receivedContext = InputContextId.None;
_component.ContextChanged += ctx => receivedContext = ctx;
_component.PopContext();
Assert.That(receivedContext, Is.EqualTo(InputContextId.None));
}
[Test]
public void ContextChanged_FiresOnClearContexts()
{
_component.SetContext(InputContextId.GameplayExplore);
InputContextId receivedContext = InputContextId.None;
_component.ContextChanged += ctx => receivedContext = ctx;
_component.ClearContexts();
Assert.That(receivedContext, Is.EqualTo(InputContextId.None));
}
[Test]
public void ContextChanged_DoesNotFireOnDuplicateSet()
{
_component.SetContext(InputContextId.UI);
int fireCount = 0;
_component.ContextChanged += _ => fireCount++;
_component.SetContext(InputContextId.UI);
Assert.That(fireCount, Is.EqualTo(0));
}
[Test]
public void CurrentContext_ReflectsStackState()
{
Assert.That(_component.CurrentContext, Is.EqualTo(InputContextId.None));
_component.SetContext(InputContextId.GameplayExplore);
Assert.That(_component.CurrentContext, Is.EqualTo(InputContextId.GameplayExplore));
_component.PushContext(InputContextId.Dialog);
Assert.That(_component.CurrentContext, Is.EqualTo(InputContextId.Dialog));
_component.PopContext();
Assert.That(_component.CurrentContext, Is.EqualTo(InputContextId.GameplayExplore));
}
[Test]
public void CurrentDeviceKind_DefaultsToUnknown()
{
Assert.That(_component.CurrentDeviceKind, Is.EqualTo(InputDeviceKind.Unknown));
}
[Test]
public void RegisterListener_AddsToInternalDictionary()
{
bool called = false;
Action<InputCommand> listener = _ => called = true;
_component.RegisterListener(InputActionId.Pause, listener);
Dictionary<InputActionId, Action<InputCommand>> listeners =
GetPrivateListenersDictionary();
Assert.That(listeners.ContainsKey(InputActionId.Pause), Is.True);
}
[Test]
public void UnregisterListener_RemovesFromInternalDictionary()
{
Action<InputCommand> listener = _ => { };
_component.RegisterListener(InputActionId.Pause, listener);
_component.UnregisterListener(InputActionId.Pause, listener);
Dictionary<InputActionId, Action<InputCommand>> listeners =
GetPrivateListenersDictionary();
Assert.That(listeners.ContainsKey(InputActionId.Pause), Is.False);
}
[Test]
public void RegisterListener_ChainsMultipleListeners()
{
int callCount = 0;
Action<InputCommand> listenerA = _ => callCount++;
Action<InputCommand> listenerB = _ => callCount++;
_component.RegisterListener(InputActionId.Confirm, listenerA);
_component.RegisterListener(InputActionId.Confirm, listenerB);
Dictionary<InputActionId, Action<InputCommand>> listeners =
GetPrivateListenersDictionary();
Assert.That(listeners.ContainsKey(InputActionId.Confirm), Is.True);
// Verify both listeners are registered by invoking the combined delegate
listeners[InputActionId.Confirm].Invoke(default);
Assert.That(callCount, Is.EqualTo(2));
}
[Test]
public void UnregisterListener_RemovesOnlySpecifiedCallback()
{
int callCount = 0;
Action<InputCommand> listenerA = _ => callCount++;
Action<InputCommand> listenerB = _ => callCount += 10;
_component.RegisterListener(InputActionId.Cancel, listenerA);
_component.RegisterListener(InputActionId.Cancel, listenerB);
_component.UnregisterListener(InputActionId.Cancel, listenerA);
Dictionary<InputActionId, Action<InputCommand>> listeners =
GetPrivateListenersDictionary();
listeners[InputActionId.Cancel].Invoke(default);
Assert.That(callCount, Is.EqualTo(10));
}
[Test]
public void RegisterListener_NullCallback_DoesNotThrow()
{
Assert.DoesNotThrow(() => _component.RegisterListener(InputActionId.Pause, null));
}
[Test]
public void UnregisterListener_NeverRegistered_DoesNotThrow()
{
Assert.DoesNotThrow(() => _component.UnregisterListener(InputActionId.Pause, _ => { }));
}
[Test]
public void PromptMap_DefaultsToDefaultPromptMap()
{
IInputPromptMap promptMap = _component.PromptMap;
Assert.That(promptMap, Is.Not.Null);
Assert.That(promptMap, Is.InstanceOf<InputModuleDefaultPromptMap>());
}
[Test]
public void PromptMap_CanBeOverridden()
{
IInputPromptMap custom = new TestPromptMap();
_component.PromptMap = custom;
Assert.That(_component.PromptMap, Is.SameAs(custom));
}
[Test]
public void TryGetPrompt_UsesDefaultMap()
{
// CurrentDeviceKind defaults to Unknown; default map has no Unknown entries
_component.PromptMap.TryGetPrompt(InputActionId.Confirm, InputDeviceKind.KeyboardMouse, out InputPrompt prompt);
Assert.That(prompt.TextLabel, Is.EqualTo("Enter"));
}
[Test]
public void TryGetPrompt_UnknownAction_ReturnsFalse()
{
bool result = _component.TryGetPrompt(InputActionId.Unknown, out InputPrompt prompt);
Assert.That(result, Is.False);
Assert.That(prompt.IsValid, Is.False);
}
[Test]
public void TryGetPrompt_NullPromptMap_ReturnsFalse()
{
_component.PromptMap = null;
bool result = _component.TryGetPrompt(InputActionId.Confirm, out InputPrompt prompt);
Assert.That(result, Is.False);
}
private Dictionary<InputActionId, Action<InputCommand>> GetPrivateListenersDictionary()
{
FieldInfo field = typeof(InputModuleComponent).GetField(
"_listeners",
BindingFlags.NonPublic | BindingFlags.Instance);
return (Dictionary<InputActionId, Action<InputCommand>>)field.GetValue(_component);
}
}
internal sealed class TestPromptMap : IInputPromptMap
{
public bool TryGetPrompt(InputActionId actionId, InputDeviceKind deviceKind, out InputPrompt prompt)
{
prompt = new InputPrompt("Test");
return true;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 253f65bb2bca7be4cb01d2244cb3d2fc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,214 @@
using System.Collections;
using NUnit.Framework;
using SepCore.InputModule;
using SepCore.InputModule.Runtime;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.TestTools;
namespace SepCore.InputModule.Tests
{
public class InputModuleComponentRebindTests : InputTestFixture
{
private GameObject _gameObject;
private InputModuleComponent _component;
public override void Setup()
{
base.Setup();
_gameObject = new GameObject("InputModuleRebindTest");
_component = _gameObject.AddComponent<InputModuleComponent>();
_component.OnInit();
}
public override void TearDown()
{
Object.DestroyImmediate(_gameObject);
base.TearDown();
}
[Test]
public void StartRebinding_ValidBinding_ReturnsTrueAndSetsIsRebinding()
{
bool started = _component.StartRebinding(InputContextId.UI, InputActionId.Confirm, 0);
Assert.That(started, Is.True);
Assert.That(_component.IsRebinding, Is.True);
_component.CancelRebinding();
}
[Test]
public void StartRebinding_AlreadyRebinding_ReturnsFalse()
{
_component.StartRebinding(InputContextId.UI, InputActionId.Confirm, 0);
bool started = _component.StartRebinding(InputContextId.UI, InputActionId.Confirm, 1);
Assert.That(started, Is.False);
_component.CancelRebinding();
}
[Test]
public void StartRebinding_GlobalAction_ReturnsTrueAndSetsIsRebinding()
{
bool started = _component.StartRebinding(InputContextId.Global, InputActionId.Pause, 0);
Assert.That(started, Is.True);
Assert.That(_component.IsRebinding, Is.True);
_component.CancelRebinding();
}
[Test]
public void StartRebinding_InvalidBindingIndex_ReturnsFalse()
{
bool started = _component.StartRebinding(InputContextId.UI, InputActionId.Confirm, 99);
Assert.That(started, Is.False);
}
[Test]
public void CancelRebinding_InvokesRebindCompletedWithCanceled()
{
RebindResult result = default;
_component.RebindCompleted += r => result = r;
_component.StartRebinding(InputContextId.UI, InputActionId.Confirm, 0);
_component.CancelRebinding();
Assert.That(result.Status, Is.EqualTo(RebindStatus.Canceled));
Assert.That(_component.IsRebinding, Is.False);
}
[Test]
public void RebindTimeout_InvokesRebindCompletedWithTimeout()
{
RebindResult result = default;
_component.RebindCompleted += r => result = r;
_component.StartRebinding(InputContextId.UI, InputActionId.Confirm, 0, timeoutSeconds: 0.05f);
currentTime += 0.1;
InputSystem.Update();
Assert.That(result.Status, Is.EqualTo(RebindStatus.Timeout));
Assert.That(_component.IsRebinding, Is.False);
}
[UnityTest]
public IEnumerator Rebind_WithExpectedDeviceKind_AcceptsMatchingDevice()
{
RebindResult result = default;
_component.RebindCompleted += r => result = r;
Keyboard keyboard = InputSystem.AddDevice<Keyboard>();
_component.StartRebinding(InputContextId.UI, InputActionId.Confirm, 0, expectedDeviceKind: InputDeviceKind.KeyboardMouse);
Press(keyboard.spaceKey);
yield return null;
Assert.That(result.Status, Is.EqualTo(RebindStatus.Succeeded));
Assert.That(result.Path, Is.EqualTo("<Keyboard>/space"));
}
[UnityTest]
public IEnumerator Rebind_WithExpectedDeviceKind_RejectsWrongDevice()
{
RebindResult result = default;
_component.RebindCompleted += r => result = r;
Keyboard keyboard = InputSystem.AddDevice<Keyboard>();
_component.StartRebinding(InputContextId.UI, InputActionId.Confirm, 0, expectedDeviceKind: InputDeviceKind.Gamepad);
Press(keyboard.spaceKey);
yield return null;
Assert.That(result.Status, Is.EqualTo(RebindStatus.Canceled));
}
[UnityTest]
public IEnumerator Rebind_WithConflict_RejectsAndRestoresPreviousPath()
{
InputAction pauseAction = _component.RuntimeActions.FindAction($"{nameof(InputContextId.Global)}/{nameof(InputActionId.Pause)}");
pauseAction.ApplyBindingOverride("<Keyboard>/space");
RebindResult result = default;
_component.RebindCompleted += r => result = r;
Keyboard keyboard = InputSystem.AddDevice<Keyboard>();
_component.StartRebinding(InputContextId.UI, InputActionId.Confirm, 0);
Press(keyboard.spaceKey);
yield return null;
Assert.That(result.Status, Is.EqualTo(RebindStatus.ConflictDetected));
Assert.That(result.PreviousPath, Is.EqualTo("<Keyboard>/enter"));
InputAction confirmAction = _component.RuntimeActions.FindAction($"{nameof(InputContextId.UI)}/{nameof(InputActionId.Confirm)}");
Assert.That(confirmAction.bindings[0].effectivePath, Is.EqualTo("<Keyboard>/enter"));
}
[UnityTest]
public IEnumerator Rebind_Completes_RestoresPreviousContext()
{
_component.SetContext(InputContextId.GameplayExplore);
Assert.That(_component.CurrentContext, Is.EqualTo(InputContextId.GameplayExplore));
Keyboard keyboard = InputSystem.AddDevice<Keyboard>();
_component.StartRebinding(InputContextId.UI, InputActionId.Confirm, 0);
Press(keyboard.spaceKey);
yield return null;
Assert.That(_component.CurrentContext, Is.EqualTo(InputContextId.GameplayExplore));
}
[Test]
public void ResetBindingToDefault_RemovesOverride()
{
InputAction confirmAction = _component.RuntimeActions.FindAction($"{nameof(InputContextId.UI)}/{nameof(InputActionId.Confirm)}");
confirmAction.ApplyBindingOverride(0, "<Keyboard>/space");
_component.ResetBindingToDefault(InputContextId.UI, InputActionId.Confirm, 0);
Assert.That(confirmAction.bindings[0].overridePath, Is.Null);
}
[Test]
public void ResetActionToDefaults_RemovesAllOverridesForAction()
{
InputAction confirmAction = _component.RuntimeActions.FindAction($"{nameof(InputContextId.UI)}/{nameof(InputActionId.Confirm)}");
confirmAction.ApplyBindingOverride(0, "<Keyboard>/space");
confirmAction.ApplyBindingOverride(1, "<Keyboard>/f");
_component.ResetActionToDefaults(InputContextId.UI, InputActionId.Confirm);
Assert.That(confirmAction.bindings[0].overridePath, Is.Null);
Assert.That(confirmAction.bindings[1].overridePath, Is.Null);
}
[Test]
public void ResetAllBindingsToDefaults_RemovesAllOverrides()
{
InputAction confirmAction = _component.RuntimeActions.FindAction($"{nameof(InputContextId.UI)}/{nameof(InputActionId.Confirm)}");
confirmAction.ApplyBindingOverride(0, "<Keyboard>/space");
_component.ResetAllBindingsToDefaults();
Assert.That(confirmAction.bindings[0].overridePath, Is.Null);
}
[Test]
public void ApplyBindingSnapshot_AfterReset_RestoresOverrides()
{
InputAction confirmAction = _component.RuntimeActions.FindAction($"{nameof(InputContextId.UI)}/{nameof(InputActionId.Confirm)}");
confirmAction.ApplyBindingOverride(0, "<Keyboard>/space");
InputBindingSnapshot snapshot = _component.SaveBindingOverrides();
_component.ResetAllBindingsToDefaults();
Assert.That(confirmAction.bindings[0].overridePath, Is.Null);
_component.ApplyBindingSnapshot(snapshot);
Assert.That(confirmAction.bindings[0].effectivePath, Is.EqualTo("<Keyboard>/space"));
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c174bb2bfc177564684cf21b14e02393
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,122 @@
using System.Collections.Generic;
using System.Reflection;
using NUnit.Framework;
using SepCore.InputModule;
using SepCore.InputModule.Runtime;
using UnityEngine;
using UnityEngine.InputSystem;
namespace SepCore.InputModule.Tests
{
public class InputModuleDebuggerReflectionTests
{
private GameObject _gameObject;
private InputModuleComponent _component;
[SetUp]
public void SetUp()
{
_gameObject = new GameObject("InputModuleDebuggerReflectionTest");
_component = _gameObject.AddComponent<InputModuleComponent>();
}
[TearDown]
public void TearDown()
{
Object.DestroyImmediate(_gameObject);
}
[Test]
public void CanReadContextStackViaReflection()
{
_component.OnInit();
_component.SetContext(InputContextId.UI);
_component.PushContext(InputContextId.Dialog);
FieldInfo stackField = typeof(InputModuleComponent).GetField("_contextStack", BindingFlags.Instance | BindingFlags.NonPublic);
Assert.That(stackField, Is.Not.Null, "_contextStack field should exist");
object stack = stackField.GetValue(_component);
Assert.That(stack, Is.Not.Null);
Assert.That(stack, Is.InstanceOf<InputContextStack>());
PropertyInfo countProp = typeof(InputContextStack).GetProperty("Count", BindingFlags.Instance | BindingFlags.Public);
PropertyInfo itemsProp = typeof(InputContextStack).GetProperty("Items", BindingFlags.Instance | BindingFlags.Public);
Assert.That(countProp, Is.Not.Null, "Count property should exist");
Assert.That(itemsProp, Is.Not.Null, "Items property should exist");
int count = (int)countProp.GetValue(stack);
IReadOnlyList<InputContextId> items = itemsProp.GetValue(stack) as IReadOnlyList<InputContextId>;
Assert.That(count, Is.EqualTo(2));
Assert.That(items, Is.Not.Null);
Assert.That(items.Count, Is.EqualTo(2));
Assert.That(items[0], Is.EqualTo(InputContextId.UI));
Assert.That(items[1], Is.EqualTo(InputContextId.Dialog));
}
[Test]
public void CanReadActionMapsViaReflection()
{
_component.OnInit();
FieldInfo mapsField = typeof(InputModuleComponent).GetField("_actionMaps", BindingFlags.Instance | BindingFlags.NonPublic);
Assert.That(mapsField, Is.Not.Null, "_actionMaps field should exist");
object mapsObj = mapsField.GetValue(_component);
Assert.That(mapsObj, Is.Not.Null);
Assert.That(mapsObj, Is.InstanceOf<Dictionary<InputContextId, InputActionMap>>());
Dictionary<InputContextId, InputActionMap> maps = (Dictionary<InputContextId, InputActionMap>)mapsObj;
Assert.That(maps.Count, Is.EqualTo(5));
Assert.That(maps, Contains.Key(InputContextId.Global));
Assert.That(maps, Contains.Key(InputContextId.UI));
Assert.That(maps, Contains.Key(InputContextId.GameplayExplore));
Assert.That(maps, Contains.Key(InputContextId.Dialog));
Assert.That(maps, Contains.Key(InputContextId.Rebind));
}
[Test]
public void ActionMapsReflectEnableState()
{
_component.OnInit();
_component.SetContext(InputContextId.GameplayExplore);
FieldInfo mapsField = typeof(InputModuleComponent).GetField("_actionMaps", BindingFlags.Instance | BindingFlags.NonPublic);
Dictionary<InputContextId, InputActionMap> maps = (Dictionary<InputContextId, InputActionMap>)mapsField.GetValue(_component);
Assert.That(maps[InputContextId.Global].enabled, Is.True);
Assert.That(maps[InputContextId.GameplayExplore].enabled, Is.True);
Assert.That(maps[InputContextId.UI].enabled, Is.False);
_component.PushContext(InputContextId.Dialog);
Assert.That(maps[InputContextId.GameplayExplore].enabled, Is.False);
Assert.That(maps[InputContextId.Dialog].enabled, Is.True);
}
[Test]
public void ContextStackReflectsPopAndClear()
{
_component.OnInit();
_component.SetContext(InputContextId.UI);
_component.PushContext(InputContextId.Dialog);
FieldInfo stackField = typeof(InputModuleComponent).GetField("_contextStack", BindingFlags.Instance | BindingFlags.NonPublic);
PropertyInfo countProp = typeof(InputContextStack).GetProperty("Count", BindingFlags.Instance | BindingFlags.Public);
PropertyInfo itemsProp = typeof(InputContextStack).GetProperty("Items", BindingFlags.Instance | BindingFlags.Public);
object stack = stackField.GetValue(_component);
Assert.That(countProp.GetValue(stack), Is.EqualTo(2));
_component.PopContext();
Assert.That(countProp.GetValue(stack), Is.EqualTo(1));
IReadOnlyList<InputContextId> itemsAfterPop = itemsProp.GetValue(stack) as IReadOnlyList<InputContextId>;
Assert.That(itemsAfterPop[0], Is.EqualTo(InputContextId.UI));
_component.ClearContexts();
Assert.That(countProp.GetValue(stack), Is.EqualTo(0));
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ece8581965c25a14b88d3fca80c20f69
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,141 @@
using NUnit.Framework;
using UnityEngine.InputSystem;
namespace SepCore.InputModule.Runtime.Tests
{
public class InputModuleDefaultActionsTests
{
[Test]
public void CreateBuildsExpectedActionMaps()
{
InputActionAsset asset = InputModuleDefaultActions.Create();
Assert.That(asset.FindActionMap(nameof(InputContextId.Global), throwIfNotFound: false), Is.Not.Null);
Assert.That(asset.FindActionMap(nameof(InputContextId.UI), throwIfNotFound: false), Is.Not.Null);
Assert.That(asset.FindActionMap(nameof(InputContextId.GameplayExplore), throwIfNotFound: false), Is.Not.Null);
Assert.That(asset.FindActionMap(nameof(InputContextId.Dialog), throwIfNotFound: false), Is.Not.Null);
}
[Test]
public void CreateBuildsCoreActions()
{
InputActionAsset asset = InputModuleDefaultActions.Create();
Assert.That(asset.FindAction($"{nameof(InputContextId.Global)}/{nameof(InputActionId.Pause)}", throwIfNotFound: false), Is.Not.Null);
Assert.That(asset.FindAction($"{nameof(InputContextId.UI)}/{nameof(InputActionId.Confirm)}", throwIfNotFound: false), Is.Not.Null);
InputAction moveAction = asset.FindAction($"{nameof(InputContextId.GameplayExplore)}/{nameof(InputActionId.Move)}", throwIfNotFound: false);
Assert.That(moveAction, Is.Not.Null);
Assert.That(moveAction.expectedControlType, Is.EqualTo("Vector2"));
}
[Test]
public void GlobalMapContainsPauseAction()
{
InputActionAsset asset = InputModuleDefaultActions.Create();
InputActionMap globalMap = asset.FindActionMap(nameof(InputContextId.Global));
Assert.That(globalMap, Is.Not.Null);
InputAction pause = globalMap.FindAction(nameof(InputActionId.Pause));
Assert.That(pause, Is.Not.Null);
Assert.That(pause.type, Is.EqualTo(InputActionType.Button));
}
[Test]
public void UIMapContainsExpectedActions()
{
InputActionAsset asset = InputModuleDefaultActions.Create();
InputActionMap uiMap = asset.FindActionMap(nameof(InputContextId.UI));
Assert.That(uiMap, Is.Not.Null);
Assert.That(uiMap.FindAction(nameof(InputActionId.Navigate)), Is.Not.Null);
Assert.That(uiMap.FindAction(nameof(InputActionId.Confirm)), Is.Not.Null);
Assert.That(uiMap.FindAction(nameof(InputActionId.Cancel)), Is.Not.Null);
}
[Test]
public void GameplayExploreMapContainsExpectedActions()
{
InputActionAsset asset = InputModuleDefaultActions.Create();
InputActionMap geMap = asset.FindActionMap(nameof(InputContextId.GameplayExplore));
Assert.That(geMap, Is.Not.Null);
Assert.That(geMap.FindAction(nameof(InputActionId.Move)), Is.Not.Null);
Assert.That(geMap.FindAction(nameof(InputActionId.Sprint)), Is.Not.Null);
Assert.That(geMap.FindAction(nameof(InputActionId.Interact)), Is.Not.Null);
}
[Test]
public void DialogMapContainsExpectedActions()
{
InputActionAsset asset = InputModuleDefaultActions.Create();
InputActionMap dialogMap = asset.FindActionMap(nameof(InputContextId.Dialog));
Assert.That(dialogMap, Is.Not.Null);
Assert.That(dialogMap.FindAction(nameof(InputActionId.Navigate)), Is.Not.Null);
Assert.That(dialogMap.FindAction(nameof(InputActionId.Confirm)), Is.Not.Null);
Assert.That(dialogMap.FindAction(nameof(InputActionId.Cancel)), Is.Not.Null);
}
[Test]
public void DialogConfirmHasKeyboardAndGamepadBindings()
{
InputActionAsset asset = InputModuleDefaultActions.Create();
InputAction confirm = asset.FindAction($"{nameof(InputContextId.Dialog)}/{nameof(InputActionId.Confirm)}");
Assert.That(confirm.bindings.Count, Is.GreaterThanOrEqualTo(3));
}
[Test]
public void ConfirmHasKeyboardAndGamepadBindings()
{
InputActionAsset asset = InputModuleDefaultActions.Create();
InputAction confirm = asset.FindAction($"{nameof(InputContextId.UI)}/{nameof(InputActionId.Confirm)}");
Assert.That(confirm.bindings.Count, Is.GreaterThanOrEqualTo(3));
}
[Test]
public void MoveIsVector2ValueType()
{
InputActionAsset asset = InputModuleDefaultActions.Create();
InputAction move = asset.FindAction($"{nameof(InputContextId.GameplayExplore)}/{nameof(InputActionId.Move)}");
Assert.That(move.expectedControlType, Is.EqualTo("Vector2"));
Assert.That(move.type, Is.EqualTo(InputActionType.Value));
}
[Test]
public void NavigateIsVector2ValueType()
{
InputActionAsset asset = InputModuleDefaultActions.Create();
InputAction navigate = asset.FindAction($"{nameof(InputContextId.UI)}/{nameof(InputActionId.Navigate)}");
Assert.That(navigate.expectedControlType, Is.EqualTo("Vector2"));
Assert.That(navigate.type, Is.EqualTo(InputActionType.Value));
}
[Test]
public void AllMapsHaveAtLeastOneAction()
{
InputActionAsset asset = InputModuleDefaultActions.Create();
foreach (InputActionMap map in asset.actionMaps)
{
// Rebind map is intentionally empty — it serves only as a context stack placeholder.
if (map.name == nameof(InputContextId.Rebind))
continue;
Assert.That(map.actions.Count, Is.GreaterThanOrEqualTo(1), $"Map '{map.name}' has no actions.");
}
}
[Test]
public void SaveAndLoadBindingOverridesRoundTrips()
{
InputActionAsset asset = InputModuleDefaultActions.Create();
string json = asset.SaveBindingOverridesAsJson();
InputAction pause = asset.FindAction($"{nameof(InputContextId.Global)}/{nameof(InputActionId.Pause)}");
pause.ApplyBindingOverride("<Keyboard>/space");
string modifiedJson = asset.SaveBindingOverridesAsJson();
Assert.That(modifiedJson, Is.Not.EqualTo(json));
asset.LoadBindingOverridesFromJson(json);
string restoredJson = asset.SaveBindingOverridesAsJson();
Assert.That(restoredJson, Is.EqualTo(json));
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 76ebe55145921034c8a9c2cf80899046
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,129 @@
using NUnit.Framework;
using SepCore.InputModule;
using SepCore.InputModule.Runtime;
namespace SepCore.InputModule.Tests
{
public class InputModuleDefaultPromptMapTests
{
private InputModuleDefaultPromptMap _map;
[SetUp]
public void SetUp()
{
_map = new InputModuleDefaultPromptMap();
}
[Test]
public void TryGetPrompt_AllActionsHaveKeyboardMousePrompt()
{
InputActionId[] actions =
{
InputActionId.Pause,
InputActionId.Navigate,
InputActionId.Confirm,
InputActionId.Cancel,
InputActionId.Move,
InputActionId.Sprint,
InputActionId.Interact,
};
foreach (InputActionId action in actions)
{
bool result = _map.TryGetPrompt(action, InputDeviceKind.KeyboardMouse, out InputPrompt prompt);
Assert.That(result, Is.True, $"KeyboardMouse prompt missing for {action}");
Assert.That(prompt.IsValid, Is.True, $"KeyboardMouse prompt invalid for {action}");
}
}
[Test]
public void TryGetPrompt_AllActionsHaveGamepadPrompt()
{
InputActionId[] actions =
{
InputActionId.Pause,
InputActionId.Navigate,
InputActionId.Confirm,
InputActionId.Cancel,
InputActionId.Move,
InputActionId.Sprint,
InputActionId.Interact,
};
foreach (InputActionId action in actions)
{
bool result = _map.TryGetPrompt(action, InputDeviceKind.Gamepad, out InputPrompt prompt);
Assert.That(result, Is.True, $"Gamepad prompt missing for {action}");
Assert.That(prompt.IsValid, Is.True, $"Gamepad prompt invalid for {action}");
}
}
[Test]
public void TryGetPrompt_TouchHasPartialCoverage()
{
Assert.That(_map.TryGetPrompt(InputActionId.Confirm, InputDeviceKind.Touch, out _), Is.True);
Assert.That(_map.TryGetPrompt(InputActionId.Cancel, InputDeviceKind.Touch, out _), Is.True);
Assert.That(_map.TryGetPrompt(InputActionId.Interact, InputDeviceKind.Touch, out _), Is.True);
Assert.That(_map.TryGetPrompt(InputActionId.Sprint, InputDeviceKind.Touch, out _), Is.False);
}
[Test]
public void TryGetPrompt_UnknownDevice_ReturnsFalse()
{
foreach (InputActionId action in new[]
{
InputActionId.Pause,
InputActionId.Confirm,
InputActionId.Interact,
})
{
Assert.That(_map.TryGetPrompt(action, InputDeviceKind.Unknown, out _), Is.False);
}
}
[Test]
public void TryGetPrompt_UnknownAction_ReturnsFalse()
{
Assert.That(_map.TryGetPrompt(InputActionId.Unknown, InputDeviceKind.KeyboardMouse, out _), Is.False);
Assert.That(_map.TryGetPrompt(InputActionId.Unknown, InputDeviceKind.Gamepad, out _), Is.False);
}
[Test]
public void TryGetPrompt_PauseKeyboardMouse_ReturnsEsc()
{
_map.TryGetPrompt(InputActionId.Pause, InputDeviceKind.KeyboardMouse, out InputPrompt prompt);
Assert.That(prompt.TextLabel, Is.EqualTo("Esc"));
}
[Test]
public void TryGetPrompt_ConfirmGamepad_ReturnsA()
{
_map.TryGetPrompt(InputActionId.Confirm, InputDeviceKind.Gamepad, out InputPrompt prompt);
Assert.That(prompt.TextLabel, Is.EqualTo("A"));
}
[Test]
public void TryGetPrompt_InteractKeyboardMouse_ReturnsE()
{
_map.TryGetPrompt(InputActionId.Interact, InputDeviceKind.KeyboardMouse, out InputPrompt prompt);
Assert.That(prompt.TextLabel, Is.EqualTo("E"));
}
[Test]
public void TryGetPrompt_MoveKeyboardMouse_ReturnsWASD()
{
_map.TryGetPrompt(InputActionId.Move, InputDeviceKind.KeyboardMouse, out InputPrompt prompt);
Assert.That(prompt.TextLabel, Is.EqualTo("WASD"));
}
[Test]
public void TryGetPrompt_SprintTouch_ReturnsFalse()
{
Assert.That(_map.TryGetPrompt(InputActionId.Sprint, InputDeviceKind.Touch, out _), Is.False);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e5f6a7b8c9d0e1f2a3b4c5d6a7b8c9d0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,89 @@
using NUnit.Framework;
using SepCore.InputModule;
namespace SepCore.InputModule.Tests
{
public class InputPromptTests
{
[Test]
public void Constructor_SetsTextLabel()
{
InputPrompt prompt = new InputPrompt("A");
Assert.That(prompt.TextLabel, Is.EqualTo("A"));
}
[Test]
public void Constructor_NullTextLabel_ReturnsEmpty()
{
InputPrompt prompt = new InputPrompt(null);
Assert.That(prompt.TextLabel, Is.EqualTo(string.Empty));
}
[Test]
public void Constructor_SetsSpriteName()
{
InputPrompt prompt = new InputPrompt("A", "gamepad_a");
Assert.That(prompt.SpriteName, Is.EqualTo("gamepad_a"));
}
[Test]
public void Constructor_NullSpriteName_ReturnsEmpty()
{
InputPrompt prompt = new InputPrompt("A", null);
Assert.That(prompt.SpriteName, Is.EqualTo(string.Empty));
}
[Test]
public void Constructor_DefaultSpriteName_IsEmpty()
{
InputPrompt prompt = new InputPrompt("A");
Assert.That(prompt.SpriteName, Is.EqualTo(string.Empty));
}
[Test]
public void HasSprite_WithSpriteName_ReturnsTrue()
{
InputPrompt prompt = new InputPrompt("A", "gamepad_a");
Assert.That(prompt.HasSprite, Is.True);
}
[Test]
public void HasSprite_WithoutSpriteName_ReturnsFalse()
{
InputPrompt prompt = new InputPrompt("A");
Assert.That(prompt.HasSprite, Is.False);
}
[Test]
public void IsValid_WithTextLabel_ReturnsTrue()
{
InputPrompt prompt = new InputPrompt("A");
Assert.That(prompt.IsValid, Is.True);
}
[Test]
public void IsValid_WithoutTextLabel_ReturnsFalse()
{
InputPrompt prompt = new InputPrompt(string.Empty);
Assert.That(prompt.IsValid, Is.False);
}
[Test]
public void None_HasEmptyFields()
{
Assert.That(InputPrompt.None.TextLabel, Is.EqualTo(string.Empty));
Assert.That(InputPrompt.None.SpriteName, Is.EqualTo(string.Empty));
Assert.That(InputPrompt.None.IsValid, Is.False);
Assert.That(InputPrompt.None.HasSprite, Is.False);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d4e5f6a7b8c9d0e1f2a3b4c5d6a7b8c9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,27 @@
{
"name": "SepCore.InputModule.Tests",
"rootNamespace": "",
"references": [
"GUID:75469ad4d38634e559750d17036d5f7c",
"GUID:27619889b8ba8c24980f49ee34dbb44a",
"GUID:0acc523941302664db1f4e527237feb3",
"GUID:d54b9488b03814a44ab937f0aeb738b1",
"GUID:363c5eb08ff8e6a439b85e37b8c20d96",
"GUID:dc04f38471c3a459fb4d31124ee9127d",
"GUID:436e23dbdc31e7d4fb5c3f804548b2df"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": [
"nunit.framework.dll"
],
"autoReferenced": false,
"defineConstraints": [
"UNITY_INCLUDE_TESTS",
"UNITY_INCLUDE_TESTS"
],
"versionDefines": [],
"noEngineReferences": false
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 58880dcb779e0c644b335f0962ec433c
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: