Cocos Creator 3.8.5 社区版公测贴 【已发布】

给你稍微调整了一下代码。保证顺序即可。

import { _decorator, Component, instantiate, Node, Prefab, resources, Sprite, SpriteFrame } from 'cc';
import mapInfo from './Map1';
const { ccclass, property } = _decorator;

@ccclass('MapManager')
export class MapManager extends Component {
    @property(Prefab) prefabBlock:Prefab;
    @property(Prefab) prefabRigid:Prefab;

    private _loadedMapBlock: Node[][] = [];
    private _loadedCount = 0;
    private _totoalCount = 0;

    start() {
        this._loadedMapBlock.length = mapInfo.length;
        mapInfo.forEach((item,index) => {  //根据json生成瓦片地图,每一个元素为地图每一列
            const column = this._loadedMapBlock[index] = [];
            mapInfo[index].forEach((data,index) => {
                ++this._totoalCount;
                resources.load(data.src, SpriteFrame, (err, spriteFrame)=> {
                    ++this._loadedCount;
                    if(err) {
                        console.log(err);
                    }

                    let node: Node;

                    if(data.type == 'way') {
                        let te = instantiate(this.prefabBlock)
                        te.getComponent(Sprite).spriteFrame = spriteFrame
                        node = te;
                        // this.node.addChild(te);
                    }else {
                        let rigid = instantiate(this.prefabRigid)
                        rigid.getComponent(Sprite).spriteFrame = spriteFrame
                        node = rigid;
                        // this.node.addChild(rigid);
                    }

                    column[index] = node;
                    if (this._loadedCount == this._totoalCount) {
                        this.onAllBlockLoaded();
                    }
                })
            })
        })
    }

    private onAllBlockLoaded() {
        this._loadedMapBlock.forEach((column, x) => {
            column.forEach((node, y) => {
                this.node.addChild(node);
            })
        })
    }

    update(deltaTime: number) {
        
    }
}



1赞

我勒个豆,什么引擎组给开发者改游戏bug

4赞

大佬我也有个问题,之前在2.4.x里用属性装饰器,能在里面的set里做一些处理(比如触发相关的事件),但是在3.8的时候这个属性装饰器就不能用了,我在node的环境下也试过装饰器能正常使用,想问一下这个是什么原因,现在用3.8写不能用这个属性装饰器就是有点麻烦

function emit(eventEnum: string) {
    return function (target: any, propertyKey: any) {
        const getter = function () {
            return this["_" + propertyKey]
        };
        const setter = function (newValue: any) {
            this["_" + propertyKey] = newValue
            console.log("setter: " + propertyKey + " = " + newValue);
            EventManage.emit(eventEnum)
        };
        Object.defineProperty(target, propertyKey, {
            get: getter,
            set: setter,
            enumerable: true,
            configurable: true,
        });
    }
}

麻烦你了demo在上面的回复中

热更新可以直接用


3.8.5有这个bug请帮忙看看

KunpoCreator3.8.zip (453.5 KB) @dumganhar 大佬关于上边提到的问题,是哪里的问题能帮忙给看看吗,附件中是我的demo

现在打开项目的时候,会去加载kunpo-fgui插件,插件中用到了项目中名称为kunpocc的npm包,import时报警告

在另一个帖子中也有描述信息

好的 谢谢

数值默认步长能设置成0么,每一次点击手抖一下就数值就会变化,好烦啊

文档中的方法第一个传的方法名,但是在下面实例中第一个传的是布尔值,麻烦修正下谁对谁错

图片

这玩意我试过,不好用,好像是有线程问题,多调用几次就崩了

function emit(eventEnum: string): any {
    return function (target: any, propertyKey: any, descriptor: PropertyDescriptor): PropertyDescriptor {
        const getter = function () {
            console.log("getter: " + propertyKey);
            return this["_" + propertyKey]
        };
        const setter = function (newValue: any) {
            this["_" + propertyKey] = newValue
            console.log("setter: " + propertyKey + " = " + newValue);
            EventManage.emit(eventEnum)
        };
        // Object.defineProperty(target, propertyKey, {
        //     get: getter,
        //     set: setter,
        //     enumerable: true,
        //     configurable: true,
        // });

        if ('initializer' in descriptor) {
            target["_" + propertyKey] = (descriptor as any).initializer();
        }

        delete (descriptor as any).initializer;
        delete descriptor.writable;//

        return Object.assign(descriptor, { get: getter, set: setter });
    }
}

这样试试。

但这有个问题:就是 initializer 初始化后的值被作用在原型上,而不是对象的属性上。
目前受限于 babel 的实现。具体可以看这个帖子的讨论:

1赞

感谢反馈,有同学在跟进中。有进展会同步。

辛苦~
今晚又尝试了下,在项目的ts脚本中通过给全局对象添加属性的方式
globalThis[“abc”] = {a:1, b:2, c:3}

在插件的scene.ts中是可以正常取到数据的

再同步一下信息

我单独写了一个项目中的脚本,用于获取我注册过的信息

在插件中通过下图中的这种方式能正常取到我想要的数据

这个是取到的信息

只是这种方式会在项目中多一个脚本文件,并不能集成到npm包中

感谢大佬,新年快乐啊,这样可以了,是因为在3.x引擎修改了装饰器的编译方式吗,2.x对于装饰器的编译是tsc可以用Object.defineProperty修改而不用返回值,3.x使用babel必须返回一个PropertyDescriptor或者其他预期的值,才能处理属性的行为,我理解是这样的

好的,我确认下

多调用几次会奔溃,你是怎么调用的?方便提供demo看看么?

嗯,2.x 是用 tsc,3.x 改用 babel 后导致的差异。

1赞