暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

InputModuleTests.cs 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using NUnit.Framework;
  2. using UnityEngine;
  3. using UnityEditor.EventSystems;
  4. using UnityEngine.EventSystems;
  5. [TestFixture]
  6. public class InputModuleTests
  7. {
  8. private EventSystem m_EventSystem;
  9. [SetUp]
  10. public void Setup()
  11. {
  12. m_EventSystem = new GameObject("EventSystem").AddComponent<EventSystem>();
  13. }
  14. [TearDown]
  15. public void TearDown()
  16. {
  17. Object.DestroyImmediate(m_EventSystem.gameObject);
  18. }
  19. [Test]
  20. public void InputModuleComponentFactory_AddComponent_CanBeOverriden()
  21. {
  22. // First call creates a StandaloneInputModule
  23. var inputModule = InputModuleComponentFactory.AddInputModule(m_EventSystem.gameObject);
  24. Assert.IsInstanceOf<StandaloneInputModule>(inputModule);
  25. Object.DestroyImmediate(inputModule);
  26. // After setting the override to a custom type, further calls use the custom type
  27. InputModuleComponentFactory.SetInputModuleComponentOverride(go => go.AddComponent<TestInputModule>());
  28. inputModule = InputModuleComponentFactory.AddInputModule(m_EventSystem.gameObject);
  29. Assert.IsInstanceOf<TestInputModule>(inputModule);
  30. Object.DestroyImmediate(inputModule);
  31. // After setting the override to null, further calls use the StandaloneInputModule again
  32. InputModuleComponentFactory.SetInputModuleComponentOverride(null);
  33. inputModule = InputModuleComponentFactory.AddInputModule(m_EventSystem.gameObject);
  34. Assert.IsInstanceOf<StandaloneInputModule>(inputModule);
  35. }
  36. public class TestInputModule : BaseInputModule
  37. {
  38. public override void Process() { }
  39. }
  40. }