Код: Выделить всё
using System.Collections.Generic;
using UnityEngine;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using General;
using System.Threading;
public class UCIExtension : MonoBehaviour
{
private Process stockfishProcess = new Process();
private StreamWriter inputWriter;
private StreamReader outputReader;
private bool engineActive = false;
public int moveTime;
List feed = new List();
public void Start()
{
//prepare and sync engine
engineActive = true;
// Path to the Stockfish executable
string stockfishPath = Application.dataPath + "/Tools/Stockfish_17_x86-32.exe";
// Start Stockfish process
stockfishProcess.StartInfo.FileName = stockfishPath;
stockfishProcess.StartInfo.UseShellExecute = false;
stockfishProcess.StartInfo.RedirectStandardInput = true;
stockfishProcess.StartInfo.RedirectStandardOutput = true;
stockfishProcess.StartInfo.CreateNoWindow = true;
stockfishProcess.Start();
inputWriter = stockfishProcess.StandardInput;
outputReader = stockfishProcess.StandardOutput;
UnityEngine.Debug.Log(RunCommand("d", ""));
}
private void OnOutputReceived(object sender, DataReceivedEventArgs e)
{
if (e.Data != null)
{
feed.Add(e.Data);
}
}
public async Task RunCommand(string command, string conditional)
{
inputWriter.WriteLine(command);
feed.Clear();
while(true)
{
if(feed.Count == 0) continue;
UnityEngine.Debug.Log(feed[feed.Count - 1]);
return;
}
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... into-unity