refactor(map): replace main node显隐操作转为动画控制
将原来通过查找main节点手动控制显隐的逻辑,替换为新增的MapLayer动画启停方法,简化代码逻辑并统一动画管理方式
This commit is contained in:
@@ -80,10 +80,8 @@ export class MissionHomeComp extends CCComp {
|
|||||||
this.node.active=false;
|
this.node.active=false;
|
||||||
|
|
||||||
// 隐藏 mapLayer 下的 main 节点
|
// 隐藏 mapLayer 下的 main 节点
|
||||||
let mainNode = smc.map.MapView.scene.mapLayer?.node.getChildByName("main");
|
smc.map.MapView.scene.mapLayer?.stopAnimations();
|
||||||
if (mainNode) {
|
|
||||||
mainNode.active = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 打开排行榜弹窗 */
|
/** 打开排行榜弹窗 */
|
||||||
@@ -106,12 +104,7 @@ export class MissionHomeComp extends CCComp {
|
|||||||
home_active(){
|
home_active(){
|
||||||
this.uodate_data()
|
this.uodate_data()
|
||||||
this.node.active=true
|
this.node.active=true
|
||||||
|
smc.map.MapView.scene.mapLayer?.playAnimations();
|
||||||
// 重新显示 mapLayer 下的 main 节点
|
|
||||||
let mainNode = smc.map.MapView.scene.mapLayer?.node.getChildByName("main");
|
|
||||||
if (mainNode) {
|
|
||||||
mainNode.active = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 更新主页显示数据(预留) */
|
/** 更新主页显示数据(预留) */
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
*
|
*
|
||||||
* @author 落日故人 QQ 583051842
|
* @author 落日故人 QQ 583051842
|
||||||
*/
|
*/
|
||||||
import { Component, Layers, Node, Sprite, SpriteFrame, Texture2D, UITransform, Vec3, _decorator } from 'cc';
|
import { Animation, Component, Layers, Node, Sprite, SpriteFrame, Texture2D, UITransform, Vec3, _decorator } from 'cc';
|
||||||
import { oops } from '../../../../../../../extensions/oops-plugin-framework/assets/core/Oops';
|
import { oops } from '../../../../../../../extensions/oops-plugin-framework/assets/core/Oops';
|
||||||
import { LayerUtil } from '../../../../../../../extensions/oops-plugin-framework/assets/core/utils/LayerUtil';
|
import { LayerUtil } from '../../../../../../../extensions/oops-plugin-framework/assets/core/utils/LayerUtil';
|
||||||
import { smc } from '../../../../common/SingletonModuleComp';
|
import { smc } from '../../../../common/SingletonModuleComp';
|
||||||
@@ -80,6 +80,25 @@ export default class MapLayer extends Component {
|
|||||||
if (this.bgImg) {
|
if (this.bgImg) {
|
||||||
return this.bgImg.getComponent(UITransform)!.height;
|
return this.bgImg.getComponent(UITransform)!.height;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private get animations(): Animation[] {
|
||||||
|
return [this.bg_anm, this.bg_anm1, this.bg_anm2, this.bg_anm3, this.bg_anm4].filter((a): a is Animation => a !== null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public playAnimations(name?: string): void {
|
||||||
|
this.animations.forEach(a => name ? a.play(name) : a.play());
|
||||||
|
}
|
||||||
|
|
||||||
|
public stopAnimations(): void {
|
||||||
|
this.animations.forEach(a => a.stop());
|
||||||
|
}
|
||||||
|
|
||||||
|
public pauseAnimations(): void {
|
||||||
|
this.animations.forEach(a => a.pause());
|
||||||
|
}
|
||||||
|
|
||||||
|
public resumeAnimations(): void {
|
||||||
|
this.animations.forEach(a => a.resume());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user