chip-game/Assets/Scenes/StandTester.cs

80 lines
2.1 KiB
C#

using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
public class StandTester : MonoBehaviour
{
int h;
bool initialized = false;
void Start()
{
PrizeStandController.InitializationComplete += PrizeStandController_InitializationComplete;
PrizeStandController.OpeningFinished += PrizeStandController_OpeningFinished;
ComNativeWrapper.Serial_CloseAll();
h = ComNativeWrapper.Serial_Open("COM3", 115200, 8, 0, 1, 4, 10);
Debug.Log(h);
PrizeStandController.Initialize(h, 5, null);
}
private void OnDisable()
{
ComNativeWrapper.Serial_CloseAll();
}
private void PrizeStandController_InitializationComplete(bool arg1, string arg2)
{
if (arg1)
{
initialized = true;
}
Debug.Log($"Èíèöèàëèçàöèÿ. Result {arg1}; Message {arg2}");
}
private void PrizeStandController_OpeningFinished(bool arg1, string arg2)
{
Debug.Log($"Îòêðûòèå. Result {arg1}; Message {arg2}");
}
Task<Dictionary<int, BoxStatus>> awaitStatuses;
void Update()
{
if (!initialized) return;
if (Input.GetKeyDown(KeyCode.Alpha0))
{
awaitStatuses = Task.Run(PrizeStandController.GetStatusesAsync);
}
if (Input.GetKeyDown(KeyCode.Alpha1))
{
Debug.Log("=====Îòêðûòü 1=====");
_ = PrizeStandController.OpenBoxAsync(1);
}
if (Input.GetKeyDown(KeyCode.Alpha2))
{
Debug.Log("=====Îòêðûòü 2=====");
_ = PrizeStandController.OpenBoxAsync(2);
}
if (Input.GetKeyDown(KeyCode.Alpha3))
{
Debug.Log("=====Îòêðûòü 3=====");
_ = PrizeStandController.OpenBoxAsync(3);
}
if (awaitStatuses != null && awaitStatuses.IsCompleted)
{
string res = "";
foreach (var kv in awaitStatuses.Result)
{
res += $"{kv.Key} : {kv.Value}\n";
}
Debug.Log(res);
awaitStatuses = null;
}
}
}