В настоящее время я работаю с Angular2 версии 2.1.2 с визуализатором Unity, созданным с помощью Unity 5.5.
Что мне нужно сделать, так это общаться из Unity с Angular2.
Я использовал код, похожий на приведенный ниже
public void GetBillOfMaterials(string callbackFn)
{
var result = LightSystem.BillOfMaterials.Aggregate("", (current, material) => current + (material + Environment.NewLine));
Application.ExternalCall(callbackFn, result);
}
Где указанная выше функция будет вызываться в Angular2, как показано ниже
public GetBillOfMaterial()
{
SendMessage("Manager", "GetBillOfMaterials", "alert");
}
Проблема в том, что когда я пробую любую функцию angular2 внутри callbackFn, она не находит мою функцию.
Функция, которую я пытаюсь вызвать, находится внутри службы, которая выглядит так:
import { Injectable } from '@angular/core';
import { FinishService } from "./sysWideComps/finish/finish.service";
import { ColorService } from "./sysWideComps/colorTemp/color.service";
import { CircuitService } from "./filters/tabs/circuit/circuit-service";
import { StandoffService } from "./filters/tabs/standoff/standoff-tab.service";
@Injectable()
export class UnityService {
private isFirstCall: boolean = true;
constructor(private colorService: ColorService, private finishService:FinishService, private circuitService: CircuitService, private standoffService: StandoffService) { }
public ChangeFinish(finishType: string) {
console.log(`This is the finish type ${finishType}`);
this.sendMsgParam("ChangeFinish", finishType);
}
public ChangeColorTemp(colorTemp: number) {
this.sendMsgParam("ChangeColorTemperature", colorTemp);
}
public ChangeCircuit(circuitType: string) {
this.sendMsgParam("ChangeCircuit", circuitType);
}
public CreateModel(params: string) {
if (this.isFirstCall) {
this.ChangeCircuit(this.circuitService.getCircuit());
this.ChangeFinish(this.finishService.getFinish().FinishName.replace(" ", ""));
this.ChangeStandoffLength(this.standoffService.getStandoffLength());
//Dropdown goes here
let tempCTemp = this.colorService.getColorTemp().Temperature.replace("k", "");
let tempNum: number =+ tempCTemp;
this.ChangeColorTemp(tempNum);
this.isFirstCall = false;
}
this.sendMsgParam("CreateModel", params);
}
public Delete() {
this.sendMsg("Delete");
}
public ResetView() {
this.sendMsg("ResetCamera");
}
public RotateObject() {
this.sendMsg("RotateCurrentObject");
}
public Unselect() {
this.sendMsg("Unselect");
}
ChangeStandoffLength(input: number) {
this.sendMsgParam("ChangeSystemDropdownLength", input.toString());
}
public AddStandoff(params: string) {
let data: string = params;
this.sendMsgParam("AddStandoffs", data);
}
public GetBillOfMaterial() {
SendMessage("Manager", "GetBillOfMaterials", "alert");
}
public testFunction(input: string) {
alert(input);
}
sendMsgParam(functionName: string, params: any) {
SendMessage("Manager", functionName, params);
}
sendMsg(functionName: string) {
SendMessage("Manager", functionName);
}
}
В основном мне нужно иметь возможность вызывать "TestFunction" внутри вышеуказанной службы из Unity, используя Application.ExternalCall () или любую другую функцию, которая могла бы работать.
Дайте мне знать, если есть какие-либо дополнительные разъяснения, которые я могу сделать.
Спасибо!
testFunction
находится внутри модуля Angular, поэтому предположительно это будет что-то вродеApplication.ExternalCall("UnityService.testFunction","Hello angular");
. - person Luke Briggs   schedule 20.02.2017Application.ExternalCall
? Что с этим работало или не работало? - person rutter   schedule 20.02.2017