调用重载方法

OverloadMethod.lua.txt

  1. local overloadMethod = CS.UnityEngine.Object.FindObjectOfType(typeof(CS.shenjun.OverLoadMethod))
  2. --调用无参的方法
  3. overloadMethod:Func()
  4. --调用参数为int类型的方法
  5. overloadMethod:Func(10)
  6. --调用参数为string类型的方法
  7. overloadMethod:Func("shenjun")

OverloadMethod.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 OverLoadMethod : MonoBehaviour {
  11. void Start () {
  12. LuaEnv luaEnv = new LuaEnv();
  13. luaEnv.DoString("require 'OverloadMethod'");
  14. luaEnv.Dispose();
  15. }
  16. void Update () {
  17. }
  18. public void Func()
  19. {
  20. Debug.Log("Func NoParam");
  21. }
  22. public void Func(int num)
  23. {
  24. Debug.Log("Func int param :" + num);
  25. }
  26. public void Func(string name)
  27. {
  28. Debug.Log("Func string param :" + name);
  29. }
  30. }
  31. }

?