Exemplo n.º 1
0
    public static byte[] LoadFile(string file)
    {
        byte[] nbytes = null;
        if (AssetsMgr.A.useLuaAssetBundle)
        {
            string assetbundleName = file.StartsWith("config") ? "lua/config" : "lua/script";
            string assetName       = file.Replace('/', '%');
            var    txtAsset        = AssetsMgr.A.Load <TextAsset>(assetbundleName + "/" + assetName, false);
            if (txtAsset == null)
            {
                return(null);
            }

            nbytes = txtAsset.bytes;
            CLZF2.Decrypt(nbytes, nbytes.Length);
            nbytes = CLZF2.DllDecompress(nbytes);
        }
        else
        {
            if (!file.EndsWith(".lua"))
            {
                file = file + ".lua";
            }
            var luaPath = GetFilePath(file);
            if (!File.Exists(luaPath))
            {
                return(null);
            }

            nbytes = File.ReadAllBytes(luaPath);
        }

        if (nbytes[0] == 0xEF && nbytes[1] == 0xBB && nbytes[2] == 0xBF)
        {
            // 去掉BOM头
            System.Array.Copy(nbytes, 3, nbytes, 0, nbytes.Length - 3);
        }

        return(nbytes);
    }