Add FlashSprite.setOutlineByBossPhase with light/dark green shade option and red fallback; BossPhaseSystem drives HeroViewComp.applyBossPhaseOutline directly after phase switch (MON faction, no hero-level event semantics, pool-node safe); extract getFlashSprite/applyOutlineByLevel to dedupe the three outline call sites.
119 lines
4.3 KiB
TypeScript
119 lines
4.3 KiB
TypeScript
import { _decorator, color, Component, Material, Node, Sprite } from 'cc';
|
||
const { ccclass, property } = _decorator;
|
||
|
||
@ccclass('FlashSprite')
|
||
export class FlashSprite extends Component {
|
||
|
||
@property(Material)
|
||
hitFlashMaterial: Material | null = null;
|
||
|
||
@property({ type: Material, tooltip: '绿色描边材质(2级)' })
|
||
outlineMatGreen: Material | null = null;
|
||
|
||
@property({ type: Material, tooltip: '淡绿描边材质(Boss阶段2)' })
|
||
outlineMatGreenLight: Material | null = null;
|
||
|
||
@property({ type: Material, tooltip: '深绿描边材质(Boss阶段2备选)' })
|
||
outlineMatGreenDark: 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;
|
||
|
||
@property({ type: Material, tooltip: '红色描边材质(Boss阶段3)' })
|
||
outlineMatRed: Material | null = null;
|
||
|
||
orginalFlashMaterial: Material | null = null;
|
||
defaultMaterial: Material | null = null; // 缓存最原始的无描边材质
|
||
sprite: Sprite | null = null;
|
||
|
||
start() {
|
||
this.sprite = this.node.getComponent(Sprite);
|
||
// 记录最初的默认材质(无描边)
|
||
if (this.sprite) {
|
||
this.defaultMaterial = this.sprite.getRenderMaterial(0);
|
||
if (!this.orginalFlashMaterial) {
|
||
this.orginalFlashMaterial = this.defaultMaterial;
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 根据英雄等级设置描边材质
|
||
* @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);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 按 Boss 阶段设置描边材质(优先级高于等级描边)
|
||
* Why: Boss 阶段是战斗强反馈(绿色警告 / 红色危险),与英雄等级成长是两套视觉语言,
|
||
* 用独立通道避免污染 setOutlineByLevel 的等级语义
|
||
* @param phase 阶段索引:1=P2 绿 / 2=P3 红 / 0=P1 恢复默认
|
||
* @param greenShade P2 绿色色调:'light' 淡绿(默认)/ 'dark' 深绿
|
||
*/
|
||
public setOutlineByBossPhase(phase: number, greenShade: 'light' | 'dark' = 'light') {
|
||
if (!this.sprite) {
|
||
this.sprite = this.node.getComponent(Sprite);
|
||
}
|
||
if (!this.sprite) return;
|
||
|
||
let targetMat: Material | null = null;
|
||
if (phase === 1) {
|
||
targetMat = greenShade === 'dark'
|
||
? (this.outlineMatGreenDark ?? this.outlineMatGreenLight ?? this.outlineMatGreen)
|
||
: (this.outlineMatGreenLight ?? this.outlineMatGreenDark ?? this.outlineMatGreen);
|
||
} else if (phase >= 2) {
|
||
targetMat = this.outlineMatRed ?? this.outlineMatYellow;
|
||
} else {
|
||
targetMat = this.defaultMaterial;
|
||
}
|
||
|
||
if (targetMat) {
|
||
// 更新基础材质,确保闪白结束后恢复到这个阶段描边材质
|
||
this.orginalFlashMaterial = targetMat;
|
||
this.sprite.setSharedMaterial(targetMat, 0);
|
||
}
|
||
}
|
||
|
||
public clickFlash() {
|
||
if (!this.sprite || !this.hitFlashMaterial) return;
|
||
|
||
this.sprite.setSharedMaterial(this.hitFlashMaterial, 0);
|
||
this.scheduleOnce(() => {
|
||
if (this.sprite && this.orginalFlashMaterial) {
|
||
this.sprite.setSharedMaterial(this.orginalFlashMaterial, 0);
|
||
}
|
||
}, 0.1);
|
||
}
|
||
}
|
||
|