Hello all!
I take advantage of Cocos Creator model 3.8.6.
I’ve my very own IconView part in my challenge, it’s situated within the following path:
belongings/scripts/coreView/IconView.ts
I don’t know precisely beneath what situations, however generally the hyperlink to this part turns into invalid. I simply begin the sport and get an error that I’m making an attempt to name a operate on an object that isn’t assigned.
This doesn’t occur usually, however it’s nonetheless disagreeable. For instance, I’m working with some a part of the UI, inserting fully various things, assigning hyperlinks, saving the prefab (often I then shut the prefab), launching the scene and getting an error (though I didn’t contact the IconView hyperlinks manually). So far as I perceive, this solely occurs if I open the prefab. I don’t assume I’ve ever had hyperlinks get tousled like that in prefabs that I haven’t opened just lately. Afterwards, I’ve to open the prefab and assign the hyperlinks once more (within the inspector it reveals as if I didn’t set something, and never a lacking object).
To be trustworthy, I’m already uninterested in this. I observed this since model 3.8.3.
I’ve many elements in my challenge, however I solely acquired this error with three of my elements. Two of them are gone – solely IconView stays.
What’s unsuitable with him?
import { Shade, Element, Enum, Dimension, Sprite, SpriteFrame, UITransform, _decorator } from "cc";
const { ccclass, property } = _decorator;
export enum IconFillingMethod {
filling, // Could exit of space
becoming // Might be included within the space
}
Enum(IconFillingMethod);
@ccclass('IconView')
export class IconView extends Element {
@property({ kind: UITransform })
non-public areaUITransform: UITransform;
@property({ kind: UITransform })
non-public iconUITransform: UITransform;
@property({ kind: Sprite })
non-public icon: Sprite;
@property({ kind: IconFillingMethod })
non-public fillingMethod: IconFillingMethod = IconFillingMethod.becoming;
public SetIcon(sprite: SpriteFrame): void {
this.icon.spriteFrame = sprite;
this.UpdateSize();
}
public SetIconWithOriginalSize(sprite: SpriteFrame, scale: quantity = 1): void {
this.areaUITransform.setContentSize(sprite.rect.width * scale, sprite.rect.top * scale);
this.icon.spriteFrame = sprite;
this.UpdateSize();
}
public GetIcon(): SpriteFrame {
return this.icon.spriteFrame;
}
public GetIconSize(): Readonly {
return this.iconUITransform.contentSize;
}
public SetIconColor(colour: Readonly): void {
this.icon.colour = colour;
}
public GetIconColor(): Readonly {
return this.icon.colour;
}
public SetGrayscale(isGrayscale: boolean): void {
this.icon.grayscale = isGrayscale;
}
non-public UpdateSize(): void {
let areaWidth = this.areaUITransform.contentSize.width;
let areaHeight = this.areaUITransform.contentSize.top;
let originalSpriteWidth = this.icon.spriteFrame.rect.width;
let originalSpriteHeight = this.icon.spriteFrame.rect.top;
swap(this.fillingMethod) {
case IconFillingMethod.filling:
this.CalcProportionalRectFillingSize(areaWidth, areaHeight, originalSpriteWidth, originalSpriteHeight);
break;
case IconFillingMethod.becoming:
this.CalcProportionalRectFittingSize(areaWidth, areaHeight, originalSpriteWidth, originalSpriteHeight);
break;
}
}
non-public CalcProportionalRectFillingSize(fillableWidth: quantity, fillableHeight: quantity, spriteWidth: quantity, spriteHeight: quantity): void {
let width = 0;
let top = 0;
let aspectRatio = spriteWidth / spriteHeight;
width = fillableWidth;
top = width / aspectRatio;
if (top fillableHeight) {
top = fillableHeight;
width = top * aspectRatio;
}
this.iconUITransform.setContentSize(width, top);
}
}