protected void GenerateOutputs(float[] variableValues) { //VirtualConsole.Log ("Executing code..."); //string codeToRun = (inTestMode) ? testCodeText : code; string codeToRun = code; compiler = new VirtualCompiler(codeToRun); for (int i = 0; i < EV.outputs.Count; i++) { compiler.AddOutputFunction(EV.outputs[i].name); } for (int i = 0; i < EV.constants.Count; i++) { compiler.AddInput(EV.constants[i].name, EV.constants[i].value); } for (int i = 0; i < variableValues.Length; i++) { compiler.AddInput(EV.variables[i], variableValues[i]); } //VirtualConsole.LogInputs (inputNames, inputValues); List <VirtualFunction> outputs = compiler.Run(); foreach (VirtualFunction function in outputs) { if (outputs.Count > 0) { string val = ""; if (function.values.Count > 0) { val = function.values[0]; } var func = new Function() { name = function.name, value = val }; outputQueue.Enqueue(func); } //VirtualConsole.LogOutput (func.name, func.value); } }
void Update() { if (Input.GetKeyDown(KeyCode.R)) { Restart(); } if (Input.GetKeyDown(KeyCode.Space)) { computer.SetActive(true); editor.SetActive(true); player.gameObject.SetActive(false); } if (computer.activeSelf) { if (Input.GetKeyDown(KeyCode.C) && (Input.GetKey(KeyCode.LeftControl)))//|| Input.GetKey (KeyCode.LeftCommand))) { computer.SetActive(false); player.gameObject.SetActive(true); } } guards = FindObjectsOfType <HackingEnemy>(); if (!active && player.transform.position.z > -3) { active = true; turret.active = true; foreach (var e in guards) { e.active = true; } } if (active && player != null) { string code = (useTestSolution) ? testCodeSolution.text : testCodeInitial.text; code = editor.code; VirtualCompiler compiler = new VirtualCompiler(code); VirtualComputer cc = computer.GetComponent <VirtualComputer>(); cc.availableModules[0] = turret; compiler.vComputer = cc; float[] guardSpeed = new float[guards.Length]; float[] guardPosX = new float[guards.Length]; float[] guardPosY = new float[guards.Length]; float[] guardDirX = new float[guards.Length]; float[] guardDirY = new float[guards.Length]; for (int i = 0; i < guards.Length; i++) { guardSpeed[i] = guards[i].speed; guardPosX[i] = guards[i].transform.position.x; guardPosY[i] = guards[i].transform.position.z; guardDirX[i] = guards[i].transform.forward.x; guardDirY[i] = guards[i].transform.forward.y; } compiler.AddInputArray(nameof(guardSpeed), guardSpeed); compiler.AddInputArray(nameof(guardPosX), guardPosX); compiler.AddInputArray(nameof(guardPosY), guardPosY); compiler.AddInputArray(nameof(guardDirX), guardDirX); compiler.AddInputArray(nameof(guardDirY), guardDirY); compiler.AddInput("numGuards", guards.Length); compiler.AddInput("intruderPosX", player.transform.position.x); compiler.AddInput("intruderPosY", player.transform.position.z); compiler.AddInput("intruderDirX", player.dir.x); compiler.AddInput("intruderDirY", player.dir.y); compiler.AddInput("intruderSpeed", player.speed); compiler.AddInput("missileSpeed", turret.missilePrefab.speed); compiler.AddInput("turretPosX", turret.muzzle.position.x); compiler.AddInput("turretPosY", turret.muzzle.position.z); compiler.AddInput("turretHeight", turret.muzzle.position.y); compiler.AddOutputFunction("setAim"); compiler.AddOutputFunction("powerUp"); compiler.AddOutputFunction("setInactive"); List <VirtualFunction> output = compiler.Run(); ExecuteFunctions(output); //OLD /*if (output.Count > 0) * { * float aimX = output[1].values[0]; * float aimY = output[1].values[1]; * turret.setAim(aimX, aimY); * }*/ } }
protected void GenerateOutputs(float[] variableValues) { //VirtualConsole.Log ("Executing code..."); string codeToRun = (inTestMode) ? testCodeText : code; compiler = new VirtualCompiler(codeToRun); compiler.availableFuncsWthoutReturnV.Add("testMethod", testMethod); compiler.AddOutputFunction("testMethod2"); for (int i = 0; i < taskInfo.outputs.Length; i++) { compiler.AddOutputFunction(taskInfo.outputs[i].name); } for (int i = 0; i < taskInfo.constants.Length; i++) { compiler.AddInput(taskInfo.constants[i].name, taskInfo.constants[i].value); } for (int i = 0; i < variableValues.Length; i++) { compiler.AddInput(taskInfo.variables[i], variableValues[i]); } //VirtualConsole.LogInputs (inputNames, inputValues); List <VirtualFunction> outputs = compiler.Run(); if (outputs.Count > 0) { foreach (VirtualFunction vFunc in outputs) { //object[] mParams = new object[vFunc.values.Count]; //Array.Copy(vFunc.values.ToArray(), mParams, vFunc.values.Count); if (vFunc.delFunc != null) { vFunc.delFunc.Invoke(this, null); } if (vFunc.FunctionWithoutParam != null && vFunc.FunctionWithParam != null) { if (vFunc.values.Count <= 1) { vFunc.FunctionWithoutParam.Invoke(); } else { string vFuncReturnValue = vFunc.FunctionWithParam.Invoke(vFunc.values[0].ToString()); } } } float val = 0; if (outputs[0].values.Count > 0 && outputs[0].values[0] is float) { val = (float)outputs[0].values[0]; } var func = new Function() { name = outputs[0].name, value = val }; outputQueue.Enqueue(func); VirtualConsole.LogOutput(func.name, func.value); } }