Browse Source

与Unity通信

develop
徐振升 5 years ago
parent
commit
6bbd5db7a5
  1. 3
      angular.json
  2. 1
      src/app/ui/unity/unity.component.html
  3. 2
      src/app/ui/unity/unity.component.scss
  4. 30
      src/app/ui/unity/unity.component.ts
  5. 2
      src/assets/unityApp/Build/UnityLoader.js
  6. BIN
      src/assets/unityApp/Build/unityApp.data.unityweb
  7. 4
      src/assets/unityApp/Build/unityApp.json
  8. BIN
      src/assets/unityApp/Build/unityApp.wasm.code.unityweb
  9. BIN
      src/assets/unityApp/Build/unityApp.wasm.framework.unityweb
  10. 2
      src/assets/unityApp/TemplateData/UnityProgress.js
  11. 6
      src/assets/unityApp/index.html
  12. 4
      typing.d.ts

3
angular.json

@ -35,8 +35,7 @@
"scripts": [
"node_modules/echarts/dist/echarts.js",
"./node_modules/swiper/js/swiper.min.js",
"src/assets/unityApp/Build/UnityLoader.js",
"src/assets/unityApp/TemplateData/UnityProgress.js"
"src/assets/unityApp/Build/UnityLoader.js"
]
},
"configurations": {

1
src/app/ui/unity/unity.component.html

@ -1,3 +1,4 @@
<div class="webgl-content">
<div id="unityContainer"></div>
<button (click)="CallUnity()">测试</button>
</div>

2
src/app/ui/unity/unity.component.scss

@ -2,5 +2,3 @@
width: 100%;
height: 100%;
}

30
src/app/ui/unity/unity.component.ts

@ -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);
}
}

2
src/assets/unityApp/Build/UnityLoader.js

File diff suppressed because one or more lines are too long

BIN
src/assets/unityApp/Build/unityApp.data.unityweb

Binary file not shown.

4
src/assets/unityApp/Build/unityApp.json

@ -1,6 +1,6 @@
{
"companyName": "DefaultCompany",
"productName": "2DPlanMakingTool",
"productName": "UnityCallAngular",
"productVersion": "0.1",
"dataUrl": "unityApp.data.unityweb",
"wasmCodeUrl": "unityApp.wasm.code.unityweb",
@ -12,5 +12,5 @@
"cacheControl": {"default": "must-revalidate"},
"developmentBuild": false,
"multithreading": false,
"unityVersion": "2019.3.2f1"
"unityVersion": "2019.3.0f3"
}

BIN
src/assets/unityApp/Build/unityApp.wasm.code.unityweb

Binary file not shown.

BIN
src/assets/unityApp/Build/unityApp.wasm.framework.unityweb

Binary file not shown.

2
src/assets/unityApp/TemplateData/UnityProgress.js

@ -21,4 +21,6 @@ function UnityProgress(unityInstance, progress) {
unityInstance.progress.empty.style.width = (100 * (1 - progress)) + "%";
if (progress == 1)
unityInstance.logo.style.display = unityInstance.progress.style.display = "none";
console.log('1234567890');
unityInstance.SendMessage("UnityWebGL", "CallUnity");
}

6
src/assets/unityApp/index.html

@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Unity WebGL Player | 2DPlanMakingTool</title>
<title>Unity WebGL Player | UnityCallAngular</title>
<link rel="shortcut icon" href="TemplateData/favicon.ico">
<link rel="stylesheet" href="TemplateData/style.css">
<script src="TemplateData/UnityProgress.js"></script>
@ -14,11 +14,11 @@
</head>
<body>
<div class="webgl-content">
<div id="unityContainer" style="width: 1024px; height: 768px"></div>
<div id="unityContainer" style="width: 960px; height: 600px"></div>
<div class="footer">
<div class="webgl-logo"></div>
<div class="fullscreen" onclick="unityInstance.SetFullscreen(1)"></div>
<div class="title">2DPlanMakingTool</div>
<div class="title">UnityCallAngular</div>
</div>
</div>
</body>

4
typing.d.ts vendored

@ -1,4 +0,0 @@
declare var UnityLoader : any;
interface Window{
GetName: any
}
Loading…
Cancel
Save