TestCustomLoader.cs

  1. using UnityEngine;
  2. using System.IO;
  3. using LuaInterface;
  4. //use menu Lua->Copy lua files to Resources. 之后才能发布到手机
  5. public class TestCustomLoader : LuaClient
  6. {
  7. string tips = "Test custom loader";
  8. protected override LuaFileUtils InitLoader()
  9. {
  10. return new LuaResLoader();
  11. }
  12. protected override void CallMain()
  13. {
  14. LuaFunction func = luaState.GetFunction("Test");
  15. func.Call();
  16. func.Dispose();
  17. }
  18. protected override void StartMain()
  19. {
  20. luaState.DoFile("TestLoader.lua");
  21. CallMain();
  22. }
  23. new void Awake()
  24. {
  25. #if UNITY_5
  26. Application.logMessageReceived += Logger;
  27. #else
  28. Application.RegisterLogCallback(Logger);
  29. #endif
  30. base.Awake();
  31. }
  32. new void OnApplicationQuit()
  33. {
  34. base.OnApplicationQuit();
  35. #if UNITY_5
  36. Application.logMessageReceived -= Logger;
  37. #else
  38. Application.RegisterLogCallback(null);
  39. #endif
  40. }
  41. void Logger(string msg, string stackTrace, LogType type)
  42. {
  43. tips += msg;
  44. tips += "\r\n";
  45. }
  46. void OnGUI()
  47. {
  48. GUI.Label(new Rect(Screen.width / 2 - 200, Screen.height / 2 - 200, 400, 400), tips);
  49. }
  50. }

TestLoader.lua.bytes

  1. print("This is a script from a utf8 file")
  2. print("tolua: 你好! こんにちは! 안녕하세요!")
  3. function Test()
  4. print("this is lua file load by Resource.Load")
  5. end

?