feat(hero): 新增英雄按等级切换不同颜色描边的功能
新增紫色描边shader与对应材质资源,为英雄预制体注册四种颜色描边材质 重构FlashSprite组件支持按等级切换描边,在英雄初始化与升级时自动更新描边样式
This commit is contained in:
@@ -12,6 +12,7 @@ import { HeroAttrsComp } from "./HeroAttrsComp";
|
||||
import { Tooltip } from "../skill/Tooltip";
|
||||
import { timedCom } from "../skill/timedCom";
|
||||
import { oneCom } from "../skill/oncend";
|
||||
import { FlashSprite } from "./hit-flash-white/scripts/FlashSprite";
|
||||
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
@@ -109,6 +110,12 @@ export class HeroViewComp extends CCComp {
|
||||
// 🔥 重置血条 UI 显示状态
|
||||
if (this.model) {
|
||||
this.hp_show();
|
||||
|
||||
// 根据英雄模型中的等级数据设置描边
|
||||
const flashSprite = this.node.getComponent(FlashSprite);
|
||||
if (flashSprite) {
|
||||
flashSprite.setOutlineByLevel(this.model.lv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,6 +248,14 @@ export class HeroViewComp extends CCComp {
|
||||
/** 升级特效 */
|
||||
private lv_up() {
|
||||
this.spawnTimedFx("game/skill/buff/buff_lvup", this.node, 1.0);
|
||||
|
||||
// 升级时同步更新描边
|
||||
if (this.model) {
|
||||
const flashSprite = this.node.getComponent(FlashSprite);
|
||||
if (flashSprite) {
|
||||
flashSprite.setOutlineByLevel(this.model.lv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 攻击力提升特效 */
|
||||
|
||||
@@ -5,24 +5,73 @@ const { ccclass, property } = _decorator;
|
||||
export class FlashSprite extends Component {
|
||||
|
||||
@property(Material)
|
||||
hitFlashMaterial: Material;
|
||||
orginalFlashMaterial: Material;
|
||||
sprite: Sprite;
|
||||
hitFlashMaterial: Material | null = null;
|
||||
|
||||
@property({ type: Material, tooltip: '绿色描边材质(2级)' })
|
||||
outlineMatGreen: Material | null = null;
|
||||
|
||||
@property({ type: Material, tooltip: '蓝色描边材质(3级)' })
|
||||
outlineMatBlue: Material | null = null;
|
||||
|
||||
@property({ type: Material, tooltip: '紫色描边材质(4级)' })
|
||||
outlineMatPurple: Material | null = null;
|
||||
|
||||
@property({ type: Material, tooltip: '黄色描边材质(5级)' })
|
||||
outlineMatYellow: Material | null = null;
|
||||
|
||||
orginalFlashMaterial: Material | null = null;
|
||||
defaultMaterial: Material | null = null; // 缓存最原始的无描边材质
|
||||
sprite: Sprite | null = null;
|
||||
|
||||
start() {
|
||||
this.sprite = this.node.getComponent(Sprite);
|
||||
this.orginalFlashMaterial = this.sprite.getRenderMaterial(0);
|
||||
|
||||
// 记录最初的默认材质(无描边)
|
||||
if (this.sprite) {
|
||||
this.defaultMaterial = this.sprite.getRenderMaterial(0);
|
||||
if (!this.orginalFlashMaterial) {
|
||||
this.orginalFlashMaterial = this.defaultMaterial;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
|
||||
/**
|
||||
* 根据英雄等级设置描边材质
|
||||
* @param level 英雄等级 (1=无描边, 2=绿, 3=蓝, 4=紫, 5=黄)
|
||||
*/
|
||||
public setOutlineByLevel(level: number) {
|
||||
if (!this.sprite) {
|
||||
this.sprite = this.node.getComponent(Sprite);
|
||||
}
|
||||
|
||||
let targetMat: Material | null = null;
|
||||
if (level === 2) {
|
||||
targetMat = this.outlineMatGreen;
|
||||
} else if (level === 3) {
|
||||
targetMat = this.outlineMatBlue;
|
||||
} else if (level === 4) {
|
||||
targetMat = this.outlineMatPurple;
|
||||
} else if (level >= 5) {
|
||||
targetMat = this.outlineMatYellow;
|
||||
} else {
|
||||
// 1级或异常情况,使用最原始的无描边材质
|
||||
targetMat = this.defaultMaterial;
|
||||
}
|
||||
|
||||
if (targetMat && this.sprite) {
|
||||
// 更新基础材质,确保闪白结束后恢复到这个描边材质
|
||||
this.orginalFlashMaterial = targetMat;
|
||||
this.sprite.setSharedMaterial(targetMat, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public clickFlash() {
|
||||
if (!this.sprite || !this.hitFlashMaterial) return;
|
||||
|
||||
this.sprite.setSharedMaterial(this.hitFlashMaterial, 0);
|
||||
this.scheduleOnce(() => {
|
||||
this.sprite.setSharedMaterial(this.orginalFlashMaterial, 0);
|
||||
if (this.sprite && this.orginalFlashMaterial) {
|
||||
this.sprite.setSharedMaterial(this.orginalFlashMaterial, 0);
|
||||
}
|
||||
}, 0.1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user