C#版本
public static Component AddComponent(GameObject go, string assembly, string classname)
{
var asmb = System.Reflection.Assembly.Load(assembly);
var t = asmb.GetType(assembly + "." + classname);
if(null != t)
return go.AddComponent(t);
else
return null;
}
lua版本
function AddComponent(go, classname)
local com = go:GetComponent(classname)
if com then return com end
local t = System.Type.GetType(classname)
if t then
return go:AddComponent(t)
end
return nil
end