zoukankan      html  css  js  c++  java
  • CocosCreator循环引用Bug

    Level.ts

    import Enemy1Character from "./Enemy1Character";
    
    const{ccclass,property}=cc._decorator;
    
    @ccclass
    export default class Level extends cc.Component{
    	private _enemy1Prefab:cc.Node;
    	
    	protected onLoad():void{
    		let inst=cc.instantiate(this._enemy1Prefab);
    		let enemy1Character=inst.getComponent(Enemy1Character);
    	}
    	
    }
    

    BaseEnemyCharacter.ts

    import Level from "./Level";
    const{ccclass,property}=cc._decorator;
    
    @ccclass
    export default abstract class BaseEnemyCharacter extends cc.Component{
    	//@property({type:Level,visible:true}) //会导致转换后的js生成require("./Level")出现循环引用错误:load script [./Enemy1Character] failed : TypeError: Object prototype may only be an Object or null: undefined
    	protected _level:Level=null;
    	
    	protected test(val:Level):void{
    		this._level=this.node.parent.getComponent(Level); //会导致转换后的js生成require("./Level")出现循环引用错误:load script [./Enemy1Character] failed : TypeError: Object prototype may only be an Object or null: undefined
    	}
    	
    }
    

    Enemy1Character.ts

    import BaseEnemyCharacter from "./BaseEnemyCharacter";
    
    const{ccclass,property}=cc._decorator;
    
    @ccclass
    export default class Enemy1Character extends BaseEnemyCharacter{
        
    }
    

    Enemy1Character 不继承 BaseEnemyCharacter 时

    import Level from "./Level";
    
    const{ccclass,property}=cc._decorator;
    
    @ccclass
    export default class Enemy1Character extends cc.Component{
        @property({type:Level,visible:true}) //无法序列化显示(循环引用导致)
    	protected _level:Level=null;
    	
    	protected test(val:Level):void{
    		this._level=this.node.parent.getComponent(Level);//不继承可以通过编译
    	}
    }
    
  • 相关阅读:
    CF896C Willem, Chtholly and Seniorious 珂朵莉树
    LG2495 「SDOI2011」消耗战 虚树
    20191102 「HZOJ NOIP2019 Round #12」20191102模拟
    LG1345 「USACO5.4」Telecowmunication 最小割
    LG1344 「USACO4.4」Pollutant Control 最小割
    POJ1741 Tree 点分治
    [BZOJ2143]飞飞侠 并查集优化最短路
    [NOI.AC#41]最短路 线性基
    [NOI.AC#40]Erlang
    [BZOJ2238]Mst 最小生成树+树链剖分/并查集
  • 原文地址:https://www.cnblogs.com/kingBook/p/13568077.html
Copyright © 2011-2022 走看看