因為製作prefab的時候,
想要讓Editor介面裡的圖片也能隨著property不同而變換,
但是loadRes時都會報這個異常:
目前的代碼如下:
let buttonStyle = cc.Enum(
{
Green_BlackHalo: 0,
Green_GoldBorder: 1,
Transparent_GoldBorder: 2,
Transparent_GreenHalo: 3
});
cc.Class(
{
extends: cc.Component,
editor: { executeInEditMode: true },
properties:
{
String: { default:'' },
i18n: { default:'' },
Style: { type: buttonStyle, default: buttonStyle.Green_BlackHalo },
FontSize: { default:18 },
Icon: { type: cc.SpriteFrame, default:null },
},
onLoad: function ()
{
this.nodes =
{
Icon: this.node.getChildByName( '@Icon' ).getComponent( cc.Sprite ),
Label: this.node.getChildByName( '@Label' ).getComponent( cc.Label )
};
try { this.Render(); }
catch( ex ) { cc.log( '[@Button] Render Error: ' + ex ); }
},
Render ()
{
if( this.nodes.Label.fontSize !== this.FontSize ) this.nodes.Label.fontSize = this.FontSize;
if( this.Icon != null )
{
this.nodes.Icon.node.active = true;
this.nodes.Icon.spriteFrame = this.Icon;
}
else this.nodes.Icon.node.active = false;
if( this.Style != buttonStyle.Green_BlackHalo )
{
let name = buttonStyle[this.Style];
//這邊都會找不到
cc.loader.loadRes( 'images/ui/components/TextBoxes', cc.SpriteFrame, ( err, frames ) =>
{
for( let idx = 0; idx < frames.length; idx++ )
{
let f = frames[idx];
cc.log( 'frames: ' + f._name );
}
});
}
},
});
如果 CC_EDITOR下,無法使用 cc.loader.loadRes 來取得資源,我該如何設置這個圖片?
請高手指點一下,感謝