Unity通过字符串“class”调用此类class的方法

来源:互联网 发布:ruby windows 编辑:程序博客网 时间:2024/06/11 10:21

        string str = "FFF";
        Type t = Type.GetType (str);
        var obj = t.Assembly.CreateInstance (str);
        MethodInfo[] info = t.GetMethods ();
//        for(int i=0;i<info.Length;i++){
//            info [i].Invoke (obj,null);
//        }
        Debug.Log( info [1].Name);

        info [1].Invoke (obj,null);

        string s = "pop";
//        MethodInfo gg = new String (s);
//        gg.Invoke (obj,null);

        MethodInfo meth = t.GetMethod (s);
        meth.Invoke (obj,null);

//        System.Type typeinfo = this.GetType();
//        MethodInfo mth = typeinfo.GetMethod ("Start");
//        mth.Invoke (obj,null);



    }
}
public class FFF{

    public void ttt(){

    }
    public void pop(){
        Debug.Log (777);

    }

}
阅读全文
0 0