Lua 反射获取和修改C#变量
print('------------------tolua自带反射测试----------------------')
require 'tolua.reflection'
tolua.loadassembly('Assembly-CSharp')
local bitor = bit.bor(0,1,2,4,8,16,32,64,256,512,1024,2048,4096,8192,16384,32768)
local t = typeof('BoTest2')
local obj = tolua.createinstance(t)
local func = tolua.getmethod(t, 'BoTest2_public_static_int')
print(func:Call())
func:Destroy()
func = nil
local func = tolua.getmethod(t, 'BoTest2_public_static_int_arg',typeof('System.Int32'))
print(func:Call(1))
func:Destroy()
func = nil
local func = tolua.getmethod(t, 'BoTest2_public_int')
print(func:Call(obj) )
func:Destroy()
func = nil
local func = tolua.getmethod(t, 'BoTest2_public_int_arg',typeof('System.Int32'))
print(func:Call(obj,2))
func:Destroy()
func = nil
local func = tolua.gettypemethod(t, 'BoTest2_static_int',bitor)
print(func:Call())
func:Destroy()
func = nil
local func = tolua.gettypemethod(t, 'BoTest2_int',bitor)
print(func:Call(obj))
func:Destroy()
func = nil
local field = tolua.getfield(t, 'public_int')
field:Set(obj, 5)
print(field:Get(obj))
field:Destroy()
local field = tolua.getfield(t, 'private_int',bitor)
field:Set(obj, 6)
print(field:Get(obj))
field:Destroy()
local property = tolua.getproperty(t, 'public_int_set_get')
property:Set(obj, 7, null)
print(property:Get(obj, null))
property:Destroy()
local property = tolua.getproperty(t, 'private_int_set_get',bitor)
property:Set(obj, 8, null)
print(property:Get(obj, null))
property:Destroy()
local t = typeof('TestEnumOut')
local t = typeof('BoTest2+TestEnumIn')
require 'tolua.reflection'
tolua.loadassembly('Common')
local t = typeof('rkt.Common.GlobalGame')
local field = tolua.getfield(t, 'isCanQuit')
field:Set(null, false)
field:Destroy()
require 'tolua.reflection'
tolua.loadassembly('Unity.TextMeshPro')
local bitor = bit.bor(0,1,2,4,8,16,32,64,256,512,1024,2048,4096,8192,16384,32768)
local t = typeof('TMPro.TMP_Text')
local field = tolua.getfield(t, 'defaultColor',bitor)
field:Set(null, '#18dcff')
print(field:Get(null))
field:Destroy()
点此跳转详细地址