| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- 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);
- }
- 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;
- }
- }
- }
|