SLuaEnv.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace SFramework
  5. {
  6. public static class SLuaEnv
  7. {
  8. private static XLua.LuaEnv _luaState = null;
  9. public static XLua.LuaEnv Instance
  10. {
  11. get
  12. {
  13. if (null == _luaState)
  14. {
  15. _luaState = new XLua.LuaEnv();
  16. _luaState.AddLoader(SLuaEnv.CustomLoader);
  17. }
  18. return _luaState;
  19. }
  20. private set
  21. {
  22. Debug.Assert(false, "Can't set the Instance");
  23. }
  24. }
  25. private static byte[] CustomLoader(ref string luaScriptName)
  26. {
  27. //Debug.Log("CustomLoader Work Once. ---> " + luaScriptName);
  28. string fullLuaScriptPath = "LuaScripts/" + luaScriptName + ".txt";
  29. //Debug.Log("FullLuaScriptPath -> " + fullLuaScriptPath);
  30. TextAsset luaTextAssets = SFramework.SResourceManager.LoadResource(fullLuaScriptPath) as TextAsset;
  31. //Debug.Log("luaTextAssets -> " + luaTextAssets.text);
  32. Debug.Log(string.Format(
  33. "SFramework.SLuaEnv.CustomLoader -> luaScriptName: {0} \nluaTextAssets: {2}",
  34. luaScriptName, fullLuaScriptPath, luaTextAssets.text
  35. ));
  36. return luaTextAssets.bytes;
  37. }
  38. }
  39. }