| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- import { Label, Prefab, instantiate ,Node, math} from "cc";
- import { Layout_UI_Notify } from "./Layout_UI_Notify";
- import { aa } from "db://assets/scripts/aa";
- import { GameUILayers } from "db://assets/scripts/GameUILayers";
- class NotifyInfo {
- private static readonly time:number=2;
- private static readonly init_y:number=120;
- private static readonly up_y:number=80;//上升一格
- private static readonly move_speed:number=880;//向上移动速度
- private static readonly sc_state0:number=0.8;//变小大小
- private static readonly sc_state0_time:number=0.22;
- private static readonly sc_state1:number=1.2;//变大大小
- private static readonly sc_state1_time:number=0.41;
- private static readonly sc_state2:number=1;//正常大小
- private time:number;
- private node:Node;
- private state:number;
- private _state_time:number=0;
- public constructor(node:Node,parent:Node,txt:string){
- this.time=NotifyInfo.time;
- this.node=node;
- this.state=0;
- this._state_time=0;
- let label= node.getComponentInChildren(Label);
- label.string=txt;
- node.parent=parent;
- node.setPosition(0,NotifyInfo.init_y,0);
- node.setScale(NotifyInfo.sc_state0,NotifyInfo.sc_state0,NotifyInfo.sc_state0);
- node.active=true;
- }
- public up():void{
- this.node.setPosition(this.node.position.x, this.node.position.y+NotifyInfo.up_y, this.node.position.z);
- }
- public run(dt:number):boolean{
- this.time-=dt;
- if(this.time<=0){
- this.node.destroy();
- this.node=null;
- return true;
- }else if(this.time<0.5){
- this.node.setPosition(this.node.position.x, this.node.position.y+NotifyInfo.move_speed*dt, this.node.position.z);
- }else {
- if(this.state===0){
- this._state_time+=dt;
- let ratio=this._state_time/NotifyInfo.sc_state0_time;
- if(ratio>=1){
- this.state=1;
- this._state_time=0;
- this.node.setScale(NotifyInfo.sc_state1,NotifyInfo.sc_state1,NotifyInfo.sc_state1);
- }else{
- let sc=math.lerp(NotifyInfo.sc_state0,NotifyInfo.sc_state1,ratio);
- this.node.setScale(sc,sc,sc);
- }
- }else if(this.state===1){
- this._state_time+=dt;
- let ratio=this._state_time/NotifyInfo.sc_state1_time;
- if(ratio>=1){
- this.state=2;
- this._state_time=0;
- this.node.setScale(NotifyInfo.sc_state2,NotifyInfo.sc_state2,NotifyInfo.sc_state2);
- }else{
- let sc=math.lerp(NotifyInfo.sc_state1,NotifyInfo.sc_state2,ratio);
- this.node.setScale(sc,sc,sc);
- }
- }
- }
- return false;
- }
- }
- export class UI_Notify extends aa.UIcontroller {
- constructor() {
- super('ui/ui_notify/UI_Notify', GameUILayers.NOTICE, Layout_UI_Notify);
- }
- private _info_prefab:Prefab;
- private notifys:NotifyInfo[]=[];
- protected onCreated(): void {
- let layout = this.layout as Layout_UI_Notify;
- this._info_prefab=layout.info_prefab;
- }
- public newNotify(txt:string){
- let info = new NotifyInfo(instantiate(this._info_prefab),this.node,txt);
- for(var i=this.notifys.length-1;i>=0;i--)this.notifys[i].up();
- this.notifys.push(info);
- }
- protected onUpdate(dt?: number): void {
- for(var i=this.notifys.length-1;i>=0;i--)if(this.notifys[i].run(dt))this.notifys.splice(i,1);
- }
- dispose(): void {
- this._info_prefab=null;
- }
- }
|