import { _decorator, CCFloat, Color, Component, Material, Node, sp, Sprite } from 'cc'; const { ccclass, property ,menu} = _decorator; @ccclass('ShimmerWhite') @menu("树木特效/闪白") export class ShimmerWhite extends Component { @property(CCFloat) duration:number = 0.25; median:number; time:number; private _material:Material; private Color:Color = new Color(255,255,255);//Color.WHITE.clone(); get material():Material{ return; // if(!this._material){ // if (this.node.getComponent(Sprite)) { // this._material = this.node.getComponent(Sprite).getMaterialInstance(0); // } else { // this.spAnim = this.node.getComponent(sp.Skeleton); // this._material = this.spAnim.getMaterialInstance(0); // } // } // return this._material; }; spAnim:sp.Skeleton; onLoad() { this.time = 0; this.median = this.duration / 2; //this.material.setProperty("u_rate", 1); }; onEnable() { this.time = 0; // this.material.setProperty("u_rate", 1); this.Color.a = 255; this.node.getComponent(Sprite).color = this.Color; }; // onDisable() { // this.time = 0; // // this.material.setProperty("u_rate", 1); // this.Color.a = 255; // this.node.getComponent(Sprite).color = this.Color; // }; show(time?:number) { if (!time) { time = this.duration; } this.duration = time; this.time = this.duration; this.Color.a = 0; this.node.getComponent(Sprite).color = this.Color; //this.material.setProperty("u_rate", 1); }; update(dt:number) { if (this.time > 0) { this.time -= dt; if (this.time < 0) { this.time = 0; } var e = 1 - this.time / this.duration; this.Color.a = e*255; this.node.getComponent(Sprite).color = this.Color; //this.material.setProperty("u_rate", ); // if (this.spAnim) { // this.spAnim._updateMaterial(); // } } }; }