Менеджеры перенесены в отдельную папку; Накатил систему ввода на доработку
This commit is contained in:
parent
da81761e15
commit
0e043b86b4
@ -22,12 +22,9 @@ public class MainBootstrap : MonoBehaviour
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
WalletManager.Initialize(ConfigCatalog.WalletManagerConfig);
|
||||
GameModesHolder.Initialize(ConfigCatalog.GameModesConfig);
|
||||
|
||||
|
||||
|
||||
Debug.Log("Главный загрузчик отработал");
|
||||
BootstrapperState.MainBootstraped = true;
|
||||
SceneLoader.LoadScene("Menu");
|
||||
|
||||
8
Assets/Scripts/Common/Inputs.meta
Normal file
8
Assets/Scripts/Common/Inputs.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 962a8d197716e2d4d8da8269efc0fb69
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
Assets/Scripts/Common/Inputs/AbstractInputSource.cs
Normal file
9
Assets/Scripts/Common/Inputs/AbstractInputSource.cs
Normal file
@ -0,0 +1,9 @@
|
||||
public abstract class AbstractInputSource
|
||||
{
|
||||
public abstract bool Initialize();
|
||||
public abstract bool GetButton(InSignal button);
|
||||
public abstract bool GetButtonDown(InSignal button);
|
||||
public abstract bool GetButtonUp(InSignal button);
|
||||
|
||||
public abstract bool AnyButton();
|
||||
}
|
||||
2
Assets/Scripts/Common/Inputs/AbstractInputSource.cs.meta
Normal file
2
Assets/Scripts/Common/Inputs/AbstractInputSource.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a74c2426fa79eea459605e3e362b4e33
|
||||
7
Assets/Scripts/Common/Inputs/ButtonState.cs
Normal file
7
Assets/Scripts/Common/Inputs/ButtonState.cs
Normal file
@ -0,0 +1,7 @@
|
||||
public enum ButtonState
|
||||
{
|
||||
None, // Отжата
|
||||
Pressed, // Только что нажата
|
||||
Held, // Удерживается
|
||||
Released // Только что отжата
|
||||
}
|
||||
2
Assets/Scripts/Common/Inputs/ButtonState.cs.meta
Normal file
2
Assets/Scripts/Common/Inputs/ButtonState.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 52b39e6ddbb5ea84d8c3b26302cbed49
|
||||
68
Assets/Scripts/Common/Inputs/ComInput.cs
Normal file
68
Assets/Scripts/Common/Inputs/ComInput.cs
Normal file
@ -0,0 +1,68 @@
|
||||
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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Common/Inputs/ComInput.cs.meta
Normal file
2
Assets/Scripts/Common/Inputs/ComInput.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 964a00c748d98854387d8d5e477cf8a5
|
||||
27
Assets/Scripts/Common/Inputs/In.cs
Normal file
27
Assets/Scripts/Common/Inputs/In.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using UnityEngine;
|
||||
|
||||
public static class In
|
||||
{
|
||||
static AbstractInputSource CachedSource;
|
||||
public static void Initialize(AbstractInputSource inputSource)
|
||||
{
|
||||
#if !UNITY_EDITOR
|
||||
CachedSource = new ComInput();
|
||||
#else
|
||||
CachedSource = inputSource;
|
||||
#endif
|
||||
|
||||
var success = CachedSource.Initialize();
|
||||
if (!success) Debug.LogWarning("Не удалось проинициалзировать источник управления.");
|
||||
}
|
||||
|
||||
|
||||
public static bool GetButton(InSignal button) => CachedSource.GetButton(button);
|
||||
|
||||
public static bool GetButtonDown(InSignal button) => CachedSource.GetButtonDown(button);
|
||||
|
||||
public static bool GetButtonUp(InSignal button) => CachedSource.GetButtonUp(button);
|
||||
|
||||
|
||||
public static bool AnyButton() => CachedSource.AnyButton();
|
||||
}
|
||||
2
Assets/Scripts/Common/Inputs/In.cs.meta
Normal file
2
Assets/Scripts/Common/Inputs/In.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a3f75ba180e61a049a08e914eea66b94
|
||||
14
Assets/Scripts/Common/Inputs/InSignal.cs
Normal file
14
Assets/Scripts/Common/Inputs/InSignal.cs
Normal file
@ -0,0 +1,14 @@
|
||||
public enum InSignal
|
||||
{
|
||||
UpLeft,
|
||||
UpRight,
|
||||
DownLeft,
|
||||
DownRight,
|
||||
|
||||
Service,
|
||||
Coin,
|
||||
|
||||
CenterSensor,
|
||||
PeriscopeUpperLimit,
|
||||
PeriscopeLowerLimit
|
||||
}
|
||||
2
Assets/Scripts/Common/Inputs/InSignal.cs.meta
Normal file
2
Assets/Scripts/Common/Inputs/InSignal.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d5f0d253a96c3a948b18f46e0689b26e
|
||||
8
Assets/Scripts/Common/Inputs/InputConfigurations.meta
Normal file
8
Assets/Scripts/Common/Inputs/InputConfigurations.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 16b20cc9a568a4549a87101b593b7412
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,26 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public static class KeyboardConfiguration
|
||||
{
|
||||
public static Dictionary<InSignal, KeyCode> KeyboardMapping { get; }
|
||||
static KeyboardConfiguration()
|
||||
{
|
||||
KeyboardMapping = new Dictionary<InSignal, KeyCode>
|
||||
{
|
||||
[InSignal.UpLeft] = KeyCode.Q,
|
||||
[InSignal.UpRight] = KeyCode.E,
|
||||
[InSignal.DownLeft] = KeyCode.A,
|
||||
[InSignal.DownRight] = KeyCode.D,
|
||||
|
||||
[InSignal.Service] = KeyCode.F5,
|
||||
[InSignal.Coin] = KeyCode.F,
|
||||
|
||||
[InSignal.CenterSensor] = KeyCode.C,
|
||||
[InSignal.PeriscopeUpperLimit] = KeyCode.UpArrow,
|
||||
[InSignal.PeriscopeLowerLimit] = KeyCode.DownArrow
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 74f5faaed0817fa498ed0e590bceb118
|
||||
14
Assets/Scripts/Common/Inputs/KeyboardInput.cs
Normal file
14
Assets/Scripts/Common/Inputs/KeyboardInput.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using UnityEngine;
|
||||
public class KeyboardInput : AbstractInputSource
|
||||
{
|
||||
public override bool GetButton(InSignal button) => Input.GetKey(KeyboardConfiguration.KeyboardMapping[button]);
|
||||
public override bool GetButtonDown(InSignal button) => Input.GetKeyDown(KeyboardConfiguration.KeyboardMapping[button]);
|
||||
public override bool GetButtonUp(InSignal button) => Input.GetKeyUp(KeyboardConfiguration.KeyboardMapping[button]);
|
||||
public override bool Initialize() { return true; }
|
||||
|
||||
|
||||
public override bool AnyButton()
|
||||
{
|
||||
return Input.anyKey;
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Common/Inputs/KeyboardInput.cs.meta
Normal file
2
Assets/Scripts/Common/Inputs/KeyboardInput.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b6e137003756a9542a1981d9fb7f868a
|
||||
@ -1,6 +1,10 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
|
||||
public class InputManager
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user