0

现在我正在使用 UIEventListener 添加一个点击器。当我将它写入一个文件时,它可以正常工作。像这样: UIEventListener.Get(popButton).onClick = showPop;

但是当我将它写入两个单独的文件时,它给了我 error.first 文件:

public class Adapter{
    var grid:GameObject;

    function addItems(data:List.<PrintItem>, prefab:GameObject, func:Function){
        for(var i:int=0;i<data.Count;i++){
            var gameObject:GameObject = NGUITools.AddChild(grid, prefab);
            UIEventListener.Get(gameObject).onClick = func;
        }
    }
}

第二个文件:

//I use the funtion like this
adapter.addItems(list, GO[0], hidePop);
//the hidePop is like this
var hidePop:Function = function(){
    switchPopMenu(false);
};

当我运行统一时给我错误

InvalidCastException: Cannot cast from source type to destination type.
Adapter.addItems (System.Collections.Generic.List`1 data,   
UnityEngine.GameObject prefab, ICallable func) (at
Assets/Scripts/yhj/Tools/Adapter.js:12)
4

1 回答 1

0

尝试使用EventDelegate.Add(obj.onClick, func);. 直接分配可能会导致某些问题。

于 2015-08-04T09:06:56.423 回答