调用扩展方法

ExtensionMethod.lua.txt

  1. local obj = CS.UnityEngine.Object.FindObjectOfType(typeof(CS.shenjun.ExtensionMethod))
  2. obj:ShowInfo()

ExtensionMethod.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 class ExtensionMethod : MonoBehaviour {
  11. void Start () {
  12. LuaEnv luaEnv = new LuaEnv();
  13. luaEnv.DoString("require 'ExtensionMethod'");
  14. luaEnv.Dispose();
  15. }
  16. void Update () {
  17. }
  18. }
  19. [LuaCallCSharp]
  20. public static class ExtensionClass
  21. {
  22. public static void ShowInfo(this ExtensionMethod self)
  23. {
  24. Debug.Log(self.gameObject.name);
  25. }
  26. }
  27. }

?