Adobe Air桌面读取Unity标准输出



我正在制作一些Air Desktop应用程序,在某些部分运行另一个使用unity3d构建的应用程序作为本机进程

var processArgs:Vector.<String > = new Vector.<String>();
var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
nativeProcessStartupInfo.workingDirectory = File.applicationDirectory.resolvePath("bin");
nativeProcessStartupInfo.executable = File.applicationDirectory.resolvePath("bin/unityApp.exe");
var process:NativeProcess = new NativeProcess();
process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
process.addEventListener(ProgressEvent.STANDARD_INPUT_PROGRESS, onOutputData);
process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, onErrorData);
process.addEventListener(NativeProcessExitEvent.EXIT, onExit);
process.addEventListener(IOErrorEvent.STANDARD_OUTPUT_IO_ERROR, onIOError);
process.addEventListener(IOErrorEvent.STANDARD_ERROR_IO_ERROR, onIOError);
process.start(nativeProcessStartupInfo);
process.standardInput.writeUTFBytes(processArgs + "n");

function onOutputData(event:ProgressEvent):void
{
    trace("Got: ", process.standardOutput.readUTFBytes(process.standardOutput.bytesAvailable));
}
function onErrorData(event: ProgressEvent):void
{
    trace("ERROR -", process.standardError.readUTFBytes(process.standardError.bytesAvailable));
}
function onExit(event:NativeProcessExitEvent):void
{
    trace("Process exited with ", event.exitCode);
}
function onIOError(event: IOErrorEvent):void
{
    trace(event.toString());
}

,在unity应用程序中有一个按钮,它应该发送一个标准输出,所以我可以在空气中读取它。我的问题是,我在unity中使用c#方法来发送输出,但从未在空气中读取,我使用

Debug.log("text");
System.Console.Write("text");
System.Console.WriteLine("text");

我是unity和c#的新手,所以我问我应该在unity中使用什么函数来发送Air可以读取的标准输出
谢谢。

为AIR应用程序添加启动参数:

nativeProcessStartupInfo.arguments[0] = "-nolog";

在Unity中添加这段代码,发送一些字符串到控制台:

System.IO.StreamWriter standardOutput = new System.IO.StreamWriter(System.Console.OpenStandardOutput());
standardOutput.Write("Hello!");
standardOutput.AutoFlush = true;
System.Console.SetOut(standardOutput);

最新更新