Unity 2018 testing fixes

pull/413/head
Simon (darkside) Jackson 2020-10-21 18:57:03 +01:00
parent a354a22a13
commit 9ac3b24818
2 changed files with 36 additions and 37 deletions

View File

@ -5,7 +5,6 @@
using System; using System;
using UnityEngine.Events; using UnityEngine.Events;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
using UnityEngine.UIElements;
namespace UnityEngine.UI.Extensions namespace UnityEngine.UI.Extensions
{ {

View File

@ -4,7 +4,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
#if !ENABLE_LEGACY_INPUT_MANAGER #if UNITY_2019_OR_NEWER && !ENABLE_LEGACY_INPUT_MANAGER
using UnityEngine.InputSystem; using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls; using UnityEngine.InputSystem.Controls;
#endif #endif
@ -21,23 +21,21 @@ namespace UnityEngine.UI.Extensions
public static bool GetMouseButton(int button) public static bool GetMouseButton(int button)
{ {
#if ENABLE_LEGACY_INPUT_MANAGER #if UNITY_2019_OR_NEWER && !ENABLE_LEGACY_INPUT_MANAGER
return Input.GetMouseButton(button);
#else
if (Mouse.current == null) if (Mouse.current == null)
{ {
return false; return false;
} }
return Mouse.current.leftButton.isPressed; return Mouse.current.leftButton.isPressed;
#else
return Input.GetMouseButton(button);
#endif #endif
} }
public static bool GetMouseButtonDown(int button) public static bool GetMouseButtonDown(int button)
{ {
#if ENABLE_LEGACY_INPUT_MANAGER #if UNITY_2019_OR_NEWER && !ENABLE_LEGACY_INPUT_MANAGER
return Input.GetMouseButtonDown(button);
#else
if (Mouse.current == null) if (Mouse.current == null)
{ {
return false; return false;
@ -52,14 +50,14 @@ namespace UnityEngine.UI.Extensions
} }
} }
return false; return false;
#else
return Input.GetMouseButtonDown(button);
#endif #endif
} }
public static bool GetMouseButtonUp(int button) public static bool GetMouseButtonUp(int button)
{ {
#if ENABLE_LEGACY_INPUT_MANAGER #if UNITY_2019_OR_NEWER && !ENABLE_LEGACY_INPUT_MANAGER
return Input.GetMouseButtonUp(button);
#else
if (Mouse.current == null) if (Mouse.current == null)
{ {
return false; return false;
@ -71,14 +69,14 @@ namespace UnityEngine.UI.Extensions
return true; return true;
} }
return false; return false;
#else
return Input.GetMouseButtonUp(button);
#endif #endif
} }
public static bool GetButton(string input) public static bool GetButton(string input)
{ {
#if ENABLE_LEGACY_INPUT_MANAGER #if UNITY_2019_OR_NEWER && !ENABLE_LEGACY_INPUT_MANAGER
return Input.GetButton(input);
#else
ButtonControl buttonPressed = GetButtonControlFromString(input); ButtonControl buttonPressed = GetButtonControlFromString(input);
if (!buttons.ContainsKey(input)) if (!buttons.ContainsKey(input))
@ -87,10 +85,12 @@ namespace UnityEngine.UI.Extensions
} }
return buttonPressed != null ? buttonPressed.isPressed : false; return buttonPressed != null ? buttonPressed.isPressed : false;
#else
return Input.GetButton(input);
#endif #endif
} }
#if !ENABLE_LEGACY_INPUT_MANAGER #if UNITY_2019_OR_NEWER && !ENABLE_LEGACY_INPUT_MANAGER
private static ButtonControl GetButtonControlFromString(string input) private static ButtonControl GetButtonControlFromString(string input)
{ {
if (Gamepad.current == null) if (Gamepad.current == null)
@ -112,9 +112,7 @@ namespace UnityEngine.UI.Extensions
public static bool GetButtonDown(string input) public static bool GetButtonDown(string input)
{ {
#if ENABLE_LEGACY_INPUT_MANAGER #if UNITY_2019_OR_NEWER && !ENABLE_LEGACY_INPUT_MANAGER
return Input.GetButtonDown(input);
#else
ButtonControl buttonPressed = GetButtonControlFromString(input); ButtonControl buttonPressed = GetButtonControlFromString(input);
if (buttonPressed.isPressed) if (buttonPressed.isPressed)
@ -135,14 +133,14 @@ namespace UnityEngine.UI.Extensions
buttons[input] = false; buttons[input] = false;
} }
return false; return false;
#else
return Input.GetButtonDown(input);
#endif #endif
} }
public static bool GetButtonUp(string input) public static bool GetButtonUp(string input)
{ {
#if ENABLE_LEGACY_INPUT_MANAGER #if UNITY_2019_OR_NEWER && !ENABLE_LEGACY_INPUT_MANAGER
return Input.GetButtonUp(input);
#else
ButtonControl buttonPressed = GetButtonControlFromString(input); ButtonControl buttonPressed = GetButtonControlFromString(input);
if (buttons[input] && !buttonPressed.isPressed) if (buttons[input] && !buttonPressed.isPressed)
@ -151,14 +149,14 @@ namespace UnityEngine.UI.Extensions
return true; return true;
} }
return false; return false;
#else
return Input.GetButtonUp(input);
#endif #endif
} }
public static bool GetKey(KeyCode key) public static bool GetKey(KeyCode key)
{ {
#if ENABLE_LEGACY_INPUT_MANAGER #if UNITY_2019_OR_NEWER && !ENABLE_LEGACY_INPUT_MANAGER
return Input.GetKey(key);
#else
KeyControl keyPressed = GetKeyControlFromKeyCode(key); KeyControl keyPressed = GetKeyControlFromKeyCode(key);
if (!keys.ContainsKey(key)) if (!keys.ContainsKey(key))
{ {
@ -166,10 +164,12 @@ namespace UnityEngine.UI.Extensions
} }
return keyPressed != null ? keyPressed.isPressed : false; return keyPressed != null ? keyPressed.isPressed : false;
#else
return Input.GetKey(key);
#endif #endif
} }
#if !ENABLE_LEGACY_INPUT_MANAGER #if UNITY_2019_OR_NEWER && !ENABLE_LEGACY_INPUT_MANAGER
private static KeyControl GetKeyControlFromKeyCode(KeyCode key) private static KeyControl GetKeyControlFromKeyCode(KeyCode key)
{ {
if (Keyboard.current == null) if (Keyboard.current == null)
@ -203,9 +203,7 @@ namespace UnityEngine.UI.Extensions
public static bool GetKeyDown(KeyCode key) public static bool GetKeyDown(KeyCode key)
{ {
#if ENABLE_LEGACY_INPUT_MANAGER #if UNITY_2019_OR_NEWER && !ENABLE_LEGACY_INPUT_MANAGER
return Input.GetKeyDown(key);
#else
KeyControl keyPressed = GetKeyControlFromKeyCode(key); KeyControl keyPressed = GetKeyControlFromKeyCode(key);
if (keyPressed.isPressed) if (keyPressed.isPressed)
{ {
@ -225,14 +223,14 @@ namespace UnityEngine.UI.Extensions
keys[key] = false; keys[key] = false;
} }
return false; return false;
#else
return Input.GetKeyDown(key);
#endif #endif
} }
public static bool GetKeyUp(KeyCode key) public static bool GetKeyUp(KeyCode key)
{ {
#if ENABLE_LEGACY_INPUT_MANAGER #if UNITY_2019_OR_NEWER && !ENABLE_LEGACY_INPUT_MANAGER
return Input.GetKeyUp(key);
#else
KeyControl keyPressed = GetKeyControlFromKeyCode(key); KeyControl keyPressed = GetKeyControlFromKeyCode(key);
if (keys[key] && !keyPressed.isPressed) if (keys[key] && !keyPressed.isPressed)
{ {
@ -240,14 +238,14 @@ namespace UnityEngine.UI.Extensions
return true; return true;
} }
return false; return false;
#else
return Input.GetKeyUp(key);
#endif #endif
} }
public static float GetAxisRaw(string axis) public static float GetAxisRaw(string axis)
{ {
#if ENABLE_LEGACY_INPUT_MANAGER #if UNITY_2019_OR_NEWER && !ENABLE_LEGACY_INPUT_MANAGER
return Input.GetAxisRaw(axis);
#else
if (Gamepad.current == null) if (Gamepad.current == null)
{ {
return 0f; return 0f;
@ -262,6 +260,8 @@ namespace UnityEngine.UI.Extensions
} }
return 0f; return 0f;
#else
return Input.GetAxisRaw(axis);
#endif #endif
} }
@ -269,10 +269,10 @@ namespace UnityEngine.UI.Extensions
{ {
get get
{ {
#if ENABLE_LEGACY_INPUT_MANAGER #if UNITY_2019_OR_NEWER && !ENABLE_LEGACY_INPUT_MANAGER
return Input.mousePosition;
#else
return Mouse.current.position.ReadValue(); return Mouse.current.position.ReadValue();
#else
return Input.mousePosition;
#endif #endif
} }
} }