首先需要运行安装好的unity mono的cli.bat,预设一些环境变量。
然后在一个目录下建立自己的Javascript程序比如Main.js
#pragma strict
import System;
//import UnityEngine;
public static function Main(args: String[]): void {
print("Hello World!");
print("WTF,终于工作了");
var printText:String = "Hello Console!";
print(printText);
}
set UNITY_DLL_DIR=%UNITY_INSTALL_DIR%\Editor\Data\Managed
set ADDITIONAL_DDL_REFS=
set SOURCE_DIR=d:\temp\test4\ //这里保存着Main.js文件
set PATH={INSTALL_DIR}\Unity\Editor\Data\Mono\bin;{INSTALL_DIR}\Unity\MonoDevelop\bin;%PATH%
{INSTALL_DIR}是安装unity3d的目录。
然后调用:
mono "%MONO_PATH%\us.exe" -debug -target:exe -base:System.Object --method:Awake -out:"test4.exe" -reference:'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll' -srcdir:%SOURCE_DIR%
set ADDITIONAL_DDL_REFS=
set SOURCE_DIR=d:\temp\test4\ //这里保存着Main.js文件
set PATH={INSTALL_DIR}\Unity\Editor\Data\Mono\bin;{INSTALL_DIR}\Unity\MonoDevelop\bin;%PATH%
{INSTALL_DIR}是安装unity3d的目录。
然后调用:
mono "%MONO_PATH%\us.exe" -debug -target:exe -base:System.Object --method:Awake -out:"test4.exe" -reference:'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll' -srcdir:%SOURCE_DIR%