window.UtilsPrefabs = {

    init : function (parentNode) {
        this.parentNode = parentNode;
        return this;
    },
    getPrefabsName : function(){
        return this.prefabsName;
    },
    addPrefabs : function (prefabsName,parentNode,callback) {
        cc.loader.loadRes(prefabsName, function (err, texture) {
            var node = this.parentNode;

            if (parentNode!=null) {
                node = parentNode;
            }

            var prefab = cc.instantiate(texture);

            this.prefabsName = prefab.name;
            this.removePrefabs(node,this.prefabsName);


            if (node!=null) {
                node.addChild(prefab);
            }else{
                return;
            }

            if (callback != null) {
                callback(prefab);
            }
        }.bind(this));
    },
    removePrefabs : function (parentNode,prefabsName,success,fail) {

        var node = this.parentNode;

        if (parentNode!=null) {
            node = parentNode;
        }

        if (node!=null) {
            if (node.getChildByName(prefabsName) != null) {
                node.getChildByName(prefabsName).off(cc.Node.EventType.TOUCH_END);
                node.getChildByName(prefabsName).destroy();
                if (success != null) {
                    success();
                }
            }else{
                if (fail != null) {
                    fail();
                }
            }
        }

    },
    setOff : function(node){
        node.off(cc.Node.EventType.TOUCH_END);
    },
    setOn : function(node,callback){
        if (node != null) {
            node.on(cc.Node.EventType.TOUCH_END,callback);
        }else{
            console.log("当前被放进来的node节点没有可以点击的名字 请关注此段警告");
        }

        return this;
    },


    getNode: function (name, parent) {
        if (parent == null) {
            if (this.parentNode.getChildByName(name) == null) {
                // console.log("在",this.parentNode,"没有找到名字为"+name+"的node");
            }
            return this.parentNode.getChildByName(name);
        } else {
            if (parent.getChildByName(name) == null) {
                // console.log("在",parent,"没有找到名字为"+name+"的node");
            }
            return parent.getChildByName(name);
        }

    },
  
    loadResSpriteFrame : function(src,callback){
        cc.loader.loadRes(src,cc.SpriteFrame, function (err, texture) {
            if (callback!=null) {
                callback(texture);
            }
        }.bind(this));
    },




}