找回密码
 立即注册
查看: 1733|回复: 10

[简易教程] unity通过字符串调用类中的函数

[复制链接]
发表于 2018-9-7 16:20 | 显示全部楼层 |阅读模式
[code=csharp]using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System;
using UnityEngine;

public class MoveTest : MonoBehaviour
{
    private Easer easer;

    // Use this for initialization
    void Start()
    {
        string str = "FFF";
        Type type = Type.GetType (str);
        MethodInfo meth = type.GetMethod ("pop");
        var obj = type.Assembly.CreateInstance (str);
        object[] param=new object[2]{1,2};
        Vector3 ss=(Vector3)meth.Invoke (obj,param);
        Debug.Log("ss:"+ss);
    }

    // Update is called once per frame
    void Update()
    {
    }
}
public class FFF{

    public void ttt(){

    }
    public Vector3 pop(float p1,float p2){
        Debug.Log (777);
        Debug.Log ("p1:"+p1);
        Debug.Log ("p2:"+p2);
        return new Vector3(0,0,0);
    }

}[/code]
发表于 2018-9-17 12:47 | 显示全部楼层
楼主是超人
发表于 2018-9-17 13:02 | 显示全部楼层
好帖就是要顶
发表于 2018-9-17 12:56 | 显示全部楼层
真心顶
发表于 2018-9-17 13:08 | 显示全部楼层
不错不错
发表于 2018-9-17 12:50 | 显示全部楼层
LZ真是人才
发表于 2019-2-5 07:26 | 显示全部楼层
很不错
发表于 2019-2-5 07:34 | 显示全部楼层
顶顶多好
发表于 2019-2-5 07:00 | 显示全部楼层
真心顶
发表于 2019-2-5 07:21 | 显示全部楼层
说的非常好
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-6-1 09:49 , Processed in 0.121968 second(s), 26 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表