68 lines
1.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using UnityEngine;
public class ComInput : AbstractInputSource
{
private const int PIN_COUNT = 16;
private const char POSITIVE = '0';
private bool[] buttonState = new bool[PIN_COUNT];
private bool[] buttonDown = new bool[PIN_COUNT];
private bool[] buttonUp = new bool[PIN_COUNT];
private Dictionary<InSignal, int> pinMappings = new Dictionary<InSignal, int>();
private Dictionary<int, InSignal> reverseMappings = new Dictionary<int, InSignal>();
public override bool Initialize()
{
}
// Обновляет состояния инпута когда приходит новый ввод с платы. Дергается событием.
private void UpdateInputState(string input)
{
for (int i = 0; i < input.Length; i++)
{
// Получаем новое состояние пина
bool newState = input[i] == POSITIVE;
// Состояние пина изменилось => пишем в буферы
if (newState != buttonState[i])
{
if (newState) // Пин был зажат
{
buttonDown[i] = true;
buttonUp[i] = false;
}
else // Пин был отжат
{
buttonDown[i] = false;
buttonUp[i] = true;
}
}
buttonState[i] = newState;
}
}
public override bool AnyButton()
{
return false;
}
public override bool GetButton(InSignal button)
{
}
public override bool GetButtonDown(InSignal button)
{
}
public override bool GetButtonUp(InSignal button)
{
}
}