Files
Test/Library/PackageCache/com.unity.ugui@eb824e41fbc7/Tests/Editor/UGUI/EventSystem/InputModuleTests.cs
T
2026-11-01 23:39:55 +02:00

56 lines
2.0 KiB
C#

using NUnit.Framework;
using UnityEngine;
using UnityEditor.EventSystems;
using UnityEngine.EventSystems;
[TestFixture]
internal class InputModuleTests
{
private EventSystem m_EventSystem;
[SetUp]
public void Setup()
{
m_EventSystem = new GameObject("EventSystem").AddComponent<EventSystem>();
}
[TearDown]
public void TearDown()
{
Object.DestroyImmediate(m_EventSystem.gameObject);
}
[Test]
public void InputModuleComponentFactory_AddComponent_CanBeOverriden()
{
// Reset the current override
var current = InputModuleComponentFactory.InputModuleComponentOverride;
InputModuleComponentFactory.SetInputModuleComponentOverride(null);
// First call creates a StandaloneInputModule
var inputModule = InputModuleComponentFactory.AddInputModule(m_EventSystem.gameObject);
Assert.IsInstanceOf<StandaloneInputModule>(inputModule);
Object.DestroyImmediate(inputModule);
// After setting the override to a custom type, further calls use the custom type
InputModuleComponentFactory.SetInputModuleComponentOverride(go => go.AddComponent<TestInputModule>());
inputModule = InputModuleComponentFactory.AddInputModule(m_EventSystem.gameObject);
Assert.IsInstanceOf<TestInputModule>(inputModule);
Object.DestroyImmediate(inputModule);
// After setting the override to null, further calls use the StandaloneInputModule again
InputModuleComponentFactory.SetInputModuleComponentOverride(null);
inputModule = InputModuleComponentFactory.AddInputModule(m_EventSystem.gameObject);
Assert.IsInstanceOf<StandaloneInputModule>(inputModule);
Object.DestroyImmediate(inputModule);
// Set it back to it's original value
InputModuleComponentFactory.SetInputModuleComponentOverride(current);
}
internal class TestInputModule : BaseInputModule
{
public override void Process() { }
}
}