[add] first
This commit is contained in:
77
assets/scripts/logic/effect/fx-bullet-tracer.ts
Normal file
77
assets/scripts/logic/effect/fx-bullet-tracer.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
import { _decorator, Component, error, Node, randomRange, Vec3 } from 'cc';
|
||||
import { Res } from '../../core/res/res';
|
||||
import { fun } from '../../core/util/fun';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('FxBulletTracer')
|
||||
export class FxBulletTracer extends Component {
|
||||
|
||||
@property
|
||||
poolCount = 5;
|
||||
|
||||
@property
|
||||
segment = 5;
|
||||
|
||||
@property
|
||||
hiddenTime = 0.05;
|
||||
|
||||
pool:Array<Node> | undefined;
|
||||
|
||||
__preload() {
|
||||
this.node.on('init', this.init, this);
|
||||
}
|
||||
|
||||
init() {
|
||||
|
||||
this.pool = new Array(this.poolCount);
|
||||
const firstChild = this.node.children[0];
|
||||
this.pool[0] = firstChild;
|
||||
firstChild.active = false;
|
||||
|
||||
for(let i = 1; i < this.poolCount; i++) {
|
||||
this.pool[i] = Res.instNode(firstChild, this.node);
|
||||
}
|
||||
|
||||
this.node.on('setTracer', this.setTracer, this);
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
this.node.off('init', this.init, this);
|
||||
this.node.off('setTracer', this.setTracer, this);
|
||||
}
|
||||
|
||||
public setTracer(start:Vec3, end:Vec3) {
|
||||
|
||||
const endPosition = end.clone();
|
||||
const direction = end.clone().subtract(start).normalize();
|
||||
const length = endPosition.subtract(start).length();
|
||||
|
||||
const eachSegment = length/this.poolCount;
|
||||
const count = this.calculateSegment(length);
|
||||
const startPosition = start.clone();
|
||||
|
||||
for(let i = 0; i < count; i++) {
|
||||
const currentLength = eachSegment;
|
||||
const currentNode = this.pool![i];
|
||||
currentNode.active = true;
|
||||
currentNode.setPosition(startPosition);
|
||||
currentNode.lookAt(end);
|
||||
currentNode.setScale(0.3, 1, randomRange(0.3, currentLength));
|
||||
startPosition.add(direction.clone().multiplyScalar(currentLength));
|
||||
}
|
||||
|
||||
fun.delay(this.hiddenLines.bind(this), this.hiddenTime);
|
||||
|
||||
}
|
||||
|
||||
calculateSegment(length:number):number {
|
||||
let count = Math.round(length / this.segment);
|
||||
if(count > this.poolCount) count = this.poolCount;
|
||||
return count;
|
||||
}
|
||||
|
||||
hiddenLines() {
|
||||
for(let i = 0; i < this.poolCount; i++) this.pool![i].active = false;
|
||||
}
|
||||
}
|
||||
|
||||
9
assets/scripts/logic/effect/fx-bullet-tracer.ts.meta
Normal file
9
assets/scripts/logic/effect/fx-bullet-tracer.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "2027a429-8cee-495f-a9f5-c9611512be64",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
39
assets/scripts/logic/effect/fx-car-random-move.ts
Normal file
39
assets/scripts/logic/effect/fx-car-random-move.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { _decorator, Component, Node, randomRange } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('FxCarRandomMove')
|
||||
export class FxCarRandomMove extends Component {
|
||||
|
||||
@property
|
||||
offsetY = 54;
|
||||
|
||||
@property
|
||||
intervalTime = 0;
|
||||
|
||||
@property
|
||||
count = 5;
|
||||
|
||||
@property
|
||||
minTime = 3;
|
||||
|
||||
@property
|
||||
maxTime = 10;
|
||||
|
||||
start () {
|
||||
this.intervalTime = randomRange(this.minTime, this.maxTime);
|
||||
this.node.setPosition(0, this.offsetY, 0);
|
||||
}
|
||||
|
||||
update (deltaTime: number) {
|
||||
|
||||
this.intervalTime -= deltaTime;
|
||||
if (this.intervalTime < 0) {
|
||||
this.intervalTime = randomRange(this.minTime, this.maxTime);
|
||||
for (let i = 0; i < this.node.children.length; i++) {
|
||||
this.node.children[i].emit('msg_node_fly_car');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
9
assets/scripts/logic/effect/fx-car-random-move.ts.meta
Normal file
9
assets/scripts/logic/effect/fx-car-random-move.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "e2a81ec1-b745-4583-9f0c-c219f976e33d",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
42
assets/scripts/logic/effect/fx-fly-car.ts
Normal file
42
assets/scripts/logic/effect/fx-fly-car.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { _decorator, Component, Animation, randomRange, randomRangeInt, random } from 'cc';
|
||||
import { Sound } from '../../core/audio/sound';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('FxFlyCar')
|
||||
export class FxFlyCar extends Component {
|
||||
|
||||
@property
|
||||
maxTime = 5;
|
||||
|
||||
@property
|
||||
minTime = 1;
|
||||
|
||||
animation: Animation | undefined | null;
|
||||
|
||||
waitTime = 0;
|
||||
|
||||
start () {
|
||||
this.animation = this.node.children[0].getComponent(Animation);
|
||||
this.node.on('msg_node_fly_car', () => {
|
||||
this.waitTime = randomRange(this.minTime, this.maxTime);
|
||||
})
|
||||
}
|
||||
|
||||
update (deltaTime: number) {
|
||||
|
||||
this.waitTime -= deltaTime;
|
||||
if (this.waitTime < 0) {
|
||||
this.waitTime = 9999999999;
|
||||
this.node.setRotationFromEuler(0, randomRange(0, 360), 0);
|
||||
const y = randomRangeInt(0, 5);
|
||||
this.node.setPosition(0, y, 0);
|
||||
this.animation?.stop();
|
||||
this.animation?.play();
|
||||
this.animation!.defaultClip!.speed = randomRange(0.2, 0.6);
|
||||
if (random() > 0.5 && y < 7) Sound.on('sfx_car_fly', randomRange(0.3, 1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
9
assets/scripts/logic/effect/fx-fly-car.ts.meta
Normal file
9
assets/scripts/logic/effect/fx-fly-car.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "ca8aab36-e037-489d-8d30-e7a94ee8ee50",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
61
assets/scripts/logic/effect/fx-ghost-vertex.ts
Normal file
61
assets/scripts/logic/effect/fx-ghost-vertex.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import { _decorator, Component, Node, SkinnedMeshRenderer, v4, v3, Vec3, clamp01, Material } from 'cc';
|
||||
import { UtilVec3 } from '../../core/util/util';
|
||||
import { TestColliderMeshSwitch } from '../../test/test-collider-mesh-switch';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('FxGhostVertex')
|
||||
export class FxGhostVertex extends Component {
|
||||
|
||||
@property
|
||||
intensity = 4;
|
||||
|
||||
private materials: Array<Material> = [];
|
||||
|
||||
private directionUniform = v4();
|
||||
private direction: Vec3 = v3();
|
||||
|
||||
private currentPosition: Vec3 | undefined;
|
||||
private lastPosition: Vec3 | undefined;
|
||||
|
||||
private t = 0;
|
||||
|
||||
start() {
|
||||
this.currentPosition = this.node.position.clone();
|
||||
this.lastPosition = this.currentPosition.clone();
|
||||
|
||||
let components = this.node.getComponentsInChildren(SkinnedMeshRenderer);
|
||||
components.forEach(
|
||||
(comp) => {
|
||||
this.materials.push(comp.material!);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
UtilVec3.copy(this.currentPosition!, this.node.worldPosition);
|
||||
|
||||
if (this.currentPosition!.equals(this.lastPosition!)) {
|
||||
this.t = 0;
|
||||
}
|
||||
|
||||
this.t += deltaTime;
|
||||
this.t = clamp01(this.t);
|
||||
Vec3.lerp(this.lastPosition!, this.lastPosition!, this.currentPosition!, this.t);
|
||||
Vec3.subtract(this.direction, this.lastPosition!, this.currentPosition!).multiplyScalar(this.intensity);
|
||||
|
||||
this.materials.forEach(
|
||||
(material: Material) => {
|
||||
let handle = material.passes[0].getHandle("direction")
|
||||
material.passes[0].getUniform(handle, this.directionUniform);
|
||||
this.directionUniform.set(
|
||||
this.direction.x,
|
||||
this.direction.y,
|
||||
this.direction.z,
|
||||
this.directionUniform.w,
|
||||
);
|
||||
material.passes[0].setUniform(handle, this.directionUniform);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
9
assets/scripts/logic/effect/fx-ghost-vertex.ts.meta
Normal file
9
assets/scripts/logic/effect/fx-ghost-vertex.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "2f040e1b-be67-4125-8394-4b876ca3f471",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
94
assets/scripts/logic/effect/fx-ghost.ts
Normal file
94
assets/scripts/logic/effect/fx-ghost.ts
Normal file
@@ -0,0 +1,94 @@
|
||||
import { _decorator, Component, Node, MeshRenderer, Mesh, SkinnedMeshRenderer } from 'cc';
|
||||
import { Res } from '../../core/res/res';
|
||||
import { UtilNode } from '../../core/util/util';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('FxGhost')
|
||||
export class FxGhost extends Component {
|
||||
|
||||
@property
|
||||
count = 5;
|
||||
|
||||
@property(Node)
|
||||
target:Node|undefined;
|
||||
|
||||
@property
|
||||
simpleTime = 1;
|
||||
|
||||
meshRenders:SkinnedMeshRenderer[] | undefined;
|
||||
|
||||
_intervalTime = 0;
|
||||
|
||||
_ghostItems:GhostNode[] = [];
|
||||
|
||||
_eachCount = 0;
|
||||
|
||||
_index = 0;
|
||||
|
||||
_total = 0;
|
||||
|
||||
start() {
|
||||
|
||||
this.meshRenders = this.target!.getComponentsInChildren(SkinnedMeshRenderer);
|
||||
|
||||
console.log(this.meshRenders);
|
||||
|
||||
this._eachCount = this.meshRenders.length;
|
||||
|
||||
const total = this.count * this._eachCount;
|
||||
|
||||
this._total = total;
|
||||
|
||||
this._ghostItems = Array<GhostNode>(total);
|
||||
|
||||
const itemNode = this.node!.children[0];
|
||||
this._ghostItems[0] = {
|
||||
node:itemNode,
|
||||
meshRender:UtilNode.getComponent(itemNode, MeshRenderer),
|
||||
}
|
||||
for(let i = 1; i < total; i++) {
|
||||
const newNode = Res.instNode(itemNode, this.node);
|
||||
this._ghostItems[i] = {
|
||||
node:newNode,
|
||||
meshRender:UtilNode.getComponent(newNode, MeshRenderer),
|
||||
}
|
||||
}
|
||||
|
||||
console.log(this.meshRenders, this._ghostItems);
|
||||
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
|
||||
this._intervalTime -= deltaTime;
|
||||
if(this._intervalTime < 0) {
|
||||
this.simpleMeshInfo();
|
||||
this._intervalTime = this.simpleTime;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
simpleMeshInfo() {
|
||||
for(let i = 0; i < this._eachCount; i++) {
|
||||
const mesh = this.meshRenders![i].mesh;
|
||||
const node = this.meshRenders![i].node;
|
||||
if(mesh != null) {
|
||||
const copyMesh = Object.assign(mesh);
|
||||
const ghost = this._ghostItems[this._index];
|
||||
ghost.meshRender.mesh = copyMesh;
|
||||
ghost.node.setPosition(this._index, node.worldPosition.y, node.worldPosition.z);
|
||||
ghost.node.setWorldRotation(node.getWorldRotation());
|
||||
this._index++;
|
||||
console.log(this._index);
|
||||
if(this._index >= this._total) this._index = 0;
|
||||
}else{
|
||||
console.warn(`${this.meshRenders![i].node.name} Can not find mesh`)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export type GhostNode = {
|
||||
node: Node,
|
||||
meshRender: MeshRenderer,
|
||||
}
|
||||
9
assets/scripts/logic/effect/fx-ghost.ts.meta
Normal file
9
assets/scripts/logic/effect/fx-ghost.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "153349b7-ceea-4465-86f0-69b95bd07ab5",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
61
assets/scripts/logic/effect/fx-light-flash.ts
Normal file
61
assets/scripts/logic/effect/fx-light-flash.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import { _decorator, Color, Component, Material, math, MeshRenderer, Node, randomRange, randomRangeInt } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('FxLightFlash')
|
||||
export class FxLightFlash extends Component {
|
||||
|
||||
matLight:Material | undefined | null;
|
||||
|
||||
lightColor:Color = new Color(255, 255, 255, 255);
|
||||
|
||||
lightValueMax = 10;
|
||||
|
||||
lightValueMin = 200;
|
||||
|
||||
length = 0;
|
||||
|
||||
flashTimes = 3;
|
||||
|
||||
value = 0;
|
||||
|
||||
t = 0;
|
||||
|
||||
smooth = 10;
|
||||
|
||||
isFlash = false;
|
||||
|
||||
start() {
|
||||
|
||||
this.matLight = this.node.getComponent(MeshRenderer)?.materials[0];
|
||||
|
||||
this.onFlash();
|
||||
|
||||
}
|
||||
|
||||
onFlash() {
|
||||
|
||||
this.flashTimes = randomRangeInt(1, 5);
|
||||
|
||||
this.lightValueMax = 255;
|
||||
|
||||
this.lightValueMin = randomRangeInt(180, 200);
|
||||
|
||||
this.length = this.lightValueMax - this.lightValueMin;
|
||||
|
||||
this.value = this.lightValueMax;
|
||||
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
|
||||
this.t += deltaTime;
|
||||
|
||||
this.value = math.pingPong(this.t * this.smooth, this.length) + this.lightValueMin;
|
||||
this.lightColor.a = this.value;
|
||||
this.lightColor.g = this.value;
|
||||
this.lightColor.b = this.value;
|
||||
this.matLight?.setProperty('emissive', this.lightColor);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
9
assets/scripts/logic/effect/fx-light-flash.ts.meta
Normal file
9
assets/scripts/logic/effect/fx-light-flash.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "81bbc284-b42b-4a87-9360-c0681a57ff31",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
20
assets/scripts/logic/effect/fx-ray-line.ts
Normal file
20
assets/scripts/logic/effect/fx-ray-line.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { _decorator, Component, Node, v3, Vec2, Vec3 } from 'cc';
|
||||
import { UtilVec3 } from '../../core/util/util';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('FxRayLine')
|
||||
export class FxRayLine extends Component {
|
||||
|
||||
direction:Vec3 = v3(0, 0, 0);
|
||||
|
||||
public setRayLine(start:Vec3, end:Vec3) {
|
||||
|
||||
UtilVec3.copy(this.direction, end);
|
||||
this.direction.subtract(start);
|
||||
const length = this.direction.length();
|
||||
//this.node.lookAt(this.direction);
|
||||
this.node.setScale(0.1, 1, length);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
9
assets/scripts/logic/effect/fx-ray-line.ts.meta
Normal file
9
assets/scripts/logic/effect/fx-ray-line.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "303d6977-6f09-414b-882c-c5e82ef29075",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
89
assets/scripts/logic/effect/gun-tracer-pool.ts
Normal file
89
assets/scripts/logic/effect/gun-tracer-pool.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
Copyright (c) 2020-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { _decorator, Component, Node, Vec2, Vec3, CCFloat } from 'cc';
|
||||
import { Res } from '../../core/res/res';
|
||||
import { Msg } from '../../core/msg/msg';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('GunTracerPool')
|
||||
export class GunTracerPool extends Component {
|
||||
|
||||
//The depth of the object pool.
|
||||
@property({ type: CCFloat, tooltip: 'The depth of the object pool.' })
|
||||
poolCount = 20;
|
||||
|
||||
// A collection of arrays that store object pools.
|
||||
pool: Array<Node> | undefined;
|
||||
|
||||
// The usage index of the object pool.
|
||||
index = 0;
|
||||
|
||||
start () {
|
||||
|
||||
// Create an array of objects based on the object pool depth.
|
||||
this.pool = new Array(this.poolCount);
|
||||
|
||||
// Get the base object of the object pool.
|
||||
const poolItem = this.node.children[0];
|
||||
|
||||
// Set the base object as the first element of the object pool.
|
||||
this.pool[0] = poolItem;
|
||||
|
||||
// Starting from one, generate an object pool in a loop.
|
||||
for (let i = 1; i < this.poolCount; i++) {
|
||||
// Instantiates a new object from the base object. And map to the current object pool index object.
|
||||
this.pool[i] = Res.instNode(poolItem, this.node);
|
||||
// Initialize this newly generated object.
|
||||
this.pool[i].emit('init');
|
||||
}
|
||||
|
||||
// Initialize the base object.
|
||||
poolItem.emit('init');
|
||||
|
||||
// Register an external access message executor
|
||||
Msg.on('msg_set_tracer', this.setTracer.bind(this));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set start and end positions
|
||||
* @param data set data.
|
||||
*/
|
||||
setTracer (data: { start: Vec3, end: Vec3 }) {
|
||||
|
||||
// Get a ray from the object pool.
|
||||
this.pool![this.index].emit('setTracer', data.start, data.end);
|
||||
|
||||
// The object pool index add one.
|
||||
this.index++;
|
||||
|
||||
// If the index exceeds the maximum length, set the index to start from 0.
|
||||
if (this.index >= this.poolCount) this.index = 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
9
assets/scripts/logic/effect/gun-tracer-pool.ts.meta
Normal file
9
assets/scripts/logic/effect/gun-tracer-pool.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "b37075c6-b5bd-4e80-8e09-00a546a3bcdf",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
81
assets/scripts/logic/effect/sfx-heart.ts
Normal file
81
assets/scripts/logic/effect/sfx-heart.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
Copyright (c) 2020-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { _decorator, AudioSource, Component, math, Node } from 'cc';
|
||||
import { Msg } from '../../core/msg/msg';
|
||||
import { Level } from '../level/level';
|
||||
import { Sound } from '../../core/audio/sound';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('SfxHeart')
|
||||
export class SfxHeart extends Component {
|
||||
|
||||
_sfxAudio: AudioSource | undefined
|
||||
|
||||
volume = 0;
|
||||
currentVolume = 0;
|
||||
|
||||
sceneVolume = 1;
|
||||
currentSceneVolume = 1;
|
||||
|
||||
isLow = false;
|
||||
|
||||
|
||||
start() {
|
||||
this._sfxAudio = this.getComponent(AudioSource)!;
|
||||
this._sfxAudio.volume = 0;
|
||||
this._sfxAudio.loop = true;
|
||||
this._sfxAudio.play();
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
|
||||
const player = Level.Instance._player;
|
||||
|
||||
if(!player) return;
|
||||
|
||||
if(player && player?._data?.is_low_hp && !player.is_dead) {
|
||||
if(this.isLow == false) {
|
||||
this.isLow = true;
|
||||
Msg.emit('msg_ui_fx_open', 'effect_low_hp');
|
||||
}
|
||||
this.currentVolume = Sound.volumeSound;
|
||||
this.currentSceneVolume = 0.1;
|
||||
}else{
|
||||
if(this.isLow){
|
||||
this.isLow = false;
|
||||
Msg.emit('msg_ui_fx_close', 'effect_low_hp');
|
||||
}
|
||||
this.currentVolume = 0;
|
||||
this.currentSceneVolume = 1;
|
||||
}
|
||||
this.volume = math.lerp(this.volume, this.currentVolume, deltaTime);
|
||||
this.sceneVolume = math.lerp(this.sceneVolume, this.currentSceneVolume, deltaTime);
|
||||
this._sfxAudio!.volume = this.volume;
|
||||
Sound.sceneMusicPercent = this.sceneVolume;
|
||||
Sound.updateBGM();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
9
assets/scripts/logic/effect/sfx-heart.ts.meta
Normal file
9
assets/scripts/logic/effect/sfx-heart.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "e5186ce1-e2f8-40c5-8f33-2119b4019700",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user