public T GetComponent T () support in lua - sonygod/luaxe-nlua GitHub Wiki

testfile.hx

var a =	 Luanet.ctype(Transform);


current.getTypedComponent(Transform).localPosition= new Vector3(10, 10, 0);

var list =	current.getComponentsInChildrenOfType(Transform);

  untyped  oo = untyped(list.GetEnumerator());


while (untyped(oo.MoveNext())) {

  trace(untyped(oo.Current.name));

}

it's base on Luanet.ctype,see the source:

 public static function getTypedComponent<T>(c:Component, type:Class<T>):T {
          return cast c.GetComponent(untyped(Luanet.ctype(type)));
  }

  public static function getComponentsInChildrenOfType<T>(c:Component, type:Class<T>) {
    return cast (c.GetComponentsInChildren(untyped(Luanet.ctype(type))));
  }

and the lua file

function exec()

Main_Main = {};
___inherit(Main_Main, Object);
Main_Main.__name__ = "Main_Main";
Main_Main.__index = Main_Main;
	
	function Main_Main.new()
		local self = setmetatable({ }, Main_Main)
		SetMain(self)
		return self
	end
	
	function Main_Main:super()
		SetMain(self)
	end
	
	function Main_Main.main()
		Main_Main.mMain = Main_Main.new()
	end
	
	function Main_Main:Awake()
		Debug.Log("中文支持")
		local a = luanet.ctype(Transform)
		unityHelper_TypeCheck_TypeCheck.getTypedComponent(self.current, Transform).localPosition = Vector3(10, 10, 0)
		local list = unityHelper_TypeCheck_TypeCheck.getComponentsInChildrenOfType(self.current, Transform)
		oo = list:GetEnumerator()
		while (oo:MoveNext()) do
			Debug.Log(oo.Current.name)
		end
	end
	
	function Main_Main:Start()
		Debug.Log("删除开始")
	end
	
	function Main_Main:Update() end
	
	function Main_Main:OnDestroy()
		Debug.Log("lua 删除")
	end
	
	
Main_Main.__props__ = {};


Type_Type = {};
___inherit(Type_Type, Object);
Type_Type.__name__ = "Type_Type";
Type_Type.__index = Type_Type;
	
Type_Type.__props__ = {};


unityHelper_TypeCheck_TypeCheck = {};
___inherit(unityHelper_TypeCheck_TypeCheck, Object);
unityHelper_TypeCheck_TypeCheck.__name__ = "unityHelper.TypeCheck_TypeCheck";
unityHelper_TypeCheck_TypeCheck.__index = unityHelper_TypeCheck_TypeCheck;
	function unityHelper_TypeCheck_TypeCheck.getTypedComponent(c, type)
		return c:GetComponent(luanet.ctype(type));
	end
	function unityHelper_TypeCheck_TypeCheck.getComponentsInChildrenOfType(c, type)
		return c:GetComponentsInChildren(luanet.ctype(type));
	end
	
unityHelper_TypeCheck_TypeCheck.__props__ = {};


end

exec(); exec = nil
Main_Main.main();
⚠️ **GitHub.com Fallback** ⚠️