153 lines
4.9 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 CharacterSystem;
using PrizeSystem;
using System.Text;
using UnityEngine;
public class Bootstrap : MonoBehaviour
{
private const int DEFAULT_FRAME_RATE = 60;
[SerializeField] private SoundManager soundManager;
[SerializeField] private Board board;
[SerializeField] private ChipPool chipPool;
[SerializeField] private Chip chipPrefab;
[SerializeField] private NotificationSystem notificationSystem;
[SerializeField] private In inputSystem;
[SerializeField] private PrizeSystemManager prizeSystem;
[SerializeField] private VideoUtility videoUtility;
[SerializeField] private VitrinaCatcher vitrinaCatcher;
[SerializeField] private DualAvatarController avatarController;
[SerializeField] private GameManager gameManager;
[SerializeField] private CharactersController characterController;
[SerializeField] private Defender defender;
[SerializeField] private ControlsPerformer controlsPerformer;
[SerializeField] private Menu menu;
[SerializeField] private SettingsScheme defaultSettings;
[SerializeField] private SettingViewSet _settingViews;
[SerializeField] private CoinCounter _coinCounter;
private void Awake() => Initialize();
private void Initialize()
{
Application.targetFrameRate = DEFAULT_FRAME_RATE;
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
SettingsManager.Initialize(defaultSettings);
SettingViewsProvider.Inject(_settingViews);
//_settingsScreen.Generate();
soundManager.Initialize();
ConfigManager.Initialize();
UnityMainThreadDispatcher.Initialize();
InitializePrefs();
InitializeDevices();
PaymentSystem.Initialize();
notificationSystem.Initialize();
vitrinaCatcher.Initialize();
inputSystem.Initialize();
prizeSystem.Initialize();
videoUtility.Initialize();
#if !UNITY_EDITOR
CheckLicense();
#endif
//todo: сагрегировать эти объекты
avatarController.GetComponent<AvatarEventBus>().Initialize();
avatarController.Initialize();
characterController.Initialize();
gameManager.Initialize();
MachineCountersService.Initialize();
board.Init();
chipPool.Init(chipPrefab, 30);
menu.Initialize();
controlsPerformer.Initialize();
controlsPerformer.SetControlable(menu);
_coinCounter.Initialize();
Destroy(gameObject);
}
private void CheckLicense() => defender.StartCoroutine(defender.CheckLicenseCoroutine());
private static void InitializePrefs()
{
PlayerPrefs.SetString("Serial", ConfigManager.Config.Serial);
if (!PlayerPrefs.HasKey("Number")) PlayerPrefs.SetString("Number", "70000000000");
if (!PlayerPrefs.HasKey("NumberTech")) PlayerPrefs.SetString("NumberTech", "<Не указано>");
}
private void InitializeDevices()
{
var sb = new StringBuilder();
//ИНИЦИАЛИЗАЦИЯ УСТРОЙСТВ
var devices = ComPortScanner.ScanPorts();
sb.AppendLine($"Найдено устройств: {devices.Count}");
foreach (var device in devices)
{
sb.Append($"{device.Key} : {device.Value}");
}
Debug.Log(sb.ToString());
bool controllerFound = false;
string vitrinaPort = null;
foreach (var device in devices)
{
//Витрина
if (device.Value == ComPortScanner.DeviceType.PrizeShowcase)
{
vitrinaPort = device.Key;
Debug.Log($"нашел витрину на порту, {vitrinaPort}");
}
else if (device.Value == ComPortScanner.DeviceType.ControllerV1)
{
if (!controllerFound)
{
Debug.Log("Нашел периферийник1 открываю.");
ComWrapper.Initialize(device.Key, boardVersion: 1);
controllerFound = true;
}
}
else if (device.Value == ComPortScanner.DeviceType.ControllerV2)
{
if (!controllerFound)
{
Debug.Log("Нашел периферийник2 открываю.");
ComWrapper.Initialize(device.Key, boardVersion: 2);
controllerFound = true;
}
}
else
{
Debug.Log($"неизвестный тип {device.Key}:{device.Value}");
}
}
if (vitrinaPort != null)
{
Debug.Log($"Витрину открываем (порт {vitrinaPort}");
int h = ComNativeWrapper.Serial_Open(vitrinaPort, 115200, 8, 0, 1, 4, 10);
if (h > 0) Debug.Log("Открыл");
else Debug.Log("Не Открыл");
PrizeStandController.Initialize(h, 5);
}
}
}