| 123456789101112131415161718192021222324252627282930313233343536 |
- import { _decorator, Component, Node, Size, UITransform } from 'cc';
- const { ccclass, property } = _decorator;
- @ccclass('Adaptation')
- export class Adaptation extends Component {
- @property(UITransform)
- targetNode:UITransform
- start() {
- let mySize = this.getComponent(UITransform).contentSize
- let tSize = this.targetNode.contentSize
- this.adaptationIcon(mySize,tSize)
- }
- protected onEnable(): void {
-
- }
- adaptationIcon(mySize: Size, tSize: Size) {
- let size = mySize
- //适配图片
- let iconSize = new Size()
- let raito = size.width / size.height
- let raito1 = tSize.width / tSize.height
- if (raito < raito1) {
- iconSize.height = tSize.height
- iconSize.width = tSize.height * raito
- } else {
- iconSize.width = tSize.width
- iconSize.height = tSize.width / raito
- }
- this.getComponent(UITransform).setContentSize(iconSize)
- }
- }
|