|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
import { Component, OnInit } from '@angular/core'; |
|
|
|
|
|
|
|
|
|
declare var UnityLoader: any; |
|
|
|
|
|
|
|
|
|
declare var window: Window & { getCookie: any }; |
|
|
|
|
|
|
|
|
|
@Component({ |
|
|
|
|
selector: 'app-unity', |
|
|
|
@ -16,22 +16,34 @@ export class UnityComponent implements OnInit {
|
|
|
|
|
public unityInstance: any = {}; |
|
|
|
|
|
|
|
|
|
constructor() { |
|
|
|
|
// window.GetName = window.GetName || {};
|
|
|
|
|
// window.GetName = this.GetName.bind(this);
|
|
|
|
|
//window.getCookie = this.getCookie.bind(this);
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
progressValue = 0; |
|
|
|
|
|
|
|
|
|
ngOnInit(): void { |
|
|
|
|
this.unityInstance = UnityLoader.instantiate('unityContainer', 'assets/unityApp/Build/unityApp.json'); |
|
|
|
|
// this.SendMessage('UnityWebGL', 'GetName', '');
|
|
|
|
|
this.unityInstance = UnityLoader.instantiate('unityContainer', 'assets/unityApp/Build/unityApp.json', {onProgress: this.UnityProgress}); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
UnityProgress(unityInstance, progress) { |
|
|
|
|
if (!unityInstance.Module) |
|
|
|
|
return; |
|
|
|
|
console.log(progress); |
|
|
|
|
if (progress == 1) |
|
|
|
|
unityInstance.SendMessage("UnityWebGL", "CallUnity"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public GetName(): void { |
|
|
|
|
console.log('这是Unity调用的Angular方法'); |
|
|
|
|
|
|
|
|
|
setCompanyId(){ |
|
|
|
|
this.unityInstance.SendMessage("UnityWebGL", "CallUnity"); |
|
|
|
|
} |
|
|
|
|
public SendMessage(objectName: string, methodName: string, value: any): void { |
|
|
|
|
|
|
|
|
|
CallUnity(): void { |
|
|
|
|
console.log('=============================================='); |
|
|
|
|
this.unityInstance.SendMessage(objectName, methodName, value); |
|
|
|
|
this.unityInstance.SendMessage("UnityWebGL", "CallUnity"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public SendMessage(objectName: string, methodName: string): void { |
|
|
|
|
this.unityInstance.SendMessage(objectName, methodName); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|