| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace SFramework
- {
- public static class SLuaEnv
- {
- private static XLua.LuaEnv _luaState = null;
- public static XLua.LuaEnv Instance
- {
- get
- {
- if (null == _luaState)
- {
- _luaState = new XLua.LuaEnv();
- _luaState.AddLoader(SLuaEnv.CustomLoader);
- _luaState.AddBuildin("rapidjson", XLua.LuaDLL.Lua.LoadRapidJson);
- _luaState.AddBuildin("lpeg", XLua.LuaDLL.Lua.LoadLpeg);
- _luaState.AddBuildin("pb", XLua.LuaDLL.Lua.LoadLuaProfobuf);
- _luaState.AddBuildin("ffi", XLua.LuaDLL.Lua.LoadFFI);
- }
- return _luaState;
- }
- private set
- {
- Debug.Assert(false, "Can't set the Instance");
- }
- }
- private static TextAsset GetTextAsset(string fullLuaScriptPath)
- {
- #if UNITY_EDITOR
- string resFinalPath = "Assets/" + SFrameworkDefR.ResourceDir + "/" + fullLuaScriptPath;
- TextAsset luaTextAssets = UnityEditor.AssetDatabase.LoadAssetAtPath(resFinalPath, typeof(UnityEngine.Object)) as TextAsset;
- #else
- TextAsset luaTextAssets = SFramework.SResourceManagerR.LoadResource(fullLuaScriptPath) as TextAsset;
- #endif
- return luaTextAssets;
- }
- private static byte[] CustomLoader(ref string luaScriptName)
- {
- //Debug.Log("CustomLoader Work Once. ---> " + luaScriptName);
- string fullLuaScriptPath = "LuaScripts/" + luaScriptName + ".txt";
- //Debug.Log("FullLuaScriptPath -> " + fullLuaScriptPath);
- //TextAsset luaTextAssets = SFramework.SResourceManagerR.LoadResource(fullLuaScriptPath) as TextAsset;
- TextAsset luaTextAssets = GetTextAsset(fullLuaScriptPath);
- //Debug.Log("luaTextAssets -> " + luaTextAssets.text);
- Debug.Log(string.Format(
- "SFramework.SLuaEnv.CustomLoader -> luaScriptName: {0} \nluaTextAssets: {2}",
- luaScriptName, fullLuaScriptPath, luaTextAssets.text
- ));
- return luaTextAssets.bytes;
- }
- }
- }
|