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