feat(hero): 添加受击闪光效果并重构相关代码

新增FlashSprite组件实现受击闪光效果
重构HeroAnmComp和HeroViewComp以支持闪光效果
更新多个英雄prefab以包含闪光材质和组件
This commit is contained in:
2025-11-15 11:15:30 +08:00
parent 4af9a6fd9e
commit 46a779633a
28 changed files with 2800 additions and 862 deletions

View File

@@ -1,17 +1,19 @@
import { _decorator, Animation, AnimationState, CCClass, Component, } from "cc";
import { HeroViewComp } from "./HeroViewComp";
import { FacSet } from "../common/config/GameSet";
import { FlashSprite } from "./hit-flash-white/scripts/FlashSprite";
const { ccclass, property } = _decorator;
@ccclass('HeroAnmComp')
export default class HeroAnmComp extends Component{
fsSprite:FlashSprite = null!;
private anmcon:any=null
private _hasStop = true;
private default_anim:string='Idle'
anms:any[]=["idle","move","stun","dead","buff","atk0","atk1","atk2","max0","max1"]
onLoad () {
this.anmcon=this.node.getComponent(Animation)
this.fsSprite = this.node.getComponent(FlashSprite);
this.anmcon.on(Animation.EventType.FINISHED, this.onAnimationFinished, this);
}
@@ -25,6 +27,9 @@ export default class HeroAnmComp extends Component{
this.anmcon.play(this.default_anim)
}
}
atked(){
this.fsSprite.clickFlash();
}
move () {
if(this.anmcon.getState("move").isPlaying) return
this.anmcon.play("move")

View File

@@ -66,6 +66,9 @@ export class HeroSpine extends Component {
break
}
}
do_atked(){
this.anm.atked()
}
dead(){
// console.log("do dead");
this.anm.dead()

View File

@@ -14,7 +14,7 @@ import { Tooltip } from "../skill/Tooltip";
import { timedCom } from "../skill/timedCom";
import { HeroInfo, HType } from "../common/config/heroSet";
import { Timer } from "db://oops-framework/core/common/timer/Timer";
import { FlashSprite } from "./materials/scripts/FlashSprite";
const { ccclass, property } = _decorator;
@@ -38,7 +38,6 @@ export class HeroViewComp extends CCComp {
// 血条显示相关
hpBarShowTime:number = 5; // 血条显示持续时间(秒)
hpBarShowCD:number = 0; // 血条显示计时器
fsSprite:FlashSprite = null!;
// ==================== UI 节点引用 ====================
private top_node: Node = null!;
@@ -103,7 +102,6 @@ export class HeroViewComp extends CCComp {
this.top_node = this.node.getChildByName("top");
let hp_y = this.node.getComponent(UITransform).height+10;
this.top_node.setPosition(0, hp_y, 0);
this.fsSprite = this.node.getComponent(FlashSprite);
}
@@ -217,7 +215,7 @@ export class HeroViewComp extends CCComp {
/** 受击特效 */
private in_atked(anm: string = "atked", scale: number = 1) {
this.fsSprite.clickFlash();
this.as.do_atked()
// var path = "game/skill/end/" + anm;
// var prefab: Prefab = oops.res.get(path, Prefab)!;
// var node = instantiate(prefab);

View File

@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "0463b128-1ee2-4cee-972b-eaf9fee2bf6c",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "044ce6c2-4a58-4a83-8a5b-f6d7f89a3aa3",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,31 @@
{
"__type__": "cc.Material",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"_native": "",
"_effectAsset": {
"__uuid__": "b8d82f81-c2f9-40e5-805b-922f0c170a79",
"__expectedType__": "cc.EffectAsset"
},
"_techIdx": 0,
"_defines": [
{
"USE_TEXTURE": true
}
],
"_states": [
{
"rasterizerState": {},
"depthStencilState": {},
"blendState": {
"targets": [
{}
]
}
}
],
"_props": [
{}
]
}

View File

@@ -0,0 +1,11 @@
{
"ver": "1.0.21",
"importer": "material",
"imported": true,
"uuid": "8eee8ab1-fe48-4b22-b956-3f5c18fc4810",
"files": [
".json"
],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "e091410c-c7b6-4416-ae99-38697c103286",
"files": [],
"subMetas": {},
"userData": {}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,11 @@
{
"ver": "1.1.50",
"importer": "scene",
"imported": true,
"uuid": "5e1d3eb2-c300-4627-94c7-2ee03b8314f1",
"files": [
".json"
],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "e4743688-2ecb-436b-8826-69fcb4485b73",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,29 @@
import { _decorator, color, Component, Material, Node, Sprite } from 'cc';
const { ccclass, property } = _decorator;
@ccclass('FlashSprite')
export class FlashSprite extends Component {
@property(Material)
hitFlashMaterial: Material;
orginalFlashMaterial: Material;
sprite: Sprite;
start() {
this.sprite = this.node.getComponent(Sprite);
this.orginalFlashMaterial = this.sprite.getRenderMaterial(0);
}
update(deltaTime: number) {
}
public clickFlash() {
this.sprite.setSharedMaterial(this.hitFlashMaterial, 0);
this.scheduleOnce(() => {
this.sprite.setSharedMaterial(this.orginalFlashMaterial, 0);
}, 0.1);
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "954e4dd8-f902-4734-8529-9aa4c2580ec0",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "5553e1ee-12b8-410b-833c-33586c917944",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,97 @@
// 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:
alphaThreshold: { value: 0.5 }
}%
CCProgram sprite-vs %{
precision highp float;
#include <builtin/uniforms/cc-global>
#if USE_LOCAL
#include <builtin/uniforms/cc-local>
#endif
#if SAMPLE_FROM_RT
#include <common/common-define>
#endif
in vec3 a_position;
in vec2 a_texCoord;
in vec4 a_color;
out vec4 color;
out vec2 uv0;
out vec4 lightColor;
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;
lightColor = a_color;
return pos;
}
}%
CCProgram sprite-fs %{
precision highp float;
#include <builtin/internal/embedded-alpha>
#include <builtin/internal/alpha-test>
in vec4 color;
in vec4 lightColor;
#if USE_TEXTURE
in vec2 uv0;
#pragma builtin(local)
layout(set = 2, binding = 12) uniform sampler2D cc_spriteTexture;
#endif
vec4 frag () {
vec4 o = vec4(1, 1, 1, 1);
#if USE_TEXTURE
o *= CCSampleWithAlphaSeparated(cc_spriteTexture, uv0);
#if IS_GRAY
float gray = 0.2126 * o.r + 0.7152 * o.g + 0.0722 * o.b;
o.r = o.g = o.b = gray;
#endif
#endif
o.rgb = o.rgb * (1.0 - lightColor.a) + lightColor.rgb * lightColor.a;
o *= color;
ALPHA_TEST(o);
return o;
}
}%

View File

@@ -0,0 +1,11 @@
{
"ver": "1.7.1",
"importer": "effect",
"imported": true,
"uuid": "b8d82f81-c2f9-40e5-805b-922f0c170a79",
"files": [
".json"
],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "0463b128-1ee2-4cee-972b-eaf9fee2bf6c",
"files": [],
"subMetas": {},
"userData": {}
}