美文网首页
Cocos 3.x property

Cocos 3.x property

作者: 合肥黑 | 来源:发表于2021-10-22 15:32 被阅读0次

    参考https://docs.cocos.com/creator/3.0/manual/zh/scripting/ccclass.html?h=property

    1.动态的visible属性
    enum ROAD_POINT_TYPE {
        NORMAL = 1,
        START,
        GREETING,
        GOODBYE,
        END,
        AI_START,
    }
    
    Enum(ROAD_POINT_TYPE);
    
    enum ROAD_MOVE_TYPE {
        LINE = 1,
        BEND,
    }
    
    Enum(ROAD_MOVE_TYPE);
    
    @ccclass("RoadPoint")
    export class RoadPoint extends Component {
        public static RoadPointType = ROAD_POINT_TYPE;
        public static RoadMoveType = ROAD_MOVE_TYPE;
    
        @property({
            type: ROAD_POINT_TYPE,
            displayOrder: 1,
        })
        type = ROAD_POINT_TYPE.NORMAL;
    
    @property({ displayOrder: 5, visible:  function (this: RoadPoint){
        return this.type === ROAD_POINT_TYPE.AI_START;
    }})
    delayTime = 0;
    

    注意这里的Enum(ROAD_POINT_TYPE);必须要有,否则报错
    displayOrder从0开始

    2.displayName tooltip
    @property({
        type:Prefab,
        displayName:"所有UI预制体",
            tooltip: "队员模型"
    })
    public Uiprefabs:Prefab[] =[];
    
    3.基本类型

    如果是bool类型,有警告,可以不写类型:

        @property({
            displayName: "是否清除数据"
        })
        public removedata = false;
    

    相关文章

      网友评论

          本文标题:Cocos 3.x property

          本文链接:https://www.haomeiwen.com/subject/hplrgltx.html