cocos 2.4.2 属性隐藏与序列化

cocos 2.4.2 属性隐藏与序列化

//visible属性 默认true 可见 设置为false则不可见
@property({ type: cc.Node, displayName: "选择目标", visible: true})
target: cc.Node = undefined;

//使用一个布尔控制过度图是否显示 默认=false 不显示在编辑器中,设置为true时,过度图节点将显示
@property({ displayName: "使用过度图", visible: false })
use_Img_Load = false;

@property({ type: cc.Node, displayName: "过度图", visible() { return this.use_Img_Load; } })
Img_Load: cc.Node = undefined;

//这里的用法借鉴了博主 kingBook928

关于序列化

1:官方代码

export function property(
options?: {
 type?: any; 
 url?: typeof cc.RawAsset; 
 visible?: boolean|(() => boolean);
 displayName?: string; 
 tooltip?: string; 
 multiline?: boolean; 
 readonly?: boolean; 
 min?: number; 
 max?: number; 
 step?: number; 
 range?: number[]; 
 slide?: boolean; 
 serializable?: boolean; 
 formerlySerializedAs?: string; 
 editorOnly?: boolean; 
 override?: boolean; 
 animatable?: boolean
 } | any[]|Function|cc.ValueType|number|string|boolean): Function;
export function property(_target: Object, _key: any, _desc?: any): void;    

2:设置意义
multiline: 换行
type: 类型
visible: 是否显示
url :cc.RawAsset资源类型
displayName: 面板显示的名字
tooltip :未知
multiline: 是否换行
readonly: 是否只读(锁定)
Function:方法

3:示例:
序列化枚举:

enum Arrangement //排序枚举
{
    Horizontal = 1, //横排
    Vertical = 2, //竖排
}
@property({type :cc.Enum(Arrangement),displayName:"排序枚举"})
private arrangement:Arrangement = Arrangement.Horizontal;

序列化数组:

@property({type:[cc.AudioClip]})
audioClips:cc.AudioClip[] = [];

序列化CC.RawAsset

@property({url:cc.Texture2D})
texture:cc.Texture2D = null;
或者
@property(cc.Texture2D)
texture:cc.Texture2D = null;

序列化滑动条

 @property({range:[1,200],slide:true})//min:0,max:100,
 nun:number= 0;
 min,max会对 number数值进行限制

一般我们通常都是使用简便的用法如

@property(cc.SpriteAtlas)
spriteAtlas:cc.SpriteAtlas = null;
@property(cc.Node)
item:cc.Node = null;

//这里的用法借鉴了博主 HHGameDev

官方文档: 官方属性参考指南

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值