From ed1ef7a6327d3d61c304de2e7446442a4b46304e Mon Sep 17 00:00:00 2001 From: santy-wang Date: Sun, 5 Feb 2023 21:28:27 +0800 Subject: [PATCH] fix bugs --- assets/materials/connection.effect | 86 ++++++ assets/materials/connection.effect.meta | 11 + assets/materials/line.mtl | 12 + assets/materials/line.mtl.meta | 11 + assets/prefabs/Virus.prefab | 393 ++++++++++++------------ assets/scripts/Ball.ts | 4 +- 6 files changed, 320 insertions(+), 197 deletions(-) create mode 100644 assets/materials/connection.effect create mode 100644 assets/materials/connection.effect.meta create mode 100644 assets/materials/line.mtl create mode 100644 assets/materials/line.mtl.meta diff --git a/assets/materials/connection.effect b/assets/materials/connection.effect new file mode 100644 index 0000000..239d458 --- /dev/null +++ b/assets/materials/connection.effect @@ -0,0 +1,86 @@ +// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd. +CCEffect %{ + techniques: + - passes: + - vert: sprite-vs:vert + frag: sprite-fs:frag + depthStencilState: + depthTest: false + depthWrite: false + blendState: + targets: + - blend: true + blendSrc: src_alpha + blendDst: one_minus_src_alpha + blendDstAlpha: one_minus_src_alpha + rasterizerState: + cullMode: none + properties: + noiseMap: { value: white } + alphaThreshold: { value: 0.5 } +}% + +CCProgram sprite-vs %{ + precision highp float; + #include + #if USE_LOCAL + #include + #endif + #if SAMPLE_FROM_RT + #include + #endif + in vec3 a_position; + in vec2 a_texCoord; + in vec4 a_color; + + out vec4 color; + out vec2 uv0; + + vec4 vert () { + vec4 pos = vec4(a_position, 1); + + #if USE_LOCAL + pos = cc_matWorld * pos; + #endif + + #if USE_PIXEL_ALIGNMENT + pos = cc_matView * pos; + pos.xyz = floor(pos.xyz); + pos = cc_matProj * pos; + #else + pos = cc_matViewProj * pos; + #endif + + uv0 = a_texCoord; + #if SAMPLE_FROM_RT + CC_HANDLE_RT_SAMPLE_FLIP(uv0); + #endif + color = a_color; + + return pos; + } +}% + +CCProgram sprite-fs %{ + precision highp float; + #include + #include + #include + + in vec4 color; + + in vec2 uv0; + #pragma builtin(local) + layout(set = 2, binding = 11) uniform sampler2D cc_spriteTexture; + uniform sampler2D noiseMap; + + vec4 frag () { + vec4 o = vec4(1, 1, 1, 1); + + vec2 uv = uv0 * 2.0 - 1.0; + uv.x += cc_time.x; + vec4 color = texture(noiseMap, uv); + ALPHA_TEST(o); + return o; + } +}% diff --git a/assets/materials/connection.effect.meta b/assets/materials/connection.effect.meta new file mode 100644 index 0000000..d201fb3 --- /dev/null +++ b/assets/materials/connection.effect.meta @@ -0,0 +1,11 @@ +{ + "ver": "1.6.0", + "importer": "effect", + "imported": true, + "uuid": "1fb49540-f4c8-45e1-a1e7-48b00b1028a4", + "files": [ + ".json" + ], + "subMetas": {}, + "userData": {} +} diff --git a/assets/materials/line.mtl b/assets/materials/line.mtl new file mode 100644 index 0000000..a0b0deb --- /dev/null +++ b/assets/materials/line.mtl @@ -0,0 +1,12 @@ +{ + "__type__": "cc.Material", + "_name": "", + "_objFlags": 0, + "_native": "", + "_effectAsset": { + "__uuid__": "1baf0fc9-befa-459c-8bdd-af1a450a0319" + }, + "_techIdx": 0, + "_defines": [], + "_props": [] +} diff --git a/assets/materials/line.mtl.meta b/assets/materials/line.mtl.meta new file mode 100644 index 0000000..520e783 --- /dev/null +++ b/assets/materials/line.mtl.meta @@ -0,0 +1,11 @@ +{ + "ver": "1.0.16", + "importer": "material", + "imported": true, + "uuid": "707673eb-08fb-4874-b7fa-d97917853461", + "files": [ + ".json" + ], + "subMetas": {}, + "userData": {} +} diff --git a/assets/prefabs/Virus.prefab b/assets/prefabs/Virus.prefab index aac5085..10a7aa9 100644 --- a/assets/prefabs/Virus.prefab +++ b/assets/prefabs/Virus.prefab @@ -22,7 +22,7 @@ "__id__": 2 }, { - "__id__": 12 + "__id__": 10 }, { "__id__": 20 @@ -86,6 +86,166 @@ }, "_id": "" }, + { + "__type__": "cc.Node", + "_name": "MotionStreak", + "_objFlags": 0, + "_parent": { + "__id__": 1 + }, + "_children": [], + "_active": true, + "_components": [ + { + "__id__": 3 + }, + { + "__id__": 5 + }, + { + "__id__": 7 + } + ], + "_prefab": { + "__id__": 9 + }, + "_lpos": { + "__type__": "cc.Vec3", + "x": 0, + "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.UITransform", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 2 + }, + "_enabled": true, + "__prefab": { + "__id__": 4 + }, + "_contentSize": { + "__type__": "cc.Size", + "width": 52, + "height": 22 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0.7, + "y": 0.5 + }, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "61iqRtuLVKYrN0k4wSpFtZ" + }, + { + "__type__": "cc.Animation", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 2 + }, + "_enabled": true, + "__prefab": { + "__id__": 6 + }, + "playOnLoad": false, + "_clips": [ + { + "__uuid__": "4bfe65b8-e554-44a1-8053-d70d15f7966e", + "__expectedType__": "cc.AnimationClip" + } + ], + "_defaultClip": { + "__uuid__": "4bfe65b8-e554-44a1-8053-d70d15f7966e", + "__expectedType__": "cc.AnimationClip" + }, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "3butKyzXJNlbcjCZDSqG3V" + }, + { + "__type__": "cc.Sprite", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 2 + }, + "_enabled": true, + "__prefab": { + "__id__": 8 + }, + "_customMaterial": null, + "_srcBlendFactor": 2, + "_dstBlendFactor": 4, + "_color": { + "__type__": "cc.Color", + "r": 255, + "g": 255, + "b": 255, + "a": 255 + }, + "_spriteFrame": { + "__uuid__": "c94495ca-b92e-4f31-86aa-6a66b67354ef@e290b", + "__expectedType__": "cc.SpriteFrame" + }, + "_type": 0, + "_fillType": 0, + "_sizeMode": 1, + "_fillCenter": { + "__type__": "cc.Vec2", + "x": 0, + "y": 0 + }, + "_fillStart": 0, + "_fillRange": 0, + "_isTrimmedMode": true, + "_useGrayscale": false, + "_atlas": null, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "34gr+79JtCA67lyW+uy+yN" + }, + { + "__type__": "cc.PrefabInfo", + "root": { + "__id__": 1 + }, + "asset": { + "__id__": 0 + }, + "fileId": "d0c3nknoNH6aoW+SpTDq7e" + }, { "__type__": "cc.Node", "_name": "Indicator", @@ -95,13 +255,13 @@ }, "_children": [ { - "__id__": 3 + "__id__": 11 } ], "_active": true, "_components": [], "_prefab": { - "__id__": 11 + "__id__": 19 }, "_lpos": { "__type__": "cc.Vec3", @@ -136,23 +296,23 @@ "_name": "cylinder", "_objFlags": 0, "_parent": { - "__id__": 2 + "__id__": 10 }, "_children": [], "_active": true, "_components": [ { - "__id__": 4 + "__id__": 12 }, { - "__id__": 6 + "__id__": 14 }, { - "__id__": 8 + "__id__": 16 } ], "_prefab": { - "__id__": 10 + "__id__": 18 }, "_lpos": { "__type__": "cc.Vec3", @@ -187,11 +347,11 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 3 + "__id__": 11 }, "_enabled": true, "__prefab": { - "__id__": 5 + "__id__": 13 }, "_material": { "__uuid__": "ba21476f-2866-4f81-9c4d-6e359316e448", @@ -218,11 +378,11 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 3 + "__id__": 11 }, "_enabled": true, "__prefab": { - "__id__": 7 + "__id__": 15 }, "_group": 4, "_type": 4, @@ -254,11 +414,11 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 3 + "__id__": 11 }, "_enabled": true, "__prefab": { - "__id__": 9 + "__id__": 17 }, "_contentSize": { "__type__": "cc.Size", @@ -307,17 +467,17 @@ "_active": true, "_components": [ { - "__id__": 13 + "__id__": 21 }, { - "__id__": 15 + "__id__": 23 }, { - "__id__": 17 + "__id__": 25 } ], "_prefab": { - "__id__": 19 + "__id__": 27 }, "_lpos": { "__type__": "cc.Vec3", @@ -352,11 +512,11 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 12 + "__id__": 20 }, "_enabled": true, "__prefab": { - "__id__": 14 + "__id__": 22 }, "_contentSize": { "__type__": "cc.Size", @@ -379,11 +539,11 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 12 + "__id__": 20 }, "_enabled": true, "__prefab": { - "__id__": 16 + "__id__": 24 }, "playOnLoad": false, "_clips": [ @@ -407,11 +567,11 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 12 + "__id__": 20 }, "_enabled": true, "__prefab": { - "__id__": 18 + "__id__": 26 }, "_customMaterial": null, "_srcBlendFactor": 2, @@ -464,17 +624,17 @@ "_active": true, "_components": [ { - "__id__": 21 + "__id__": 29 }, { - "__id__": 23 + "__id__": 31 }, { - "__id__": 25 + "__id__": 33 } ], "_prefab": { - "__id__": 27 + "__id__": 35 }, "_lpos": { "__type__": "cc.Vec3", @@ -509,11 +669,11 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 20 + "__id__": 28 }, "_enabled": true, "__prefab": { - "__id__": 22 + "__id__": 30 }, "_contentSize": { "__type__": "cc.Size", @@ -536,11 +696,11 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 20 + "__id__": 28 }, "_enabled": true, "__prefab": { - "__id__": 24 + "__id__": 32 }, "playOnLoad": false, "_clips": [ @@ -564,11 +724,11 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 20 + "__id__": 28 }, "_enabled": true, "__prefab": { - "__id__": 26 + "__id__": 34 }, "_customMaterial": null, "_srcBlendFactor": 2, @@ -610,163 +770,6 @@ }, "fileId": "c8dU0lNrpEcrJO8Qyom1G8" }, - { - "__type__": "cc.Node", - "_name": "MotionStreak", - "_objFlags": 0, - "_parent": { - "__id__": 1 - }, - "_children": [], - "_active": true, - "_components": [ - { - "__id__": 29 - }, - { - "__id__": 31 - }, - { - "__id__": 33 - } - ], - "_prefab": { - "__id__": 35 - }, - "_lpos": { - "__type__": "cc.Vec3", - "x": 0, - "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.UITransform", - "_name": "", - "_objFlags": 0, - "node": { - "__id__": 28 - }, - "_enabled": true, - "__prefab": { - "__id__": 30 - }, - "_contentSize": { - "__type__": "cc.Size", - "width": 2.6, - "height": 1.1 - }, - "_anchorPoint": { - "__type__": "cc.Vec2", - "x": 0.7, - "y": 0.5 - }, - "_id": "" - }, - { - "__type__": "cc.CompPrefabInfo", - "fileId": "61iqRtuLVKYrN0k4wSpFtZ" - }, - { - "__type__": "cc.Animation", - "_name": "", - "_objFlags": 0, - "node": { - "__id__": 28 - }, - "_enabled": true, - "__prefab": { - "__id__": 32 - }, - "playOnLoad": false, - "_clips": [ - { - "__uuid__": "4bfe65b8-e554-44a1-8053-d70d15f7966e", - "__expectedType__": "cc.AnimationClip" - } - ], - "_defaultClip": { - "__uuid__": "4bfe65b8-e554-44a1-8053-d70d15f7966e", - "__expectedType__": "cc.AnimationClip" - }, - "_id": "" - }, - { - "__type__": "cc.CompPrefabInfo", - "fileId": "3butKyzXJNlbcjCZDSqG3V" - }, - { - "__type__": "cc.Sprite", - "_name": "", - "_objFlags": 0, - "node": { - "__id__": 28 - }, - "_enabled": true, - "__prefab": { - "__id__": 34 - }, - "_customMaterial": null, - "_srcBlendFactor": 2, - "_dstBlendFactor": 4, - "_color": { - "__type__": "cc.Color", - "r": 255, - "g": 255, - "b": 255, - "a": 255 - }, - "_spriteFrame": null, - "_type": 0, - "_fillType": 0, - "_sizeMode": 1, - "_fillCenter": { - "__type__": "cc.Vec2", - "x": 0, - "y": 0 - }, - "_fillStart": 0, - "_fillRange": 0, - "_isTrimmedMode": true, - "_useGrayscale": false, - "_atlas": null, - "_id": "" - }, - { - "__type__": "cc.CompPrefabInfo", - "fileId": "34gr+79JtCA67lyW+uy+yN" - }, - { - "__type__": "cc.PrefabInfo", - "root": { - "__id__": 1 - }, - "asset": { - "__id__": 0 - }, - "fileId": "d0c3nknoNH6aoW+SpTDq7e" - }, { "__type__": "cc.SphereCollider", "_name": "", @@ -846,13 +849,13 @@ "operationRadius": 30, "operationTheta": 60, "indicator": { - "__id__": 2 + "__id__": 10 }, "launchAnimation": { - "__id__": 15 + "__id__": 23 }, "absorbAnimation": { - "__id__": 23 + "__id__": 31 }, "idleAnimation": null, "pushStrength": 20, @@ -883,7 +886,7 @@ "__id__": 44 }, "motionStreakAnimation": { - "__id__": 31 + "__id__": 5 }, "smog": { "__uuid__": "24cd13b0-9d87-4143-8e00-0281ed709f31", diff --git a/assets/scripts/Ball.ts b/assets/scripts/Ball.ts index 20fb32d..4864e30 100644 --- a/assets/scripts/Ball.ts +++ b/assets/scripts/Ball.ts @@ -1,4 +1,4 @@ -import { _decorator, Component, RigidBody, Enum, Vec3, math, Collider, ICollisionEvent, js, Animation, Prefab, instantiate } from 'cc'; +import { _decorator, Component, RigidBody, Enum, Vec3, math, Collider, ICollisionEvent, js, Animation, Prefab, instantiate, Quat } from 'cc'; import { AudioController } from './AudioController'; import { LevelManager } from './LevelManager'; const { ccclass, property, requireComponent, type } = _decorator; @@ -103,7 +103,7 @@ export class Ball extends Component { update(deltaTime: number) { this._rigidBody.getLinearVelocity(this._velocity); if(this.motionStreakAnimation){ - this.motionStreakAnimation.node.eulerAngles = new Vec3(this.node.eulerAngles.x, this.node.eulerAngles.y, Math.atan2(this._velocity.y, this._velocity.x) * (180 / Math.PI)); + this.motionStreakAnimation.node.worldRotation = Quat.fromAngleZ(new Quat, Math.atan2(this._velocity.y, this._velocity.x) * (180 / Math.PI)); } } } \ No newline at end of file