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);//不继承可以通过编译
    	}
    }
    
  • 相关阅读:
    NYOJ 625 笨蛋的难题(二)
    NYOJ 102 次方求模
    ZJU Least Common Multiple
    ZJUOJ 1073 Round and Round We Go
    NYOJ 709 异形卵
    HDU 1279 验证角谷猜想
    BNUOJ 1015 信息战(一)——加密程序
    HDU 1202 The calculation of GPA
    "蓝桥杯“基础练习:字母图形
    "蓝桥杯“基础练习:数列特征
  • 原文地址:https://www.cnblogs.com/kingBook/p/13568077.html
Copyright © 2011-2022 走看看