Removed old inputsystem modules as they are no longer effective under Unity's new inputsystem.

pull/413/head
Simon (darkside) Jackson 2020-10-12 23:29:16 +01:00
parent 38740bfef0
commit b7277edb89
4 changed files with 0 additions and 409 deletions

View File

@ -1,165 +0,0 @@
/// Credit Chris Trueman
/// Sourced from - http://forum.unity3d.com/threads/use-reticle-like-mouse-for-worldspace-uis.295271/
using UnityEngine.UI.Extensions;
namespace UnityEngine.EventSystems.Extensions
{
[RequireComponent(typeof(EventSystem))]
[AddComponentMenu("Event/Extensions/Aimer Input Module")]
public class AimerInputModule : PointerInputModule
{
/// <summary>
/// The Input axis name used to activate the object under the reticle.
/// </summary>
public string activateAxis = "Submit";
/// <summary>
/// The aimer offset position. Aimer is center screen use this offset to change that.
/// </summary>
public Vector2 aimerOffset = new Vector2(0, 0);
/// <summary>
/// The object under aimer. A static access field that lets you know what is under the aimer.
/// This field can return null.
/// </summary>
public static GameObject objectUnderAimer;
protected AimerInputModule() { }
public override void ActivateModule()
{
StandaloneInputModule StandAloneSystem = GetComponent<StandaloneInputModule>();
if (StandAloneSystem != null && StandAloneSystem.enabled)
{
Debug.LogError("Aimer Input Module is incompatible with the StandAloneInputSystem, " +
"please remove it from the Event System in this scene or disable it when this module is in use");
}
}
public override void Process()
{
bool pressed = UIExtensionsInputManager.GetButtonDown(activateAxis);
bool released = UIExtensionsInputManager.GetButtonUp(activateAxis);
PointerEventData pointer = GetAimerPointerEventData();
ProcessInteraction(pointer, pressed, released);
if (!released)
ProcessMove(pointer);
else
RemovePointerData(pointer);
}
protected virtual PointerEventData GetAimerPointerEventData()
{
PointerEventData pointerData;
//Not certain on the use of this.
//I know that -1 is the mouse and anything positive would be a finger/touch, 0 being the first finger, 1 being the second and so one till the system limit is reached.
//So that is the reason I choose -2.
GetPointerData(-2, out pointerData, true);
pointerData.Reset();
pointerData.position = new Vector2(Screen.width * 0.5f, Screen.height * 0.5f) + aimerOffset;
eventSystem.RaycastAll(pointerData, m_RaycastResultCache);
var raycast = FindFirstRaycast(m_RaycastResultCache);
pointerData.pointerCurrentRaycast = raycast;
m_RaycastResultCache.Clear();
return pointerData;
}
private void ProcessInteraction(PointerEventData pointer, bool pressed, bool released)
{
var currentOverGo = pointer.pointerCurrentRaycast.gameObject;
objectUnderAimer = ExecuteEvents.GetEventHandler<ISubmitHandler>(currentOverGo);//we only want objects that we can submit on.
if (pressed)
{
pointer.eligibleForClick = true;
pointer.delta = Vector2.zero;
pointer.pressPosition = pointer.position;
pointer.pointerPressRaycast = pointer.pointerCurrentRaycast;
// search for the control that will receive the press
// if we can't find a press handler set the press
// handler to be what would receive a click.
var newPressed = ExecuteEvents.ExecuteHierarchy(currentOverGo, pointer, ExecuteEvents.submitHandler);
// didn't find a press handler... search for a click handler
if (newPressed == null)
{
newPressed = ExecuteEvents.ExecuteHierarchy(currentOverGo, pointer, ExecuteEvents.pointerDownHandler);
if (newPressed == null)
newPressed = ExecuteEvents.GetEventHandler<IPointerClickHandler>(currentOverGo);
}
else
{
pointer.eligibleForClick = false;
}
if (newPressed != pointer.pointerPress)
{
pointer.pointerPress = newPressed;
pointer.rawPointerPress = currentOverGo;
pointer.clickCount = 0;
}
// Save the drag handler as well
pointer.pointerDrag = ExecuteEvents.GetEventHandler<IDragHandler>(currentOverGo);
if (pointer.pointerDrag != null)
ExecuteEvents.Execute<IBeginDragHandler>(pointer.pointerDrag, pointer, ExecuteEvents.beginDragHandler);
}
if (released)
{
//Debug.Log("Executing pressup on: " + pointer.pointerPress);
ExecuteEvents.Execute(pointer.pointerPress, pointer, ExecuteEvents.pointerUpHandler);
//Debug.Log("KeyCode: " + pointer.eventData.keyCode);
// see if we mouse up on the same element that we clicked on...
var pointerUpHandler = ExecuteEvents.GetEventHandler<IPointerClickHandler>(currentOverGo);
// PointerClick
if (pointer.pointerPress == pointerUpHandler && pointer.eligibleForClick)
{
float time = Time.unscaledTime;
if (time - pointer.clickTime < 0.3f)
++pointer.clickCount;
else
pointer.clickCount = 1;
pointer.clickTime = time;
ExecuteEvents.Execute(pointer.pointerPress, pointer, ExecuteEvents.pointerClickHandler);
}
else if (pointer.pointerDrag != null)
{
ExecuteEvents.ExecuteHierarchy(currentOverGo, pointer, ExecuteEvents.dropHandler);
}
pointer.eligibleForClick = false;
pointer.pointerPress = null;
pointer.rawPointerPress = null;
if (pointer.pointerDrag != null)
ExecuteEvents.Execute(pointer.pointerDrag, pointer, ExecuteEvents.endDragHandler);
pointer.pointerDrag = null;
}
}
public override void DeactivateModule()
{
base.DeactivateModule();
ClearSelection();
}
}
}

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 08b9f423b73fdfb47b59e7de89863600
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@ -1,228 +0,0 @@
/// Credit Simon (simonDarksideJ) Jackson
/// Sourced from - UI SIM source and My Brain
using UnityEngine.UI.Extensions;
namespace UnityEngine.EventSystems
{
[AddComponentMenu("Event/Extensions/GamePad Input Module")]
public class GamePadInputModule : BaseInputModule
{
private float m_PrevActionTime;
Vector2 m_LastMoveVector;
int m_ConsecutiveMoveCount = 0;
protected GamePadInputModule()
{}
[SerializeField]
private string m_HorizontalAxis = "Horizontal";
/// <summary>
/// Name of the vertical axis for movement (if axis events are used).
/// </summary>
[SerializeField]
private string m_VerticalAxis = "Vertical";
/// <summary>
/// Name of the submit button.
/// </summary>
[SerializeField]
private string m_SubmitButton = "Submit";
/// <summary>
/// Name of the submit button.
/// </summary>
[SerializeField]
private string m_CancelButton = "Cancel";
[SerializeField]
private float m_InputActionsPerSecond = 10;
[SerializeField]
private float m_RepeatDelay = 0.1f;
public float inputActionsPerSecond
{
get { return m_InputActionsPerSecond; }
set { m_InputActionsPerSecond = value; }
}
public float repeatDelay
{
get { return m_RepeatDelay; }
set { m_RepeatDelay = value; }
}
/// <summary>
/// Name of the horizontal axis for movement (if axis events are used).
/// </summary>
public string horizontalAxis
{
get { return m_HorizontalAxis; }
set { m_HorizontalAxis = value; }
}
/// <summary>
/// Name of the vertical axis for movement (if axis events are used).
/// </summary>
public string verticalAxis
{
get { return m_VerticalAxis; }
set { m_VerticalAxis = value; }
}
public string submitButton
{
get { return m_SubmitButton; }
set { m_SubmitButton = value; }
}
public string cancelButton
{
get { return m_CancelButton; }
set { m_CancelButton = value; }
}
public override bool ShouldActivateModule()
{
if (!base.ShouldActivateModule())
return false;
var shouldActivate = true;
shouldActivate |= UIExtensionsInputManager.GetButtonDown(m_SubmitButton);
shouldActivate |= UIExtensionsInputManager.GetButtonDown(m_CancelButton);
shouldActivate |= !Mathf.Approximately(UIExtensionsInputManager.GetAxisRaw(m_HorizontalAxis), 0.0f);
shouldActivate |= !Mathf.Approximately(UIExtensionsInputManager.GetAxisRaw(m_VerticalAxis), 0.0f);
return shouldActivate;
}
public override void ActivateModule()
{
StandaloneInputModule StandAloneSystem = GetComponent<StandaloneInputModule>();
if (StandAloneSystem && StandAloneSystem.enabled)
{
Debug.LogError("StandAloneInputSystem should not be used with the GamePadInputModule, " +
"please remove it from the Event System in this scene or disable it when this module is in use");
}
base.ActivateModule();
var toSelect = eventSystem.currentSelectedGameObject;
if (toSelect == null)
toSelect = eventSystem.firstSelectedGameObject;
eventSystem.SetSelectedGameObject(toSelect, GetBaseEventData());
}
public override void DeactivateModule()
{
base.DeactivateModule();
}
public override void Process()
{
bool usedEvent = SendUpdateEventToSelectedObject();
if (eventSystem.sendNavigationEvents)
{
if (!usedEvent)
usedEvent |= SendMoveEventToSelectedObject();
if (!usedEvent)
SendSubmitEventToSelectedObject();
}
}
/// <summary>
/// Process submit keys.
/// </summary>
protected bool SendSubmitEventToSelectedObject()
{
if (eventSystem.currentSelectedGameObject == null)
return false;
var data = GetBaseEventData();
if (UIExtensionsInputManager.GetButtonDown(m_SubmitButton))
ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, data, ExecuteEvents.submitHandler);
if (UIExtensionsInputManager.GetButtonDown(m_CancelButton))
ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, data, ExecuteEvents.cancelHandler);
return data.used;
}
private Vector2 GetRawMoveVector()
{
Vector2 move = Vector2.zero;
move.x = UIExtensionsInputManager.GetAxisRaw(m_HorizontalAxis);
move.y = UIExtensionsInputManager.GetAxisRaw(m_VerticalAxis);
if (UIExtensionsInputManager.GetButtonDown(m_HorizontalAxis))
{
if (move.x < 0)
move.x = -1f;
if (move.x > 0)
move.x = 1f;
}
if (UIExtensionsInputManager.GetButtonDown(m_VerticalAxis))
{
if (move.y < 0)
move.y = -1f;
if (move.y > 0)
move.y = 1f;
}
return move;
}
/// <summary>
/// Process events.
/// </summary>
protected bool SendMoveEventToSelectedObject()
{
float time = Time.unscaledTime;
Vector2 movement = GetRawMoveVector();
if (Mathf.Approximately(movement.x, 0f) && Mathf.Approximately(movement.y, 0f))
{
m_ConsecutiveMoveCount = 0;
return false;
}
// If user pressed key again, always allow event
bool allow = UIExtensionsInputManager.GetButtonDown(m_HorizontalAxis) || UIExtensionsInputManager.GetButtonDown(m_VerticalAxis);
bool similarDir = (Vector2.Dot(movement, m_LastMoveVector) > 0);
if (!allow)
{
// Otherwise, user held down key or axis.
// If direction didn't change at least 90 degrees, wait for delay before allowing consecutive event.
if (similarDir && m_ConsecutiveMoveCount == 1)
allow = (time > m_PrevActionTime + m_RepeatDelay);
// If direction changed at least 90 degree, or we already had the delay, repeat at repeat rate.
else
allow = (time > m_PrevActionTime + 1f / m_InputActionsPerSecond);
}
if (!allow)
return false;
var axisEventData = GetAxisEventData(movement.x, movement.y, 0.6f);
ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, axisEventData, ExecuteEvents.moveHandler);
if (!similarDir)
m_ConsecutiveMoveCount = 0;
m_ConsecutiveMoveCount++;
m_PrevActionTime = time;
m_LastMoveVector = movement;
return axisEventData.used;
}
protected bool SendUpdateEventToSelectedObject()
{
if (eventSystem.currentSelectedGameObject == null)
return false;
var data = GetBaseEventData();
ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, data, ExecuteEvents.updateSelectedHandler);
return data.used;
}
}
}

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 26158f38115d49a4a915f46c7eced4ab
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData: