import { _decorator, Component, Node, Size, Sprite, SpriteFrame, UITransform, Vec2 } from 'cc'; import { Hall } from '../../hall/Hall'; import { ch } from 'db://assets/ch/ch'; const { ccclass, property } = _decorator; @ccclass('UI_Head_Icon') export class UI_Head_Icon extends Component { @property(Sprite) private head: Sprite; @property([SpriteFrame]) private default_head: SpriteFrame[] = []; start() { } update(deltaTime: number) { } show(uid: string, head: string | null): void { const rc = this.default_head[ch.util.getRandomInt(0, this.default_head.length - 1)]; Hall.getInstance().head_icon.showIcon(uid, head, this.head, rc).then((spf)=>{ if(spf != null) this.adaptationIcon(this.head, spf, new Size(55,55)); }); } adaptationIcon(icon: Sprite, spriteFrameIcon: SpriteFrame, tSize: Size) { if (spriteFrameIcon) { let size = spriteFrameIcon.originalSize //适配图片 let iconSize = new Size() let raito = size.width / size.height if (raito < 1) { iconSize.height = tSize.height iconSize.width = tSize.height * raito } else { iconSize.width = tSize.width iconSize.height = tSize.width / raito } icon.spriteFrame = spriteFrameIcon icon.getComponent(UITransform).setContentSize(iconSize) } } }