调用泛型方法

Generic.lua.txt

  1. local obj = CS.UnityEngine.Object.FindObjectOfType(typeof(CS.shenjun.Generic))
  2. local cam = obj:GetCamera()
  3. local cam1 = obj:GetComponent();
  4. if cam1 == cam then
  5. print("the same camera")
  6. end

Generic.cs

  1. /*
  2. * created by shenjun
  3. */
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. using XLua;
  8. namespace shenjun
  9. {
  10. public sealed class Generic : MonoBehaviour {
  11. void Start () {
  12. LuaEnv luaEnv = new LuaEnv();
  13. luaEnv.DoString("require 'Generic'");
  14. luaEnv.Dispose();
  15. }
  16. void Update () {
  17. }
  18. public Camera GetCamera()
  19. {
  20. return this.GetComponent<Camera>();
  21. }
  22. }
  23. [LuaCallCSharp]
  24. public static class GenericExtension
  25. {
  26. public static Camera GetComponent(this Generic self)
  27. {
  28. return self.GetComponent<Camera>();
  29. }
  30. }
  31. }

?