From 8930b34e38914165c7a14a22739ae6e09c7f15d6 Mon Sep 17 00:00:00 2001 From: King Wang Date: Tue, 7 Dec 2021 01:00:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=90=BD=E7=82=B9=E6=98=BE?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../assets/prefabs/Arrow/Arrow.prefab | 201 +++++++++- .../frontend/assets/prefabs/Arrow/Arrow.ts | 15 +- .../frontend/assets/prefabs/Arrow/mat.meta | 12 + .../assets/prefabs/Arrow/mat/circle.png | Bin 0 -> 7717 bytes .../assets/prefabs/Arrow/mat/circle.png.meta | 40 ++ .../prefabs/Arrow/mat/mat-circle-border.mtl | 35 ++ .../Arrow/mat/mat-circle-border.mtl.meta | 11 + .../assets/scenes/GameScene/GameScene.scene | 358 +++++++++--------- .../assets/scenes/GameScene/GameScene.ts | 25 +- 9 files changed, 489 insertions(+), 208 deletions(-) create mode 100644 examples/cocos-creator-multiplayer/frontend/assets/prefabs/Arrow/mat.meta create mode 100644 examples/cocos-creator-multiplayer/frontend/assets/prefabs/Arrow/mat/circle.png create mode 100644 examples/cocos-creator-multiplayer/frontend/assets/prefabs/Arrow/mat/circle.png.meta create mode 100644 examples/cocos-creator-multiplayer/frontend/assets/prefabs/Arrow/mat/mat-circle-border.mtl create mode 100644 examples/cocos-creator-multiplayer/frontend/assets/prefabs/Arrow/mat/mat-circle-border.mtl.meta diff --git a/examples/cocos-creator-multiplayer/frontend/assets/prefabs/Arrow/Arrow.prefab b/examples/cocos-creator-multiplayer/frontend/assets/prefabs/Arrow/Arrow.prefab index b1369cb..a8c1c1f 100644 --- a/examples/cocos-creator-multiplayer/frontend/assets/prefabs/Arrow/Arrow.prefab +++ b/examples/cocos-creator-multiplayer/frontend/assets/prefabs/Arrow/Arrow.prefab @@ -18,21 +18,69 @@ "_children": [ { "__id__": 2 + }, + { + "__id__": 13 } ], "_active": true, "_components": [ { - "__id__": 11 + "__id__": 18 } ], "_prefab": { - "__id__": 13 + "__id__": 20 }, "_lpos": { "__type__": "cc.Vec3", "x": 0, - "y": 1.248, + "y": 0, + "z": 0 + }, + "_lrot": { + "__type__": "cc.Quat", + "x": 0, + "y": 0, + "z": 0, + "w": 1 + }, + "_lscale": { + "__type__": "cc.Vec3", + "x": 1, + "y": 1, + "z": 1 + }, + "_layer": 1073741824, + "_euler": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_id": "" + }, + { + "__type__": "cc.Node", + "_name": "arrow", + "_objFlags": 0, + "_parent": { + "__id__": 1 + }, + "_children": [ + { + "__id__": 3 + } + ], + "_active": true, + "_components": [], + "_prefab": { + "__id__": 12 + }, + "_lpos": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, "z": 0 }, "_lrot": { @@ -62,17 +110,17 @@ "_name": "javelin", "_objFlags": 0, "_parent": { - "__id__": 1 + "__id__": 2 }, "_children": [ { - "__id__": 3 + "__id__": 4 } ], "_active": true, "_components": [], "_prefab": { - "__id__": 10 + "__id__": 11 }, "_lpos": { "__type__": "cc.Vec3", @@ -107,17 +155,17 @@ "_name": "RootNode", "_objFlags": 0, "_parent": { - "__id__": 2 + "__id__": 3 }, "_children": [ { - "__id__": 4 + "__id__": 5 } ], "_active": true, "_components": [], "_prefab": { - "__id__": 9 + "__id__": 10 }, "_lpos": { "__type__": "cc.Vec3", @@ -152,17 +200,17 @@ "_name": "对象001", "_objFlags": 0, "_parent": { - "__id__": 3 + "__id__": 4 }, "_children": [], "_active": true, "_components": [ { - "__id__": 5 + "__id__": 6 } ], "_prefab": { - "__id__": 8 + "__id__": 9 }, "_lpos": { "__type__": "cc.Vec3", @@ -197,11 +245,11 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 4 + "__id__": 5 }, "_enabled": true, "__prefab": { - "__id__": 6 + "__id__": 7 }, "_materials": [ { @@ -211,7 +259,7 @@ ], "_visFlags": 0, "lightmapSettings": { - "__id__": 7 + "__id__": 8 }, "_mesh": { "__uuid__": "401c28d6-3085-4209-9f2e-3aff6da5855c@035c0", @@ -272,6 +320,121 @@ }, "fileId": "e4s27HRhlBboS6EhifyuWl" }, + { + "__type__": "cc.PrefabInfo", + "root": { + "__id__": 1 + }, + "asset": { + "__id__": 0 + }, + "fileId": "5bf0LATlNOKYlJWbTsFq/i" + }, + { + "__type__": "cc.Node", + "_name": "circle", + "_objFlags": 0, + "_parent": { + "__id__": 1 + }, + "_children": [], + "_active": true, + "_components": [ + { + "__id__": 14 + } + ], + "_prefab": { + "__id__": 17 + }, + "_lpos": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0.1, + "z": 0 + }, + "_lrot": { + "__type__": "cc.Quat", + "x": -0.7071067811865475, + "y": 0, + "z": 0, + "w": 0.7071067811865476 + }, + "_lscale": { + "__type__": "cc.Vec3", + "x": 4.7, + "y": 4.7, + "z": 1 + }, + "_layer": 1073741824, + "_euler": { + "__type__": "cc.Vec3", + "x": -90, + "y": 0, + "z": 0 + }, + "_id": "" + }, + { + "__type__": "cc.MeshRenderer", + "_name": "Quad", + "_objFlags": 0, + "node": { + "__id__": 13 + }, + "_enabled": true, + "__prefab": { + "__id__": 15 + }, + "_materials": [ + { + "__uuid__": "5bd9794b-bfe1-46e1-b390-6060f1f08992", + "__expectedType__": "cc.Material" + } + ], + "_visFlags": 0, + "lightmapSettings": { + "__id__": 16 + }, + "_mesh": { + "__uuid__": "1263d74c-8167-4928-91a6-4e2672411f47@fc873", + "__expectedType__": "cc.Mesh" + }, + "_shadowCastingMode": 0, + "_shadowReceivingMode": 1, + "_enableMorph": true, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "c3HynMn7RK/rmskpx1afpj" + }, + { + "__type__": "cc.ModelLightmapSettings", + "texture": null, + "uvParam": { + "__type__": "cc.Vec4", + "x": 0, + "y": 0, + "z": 0, + "w": 0 + }, + "_bakeable": false, + "_castShadow": false, + "_receiveShadow": false, + "_recieveShadow": false, + "_lightmapSize": 64 + }, + { + "__type__": "cc.PrefabInfo", + "root": { + "__id__": 1 + }, + "asset": { + "__id__": 0 + }, + "fileId": "51HSPesSRFgrKXr9+iQVi5" + }, { "__type__": "2330evjMPtBCJhzJpbQ/Kgk", "_name": "", @@ -282,7 +445,13 @@ }, "_enabled": true, "__prefab": { - "__id__": 12 + "__id__": 19 + }, + "arrow": { + "__id__": 2 + }, + "circle": { + "__id__": 13 }, "_id": "" }, diff --git a/examples/cocos-creator-multiplayer/frontend/assets/prefabs/Arrow/Arrow.ts b/examples/cocos-creator-multiplayer/frontend/assets/prefabs/Arrow/Arrow.ts index 2d4638c..374d522 100644 --- a/examples/cocos-creator-multiplayer/frontend/assets/prefabs/Arrow/Arrow.ts +++ b/examples/cocos-creator-multiplayer/frontend/assets/prefabs/Arrow/Arrow.ts @@ -1,5 +1,5 @@ -import { Component, Vec3, _decorator } from 'cc'; +import { Color, Component, MeshRenderer, Node, Vec3, _decorator } from 'cc'; import { MathUtil } from '../../scripts/models/MathUtil'; import { gameConfig } from '../../scripts/shared/game/gameConfig'; import { ArrowState } from '../../scripts/shared/game/state/ArrowState'; @@ -13,6 +13,11 @@ export class Arrow extends Component { id!: number; state!: ArrowState; + @property(Node) + arrow!: Node; + @property(Node) + circle!: Node; + // 开始位置(场景坐标) private _startPos = new Vec3; // 落点位置(场景坐标) @@ -32,6 +37,8 @@ export class Arrow extends Component { this._endTime = this._startTime + gameConfig.arrowFlyTime; this._updatePosAndForward(0); + this.circle.setPosition(this._endPos.x, 0.1, this._endPos.z); + this.circle.getComponent(MeshRenderer)?.material!.setProperty('mainColor', new Color(255, 255, 255, 255)); } update() { @@ -51,6 +58,8 @@ export class Arrow extends Component { } this._isRemoved = true; + this.circle.getComponent(MeshRenderer)?.material!.setProperty('mainColor', new Color(255, 0, 0, 255)); + // 落地 1 秒后消失 this.scheduleOnce(() => { this.node.removeFromParent() @@ -59,11 +68,11 @@ export class Arrow extends Component { private _updatePosAndForward(percent: number) { let nextPos = this._getPos(percent); - this.node.position = nextPos; + this.arrow.position = nextPos; //武器朝向下一个目标位置, 形成曲线飞行的感觉 let lastPos = this._getPos(percent - 0.01) - this.node.forward = nextPos.clone().subtract(lastPos).normalize(); + this.arrow.forward = nextPos.clone().subtract(lastPos).normalize(); } private _getPos(percent: number) { diff --git a/examples/cocos-creator-multiplayer/frontend/assets/prefabs/Arrow/mat.meta b/examples/cocos-creator-multiplayer/frontend/assets/prefabs/Arrow/mat.meta new file mode 100644 index 0000000..4d0cb10 --- /dev/null +++ b/examples/cocos-creator-multiplayer/frontend/assets/prefabs/Arrow/mat.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.0", + "importer": "directory", + "imported": true, + "uuid": "92638561-9d6c-4011-ba3c-c672a78e54f1", + "files": [], + "subMetas": {}, + "userData": { + "compressionType": {}, + "isRemoteBundle": {} + } +} diff --git a/examples/cocos-creator-multiplayer/frontend/assets/prefabs/Arrow/mat/circle.png b/examples/cocos-creator-multiplayer/frontend/assets/prefabs/Arrow/mat/circle.png new file mode 100644 index 0000000000000000000000000000000000000000..e9f7d54058ebc598e1535bed5f33226c2872494a GIT binary patch literal 7717 zcmV+=9@^oFP)W;QlX0qB{Yo^DL-wQ3cBMi{M9zGA<7L?jrkPbqqdM!3`#2hG-Yr=A>itE#$L^aA(^JF>e?ViG2FId3`st zU6+}FK$C1;%e;OfpEcULNyHpI5i{i5L7RNK-;NXn?fCjaK68RaBwWb4e#YwBP)&>& zqa&i2+=zUvc)Ms5E+QZ=+jp2Oxoems9&bCzY}3!U%~6ta6hutqQ(`E2yxu{RfV;Bq zp6nYDvWtAWtOPvi*mg2t-^OvqLdvZsqC5B%)URXWDWQ1VZm_M`rgi|u^%YJ(u?e+PItVFsVkx_}q>rTRBTIcP&jmgQi zn{o%|DmPXkHHvQq>-`$`3Smk+K}J@ZPS_a1({qrQB*MU1D#B)dP=xkRPWKcswB6Q^AU5=Gb0y0t67f77@6H; zw8_ZZj)H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v98c*3WT*e~SKktk6e5lpwK zimJ*o5zjB+1`^P*(L{6%AS6e>>QAbA?#uEH+Cht|W6m_|_0s^wmz5lm8am-LYF5Qm zMb);iJtue(Yy}Y=0|*)UlWM+M@%Ch&NM-vJv2lu-IwH)oU_J5~hZ1iQ9JdhhD$zm6 zoat7Qs_9h)lsn8Rq^c$77NfkQmaQS4Vk?R02ngwQWKz}CI{AP$ z`Et>6q=a30L{`MUg!T}%3)OF1$;a4gA}TVepBynGlg?_VikR~am54m*aw6MvgwkbS zhkVX$o~rN|NN5-p5gi%R&C5!-zM}0w+CMwAEITQgkQ~Y8Ol-^KO50m&f^!%p5g9b8 zf|bg!D>V?C-`uwBA?bKIQ?34EM7mKEPceETI{XnxQAFH4iI@W`XFyaX7DE+~$#|Ap@wTq& fLG^-yf=l49_5m8em@cLX00000NkvXXu0mjfbxXmY literal 0 HcmV?d00001 diff --git a/examples/cocos-creator-multiplayer/frontend/assets/prefabs/Arrow/mat/circle.png.meta b/examples/cocos-creator-multiplayer/frontend/assets/prefabs/Arrow/mat/circle.png.meta new file mode 100644 index 0000000..b53c42a --- /dev/null +++ b/examples/cocos-creator-multiplayer/frontend/assets/prefabs/Arrow/mat/circle.png.meta @@ -0,0 +1,40 @@ +{ + "ver": "1.0.21", + "importer": "image", + "imported": true, + "uuid": "06fa3f81-1aae-4aad-a544-143756df67eb", + "files": [ + ".png", + ".json" + ], + "subMetas": { + "6c48a": { + "importer": "texture", + "uuid": "06fa3f81-1aae-4aad-a544-143756df67eb@6c48a", + "displayName": "circle", + "id": "6c48a", + "name": "texture", + "userData": { + "wrapModeS": "repeat", + "wrapModeT": "repeat", + "minfilter": "linear", + "magfilter": "linear", + "mipfilter": "none", + "anisotropy": 0, + "isUuid": true, + "imageUuidOrDatabaseUri": "06fa3f81-1aae-4aad-a544-143756df67eb" + }, + "ver": "1.0.21", + "imported": true, + "files": [ + ".json" + ], + "subMetas": {} + } + }, + "userData": { + "hasAlpha": true, + "type": "texture", + "redirect": "06fa3f81-1aae-4aad-a544-143756df67eb@6c48a" + } +} diff --git a/examples/cocos-creator-multiplayer/frontend/assets/prefabs/Arrow/mat/mat-circle-border.mtl b/examples/cocos-creator-multiplayer/frontend/assets/prefabs/Arrow/mat/mat-circle-border.mtl new file mode 100644 index 0000000..f874721 --- /dev/null +++ b/examples/cocos-creator-multiplayer/frontend/assets/prefabs/Arrow/mat/mat-circle-border.mtl @@ -0,0 +1,35 @@ +{ + "__type__": "cc.Material", + "_name": "", + "_objFlags": 0, + "_native": "", + "_effectAsset": { + "__uuid__": "a3cd009f-0ab0-420d-9278-b9fdab939bbc", + "__expectedType__": "cc.EffectAsset" + }, + "_techIdx": "1", + "_defines": [ + { + "USE_TEXTURE": true + } + ], + "_states": [ + { + "rasterizerState": {}, + "depthStencilState": {}, + "blendState": { + "targets": [ + {} + ] + } + } + ], + "_props": [ + { + "mainTexture": { + "__uuid__": "06fa3f81-1aae-4aad-a544-143756df67eb@6c48a", + "__expectedType__": "cc.Texture2D" + } + } + ] +} \ No newline at end of file diff --git a/examples/cocos-creator-multiplayer/frontend/assets/prefabs/Arrow/mat/mat-circle-border.mtl.meta b/examples/cocos-creator-multiplayer/frontend/assets/prefabs/Arrow/mat/mat-circle-border.mtl.meta new file mode 100644 index 0000000..50d3bfc --- /dev/null +++ b/examples/cocos-creator-multiplayer/frontend/assets/prefabs/Arrow/mat/mat-circle-border.mtl.meta @@ -0,0 +1,11 @@ +{ + "ver": "1.0.9", + "importer": "material", + "imported": true, + "uuid": "5bd9794b-bfe1-46e1-b390-6060f1f08992", + "files": [ + ".json" + ], + "subMetas": {}, + "userData": {} +} diff --git a/examples/cocos-creator-multiplayer/frontend/assets/scenes/GameScene/GameScene.scene b/examples/cocos-creator-multiplayer/frontend/assets/scenes/GameScene/GameScene.scene index e374f94..6a96be9 100644 --- a/examples/cocos-creator-multiplayer/frontend/assets/scenes/GameScene/GameScene.scene +++ b/examples/cocos-creator-multiplayer/frontend/assets/scenes/GameScene/GameScene.scene @@ -27,17 +27,20 @@ "__id__": 16 }, { - "__id__": 25 + "__id__": 17 + }, + { + "__id__": 50 } ], "_active": true, "_components": [], "_prefab": { - "__id__": 58 + "__id__": 53 }, "autoReleaseAssets": false, "_globals": { - "__id__": 61 + "__id__": 56 }, "_id": "0d3889f6-dc9c-424e-b8cd-6fa78d63af15" }, @@ -320,11 +323,7 @@ "_parent": { "__id__": 1 }, - "_children": [ - { - "__id__": 17 - } - ], + "_children": [], "_active": true, "_components": [], "_prefab": null, @@ -356,113 +355,6 @@ }, "_id": "46+eJFPoNAd75C26ynMBuo" }, - { - "__type__": "cc.Node", - "_objFlags": 0, - "_parent": { - "__id__": 16 - }, - "_prefab": { - "__id__": 18 - } - }, - { - "__type__": "cc.PrefabInfo", - "root": { - "__id__": 17 - }, - "asset": { - "__uuid__": "6eda806d-83a6-474f-a7b7-b75c57ba73b3", - "__expectedType__": "cc.Prefab" - }, - "fileId": "ad10ECDidH979xbvqlbbgn", - "instance": { - "__id__": 19 - } - }, - { - "__type__": "cc.PrefabInstance", - "fileId": "f7+AxAbd1K15HySl2cJ7yx", - "mountedChildren": [], - "mountedComponents": [], - "propertyOverrides": [ - { - "__id__": 20 - }, - { - "__id__": 22 - }, - { - "__id__": 23 - }, - { - "__id__": 24 - } - ], - "removedComponents": [] - }, - { - "__type__": "CCPropertyOverrideInfo", - "targetInfo": { - "__id__": 21 - }, - "propertyPath": [ - "_name" - ], - "value": "Arrow" - }, - { - "__type__": "cc.TargetInfo", - "localID": [ - "ad10ECDidH979xbvqlbbgn" - ] - }, - { - "__type__": "CCPropertyOverrideInfo", - "targetInfo": { - "__id__": 21 - }, - "propertyPath": [ - "_lpos" - ], - "value": { - "__type__": "cc.Vec3", - "x": 0, - "y": 1.248, - "z": 0 - } - }, - { - "__type__": "CCPropertyOverrideInfo", - "targetInfo": { - "__id__": 21 - }, - "propertyPath": [ - "_lrot" - ], - "value": { - "__type__": "cc.Quat", - "x": 0, - "y": 0, - "z": 0, - "w": 1 - } - }, - { - "__type__": "CCPropertyOverrideInfo", - "targetInfo": { - "__id__": 21 - }, - "propertyPath": [ - "_euler" - ], - "value": { - "__type__": "cc.Vec3", - "x": 0, - "y": 0, - "z": 0 - } - }, { "__type__": "cc.Node", "_name": "Canvas", @@ -472,28 +364,28 @@ }, "_children": [ { - "__id__": 26 + "__id__": 18 }, { - "__id__": 28 + "__id__": 20 }, { - "__id__": 45 + "__id__": 37 } ], "_active": true, "_components": [ { - "__id__": 54 + "__id__": 46 }, { - "__id__": 55 + "__id__": 47 }, { - "__id__": 56 + "__id__": 48 }, { - "__id__": 57 + "__id__": 49 } ], "_prefab": null, @@ -530,13 +422,13 @@ "_name": "Camera", "_objFlags": 0, "_parent": { - "__id__": 25 + "__id__": 17 }, "_children": [], "_active": true, "_components": [ { - "__id__": 27 + "__id__": 19 } ], "_prefab": null, @@ -573,7 +465,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 26 + "__id__": 18 }, "_enabled": true, "__prefab": null, @@ -613,16 +505,16 @@ "__type__": "cc.Node", "_objFlags": 0, "_parent": { - "__id__": 25 + "__id__": 17 }, "_prefab": { - "__id__": 29 + "__id__": 21 } }, { "__type__": "cc.PrefabInfo", "root": { - "__id__": 28 + "__id__": 20 }, "asset": { "__uuid__": "0363f7f8-204e-410e-ade0-03adca6ea835", @@ -630,7 +522,7 @@ }, "fileId": "25fHuwytBN2qk6dH5oVJvO", "instance": { - "__id__": 30 + "__id__": 22 } }, { @@ -639,32 +531,32 @@ "mountedChildren": [], "mountedComponents": [], "propertyOverrides": [ + { + "__id__": 23 + }, + { + "__id__": 25 + }, + { + "__id__": 26 + }, + { + "__id__": 27 + }, + { + "__id__": 28 + }, + { + "__id__": 30 + }, { "__id__": 31 }, { "__id__": 33 }, - { - "__id__": 34 - }, { "__id__": 35 - }, - { - "__id__": 36 - }, - { - "__id__": 38 - }, - { - "__id__": 39 - }, - { - "__id__": 41 - }, - { - "__id__": 43 } ], "removedComponents": [] @@ -672,7 +564,7 @@ { "__type__": "CCPropertyOverrideInfo", "targetInfo": { - "__id__": 32 + "__id__": 24 }, "propertyPath": [ "_name" @@ -688,7 +580,7 @@ { "__type__": "CCPropertyOverrideInfo", "targetInfo": { - "__id__": 32 + "__id__": 24 }, "propertyPath": [ "_lpos" @@ -703,7 +595,7 @@ { "__type__": "CCPropertyOverrideInfo", "targetInfo": { - "__id__": 32 + "__id__": 24 }, "propertyPath": [ "_lrot" @@ -719,7 +611,7 @@ { "__type__": "CCPropertyOverrideInfo", "targetInfo": { - "__id__": 32 + "__id__": 24 }, "propertyPath": [ "_euler" @@ -734,7 +626,7 @@ { "__type__": "CCPropertyOverrideInfo", "targetInfo": { - "__id__": 37 + "__id__": 29 }, "propertyPath": [ "_contentSize" @@ -754,7 +646,7 @@ { "__type__": "CCPropertyOverrideInfo", "targetInfo": { - "__id__": 32 + "__id__": 24 }, "propertyPath": [ "_layer" @@ -764,7 +656,7 @@ { "__type__": "CCPropertyOverrideInfo", "targetInfo": { - "__id__": 40 + "__id__": 32 }, "propertyPath": [ "_layer" @@ -780,7 +672,7 @@ { "__type__": "CCPropertyOverrideInfo", "targetInfo": { - "__id__": 42 + "__id__": 34 }, "propertyPath": [ "_layer" @@ -796,7 +688,7 @@ { "__type__": "CCPropertyOverrideInfo", "targetInfo": { - "__id__": 44 + "__id__": 36 }, "propertyPath": [ "_layer" @@ -814,26 +706,26 @@ "_name": "btnAttack", "_objFlags": 0, "_parent": { - "__id__": 25 + "__id__": 17 }, "_children": [ { - "__id__": 46 + "__id__": 38 } ], "_active": true, "_components": [ { - "__id__": 49 + "__id__": 41 }, { - "__id__": 50 + "__id__": 42 }, { - "__id__": 51 + "__id__": 43 }, { - "__id__": 53 + "__id__": 45 } ], "_prefab": null, @@ -870,16 +762,16 @@ "_name": "Label", "_objFlags": 512, "_parent": { - "__id__": 45 + "__id__": 37 }, "_children": [], "_active": true, "_components": [ { - "__id__": 47 + "__id__": 39 }, { - "__id__": 48 + "__id__": 40 } ], "_prefab": null, @@ -916,7 +808,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 46 + "__id__": 38 }, "_enabled": true, "__prefab": null, @@ -937,7 +829,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 46 + "__id__": 38 }, "_enabled": true, "__prefab": null, @@ -975,7 +867,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 45 + "__id__": 37 }, "_enabled": true, "__prefab": null, @@ -996,7 +888,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 45 + "__id__": 37 }, "_enabled": true, "__prefab": null, @@ -1035,13 +927,13 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 45 + "__id__": 37 }, "_enabled": true, "__prefab": null, "clickEvents": [ { - "__id__": 52 + "__id__": 44 } ], "_interactable": true, @@ -1093,14 +985,14 @@ "_duration": 0.1, "_zoomScale": 1.2, "_target": { - "__id__": 45 + "__id__": 37 }, "_id": "96d2z2/TpJ558pTlUMNNUO" }, { "__type__": "cc.ClickEvent", "target": { - "__id__": 25 + "__id__": 17 }, "component": "", "_componentId": "d4728cOzxlKHLMu5Xg48U8U", @@ -1112,7 +1004,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 45 + "__id__": 37 }, "_enabled": true, "__prefab": null, @@ -1124,7 +1016,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 25 + "__id__": 17 }, "_enabled": true, "__prefab": null, @@ -1145,12 +1037,12 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 25 + "__id__": 17 }, "_enabled": true, "__prefab": null, "_cameraComponent": { - "__id__": 27 + "__id__": 19 }, "_alignCanvasWithScreen": true, "_id": "ebX9QTnS1AlKH1eI+/bdJk" @@ -1160,7 +1052,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 25 + "__id__": 17 }, "_enabled": true, "__prefab": null, @@ -1189,7 +1081,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 25 + "__id__": 17 }, "_enabled": true, "__prefab": null, @@ -1212,33 +1104,123 @@ "__id__": 4 }, "btnAttack": { - "__id__": 45 + "__id__": 37 + }, + "attackPosIndicator": { + "__id__": 50 }, "_id": "86PJf2PFRK5LGUONuKqmzS" }, + { + "__type__": "cc.Node", + "_name": "attackPosIndicator", + "_objFlags": 0, + "_parent": { + "__id__": 1 + }, + "_children": [], + "_active": true, + "_components": [ + { + "__id__": 51 + } + ], + "_prefab": null, + "_lpos": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0.1, + "z": 0 + }, + "_lrot": { + "__type__": "cc.Quat", + "x": -0.7071067811865475, + "y": 0, + "z": 0, + "w": 0.7071067811865476 + }, + "_lscale": { + "__type__": "cc.Vec3", + "x": 4.7, + "y": 4.7, + "z": 1 + }, + "_layer": 1073741824, + "_euler": { + "__type__": "cc.Vec3", + "x": -90, + "y": 0, + "z": 0 + }, + "_id": "fdFAHYRNVNIr2aN7wVD+Nn" + }, + { + "__type__": "cc.MeshRenderer", + "_name": "Quad", + "_objFlags": 0, + "node": { + "__id__": 50 + }, + "_enabled": true, + "__prefab": null, + "_materials": [ + { + "__uuid__": "5bd9794b-bfe1-46e1-b390-6060f1f08992", + "__expectedType__": "cc.Material" + } + ], + "_visFlags": 0, + "lightmapSettings": { + "__id__": 52 + }, + "_mesh": { + "__uuid__": "1263d74c-8167-4928-91a6-4e2672411f47@fc873", + "__expectedType__": "cc.Mesh" + }, + "_shadowCastingMode": 0, + "_shadowReceivingMode": 1, + "_enableMorph": true, + "_id": "6fuuF9XfNLL4/uFd0cFyL+" + }, + { + "__type__": "cc.ModelLightmapSettings", + "texture": null, + "uvParam": { + "__type__": "cc.Vec4", + "x": 0, + "y": 0, + "z": 0, + "w": 0 + }, + "_bakeable": false, + "_castShadow": false, + "_receiveShadow": false, + "_recieveShadow": false, + "_lightmapSize": 64 + }, { "__type__": "cc.PrefabInfo", "fileId": "", "targetOverrides": [ { - "__id__": 59 + "__id__": 54 } ] }, { "__type__": "cc.TargetOverrideInfo", "source": { - "__id__": 57 + "__id__": 49 }, "sourceInfo": null, "propertyPath": [ "joyStick" ], "target": { - "__id__": 28 + "__id__": 20 }, "targetInfo": { - "__id__": 60 + "__id__": 55 } }, { @@ -1250,16 +1232,16 @@ { "__type__": "cc.SceneGlobals", "ambient": { - "__id__": 62 + "__id__": 57 }, "shadows": { - "__id__": 63 + "__id__": 58 }, "_skybox": { - "__id__": 64 + "__id__": 59 }, "fog": { - "__id__": 65 + "__id__": 60 } }, { diff --git a/examples/cocos-creator-multiplayer/frontend/assets/scenes/GameScene/GameScene.ts b/examples/cocos-creator-multiplayer/frontend/assets/scenes/GameScene/GameScene.ts index 18c15f6..115ffe1 100644 --- a/examples/cocos-creator-multiplayer/frontend/assets/scenes/GameScene/GameScene.ts +++ b/examples/cocos-creator-multiplayer/frontend/assets/scenes/GameScene/GameScene.ts @@ -1,5 +1,5 @@ -import { Button, Component, instantiate, Node, Prefab, UIOpacity, Vec2, _decorator } from 'cc'; +import { Button, Color, Component, instantiate, MeshRenderer, Node, Prefab, UIOpacity, Vec2, _decorator } from 'cc'; import { Arrow } from '../../prefabs/Arrow/Arrow'; import { Joystick } from '../../prefabs/Joystick/Joystick'; import { Player } from '../../prefabs/Player/Player'; @@ -30,6 +30,8 @@ export class GameScene extends Component { @property(Node) btnAttack: Node = null as any; + @property(Node) + attackPosIndicator!: Node; gameManager!: GameManager; @@ -40,6 +42,8 @@ export class GameScene extends Component { onLoad() { (window as any).game = this; + this.attackPosIndicator.getComponent(MeshRenderer)!.material!.setProperty('mainColor', Color.CYAN); + // 初始化摇杆 this.joyStick.options = { onOperate: v => { @@ -87,6 +91,8 @@ export class GameScene extends Component { } this._updatePlayers(); + + this._updateAttackIndicator(); } private _updatePlayers() { @@ -159,6 +165,7 @@ export class GameScene extends Component { let sceneOffset = playerNode.forward.clone().normalize().multiplyScalar(gameConfig.arrowDistance); // 攻击落点(逻辑层坐标) let targetPos = new Vec2(playerState.pos.x, playerState.pos.y).add2f(sceneOffset.x, -sceneOffset.z); + // 发送输入 this.gameManager.sendClientInput({ type: 'PlayerAttack', @@ -175,4 +182,20 @@ export class GameScene extends Component { this.btnAttack.getComponent(UIOpacity)!.opacity = 255; }, 1) } + + private _updateAttackIndicator() { + let playerState = this.gameManager.state.players.find(v => v.id === this.gameManager.selfPlayerId); + if (!playerState) { + return; + } + + let playerNode = this._playerInstances[this.gameManager.selfPlayerId]?.node; + if (!playerNode) { + return; + } + + // 攻击落点位置(表现层坐标) + let sceneTargetPos = playerNode.position.clone().add(playerNode.forward.clone().normalize().multiplyScalar(gameConfig.arrowDistance)); + this.attackPosIndicator.setPosition(sceneTargetPos.x, 0.1, sceneTargetPos.z); + } } \ No newline at end of file