36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import ScreenResize from "../ScreenResize";
|
|
import { UIManager } from "../UIManager";
|
|
|
|
const { ccclass, property } = cc._decorator;
|
|
@ccclass("SwitchImgSource")
|
|
export class SwitchImgSource {
|
|
@property({ type: cc.Node })
|
|
public Sprite: cc.Sprite = null;
|
|
@property({ type: cc.SpriteFrame/*, visible: function (this: ImageGroup) { return this.Reset; } */ })
|
|
public SourceImg: cc.SpriteFrame[] = [];
|
|
|
|
public SetImg(obj: cc.Sprite, switchObj: cc.SpriteFrame): void {
|
|
if (obj == null || switchObj == null) {
|
|
return;
|
|
}
|
|
obj.getComponent(cc.Sprite).spriteFrame = switchObj;
|
|
}
|
|
}
|
|
|
|
@ccclass
|
|
export default class SwitchImgGroupExtra extends cc.Component {
|
|
@property({ displayName: "換UI群組", type: SwitchImgSource })
|
|
public ImgGroups: SwitchImgSource[] = [];
|
|
public Run(): void {
|
|
if (this.ImgGroups != null && this.ImgGroups.length) {
|
|
for (let group of this.ImgGroups) {
|
|
group.SetImg(group.Sprite, group.SourceImg[ScreenResize.IsPortrait]);
|
|
}
|
|
}
|
|
}
|
|
onLoad() {
|
|
UIManager.DireEvent.AddCallback(this.Run, this);
|
|
this.Run();
|
|
}
|
|
}
|