Пример #1
0
        //////////////////////////////////////////////////////////////////////////////////////////////

        public byte[] getEncryptBytes(byte[] bytes, string fn)
        {
#if UNITY_EDITOR
#else
            // 开关检测
            if (_luaFileCodes != null && _luaFileCodes["_CHECK"].ToString().Equals("1"))
            {
                string fileName = fn.Substring(0, fn.Length - 4);
                if (_luaFileCodes[fileName] != null)
                {
                    string md5  = _luaFileCodes[fileName].ToString();
                    string cMD5 = TextUtils.MD5(bytes);
                    // MD5检测
                    if (!cMD5.Equals(md5))
                    {
                        //LogSys.LogError(fn + "->" + cMD5 + ", reload:" + hotScriptUrl() + fn);
                        WWW www = new WWW(hotScriptUrl() + fn);
                        while (!www.isDone)
                        {
                        }
                        ;
                        // 向FTP获取最新文件
                        bytes = www.bytes;

                        /* 这里注释掉,就不再覆盖本地文件,而是下载最新的脚本,直接覆盖内存
                         * string streamAsset = Application.streamingAssetsPath;
                         * string plat_name = IPath.getPlatformName();
                         * string luaFilePath = streamAsset + "/" + plat_name + "/" + fn;
                         * string direName = Path.GetDirectoryName(luaFilePath);
                         * if (!System.IO.Directory.Exists(direName))                       {
                         * System.IO.Directory.CreateDirectory(direName);
                         * }
                         * // 覆盖本地文件
                         * File.WriteAllBytes(luaFilePath, bytes);*/
                    }
                    else
                    {
                        //LogSys.LogError(fn + "->match");
                    }
                }
            }
#endif
            byte[] text_byte = bytes;
            if (UtilTools.ArrayHeadIsWoDong(bytes))
            {
                CMyEncryptFile _encrypte = new CMyEncryptFile();
                text_byte = _encrypte.Decrypt(bytes, bytes.Length);
            }
            return(text_byte);
        }
Пример #2
0
    /// <summary>
    /// 载入xml配置
    /// </summary>
    public override void LoadXML()
    {
        string xmlPath = _configPath + _fileName;

//         Object assets = AssetManager.getInstance().loadXML(xmlPath);//同步加载XML
//         if (assets != null) {
//             ParseXML(assets.ToString());
//             LogSys.Log("load config success :" + xmlPath);
//         }
        //if (AssetManager.getInstance().IsFirstUseStreamingAssets)
        if (AssetManager.getInstance().IsStreamingAssets(xmlPath))
        {
            xmlPath = UtilTools.PathCheck(xmlPath);
            AssetBundleLoadTask task = new AssetBundleLoadTask(xmlPath, null);
            task.EventFinished += new task.TaskBase.FinishedHandler(delegate(bool manual, TaskBase currentTask)
            {
                TextAsset assetObj = ((AssetBundleLoadTask)currentTask).getTargetAsset() as TextAsset;
                if (assetObj != null)
                {
                    byte[] text_byte = assetObj.bytes;
                    if (UtilTools.ArrayHeadIsWoDong(assetObj.bytes))
                    {
                        CMyEncryptFile _encrypte = new CMyEncryptFile();
                        text_byte = _encrypte.Decrypt(assetObj.bytes, assetObj.bytes.Length);
                    }
                    ParseXML(text_byte);
                    //LogSys.Log("load config success :" + xmlPath);
                }
                else
                {
                    LogSys.LogError("load config failed:" + xmlPath);
                }
                _bLoadedXML = true;
            });
        }
        else
        {
            AssetLoadTask task = new AssetLoadTask(xmlPath, null);
            task.EventFinished += new task.TaskBase.FinishedHandler(delegate(bool manual, TaskBase currentTask)
            {
                TextAsset assetObj = ((AssetLoadTask)currentTask).getTargetAsset() as TextAsset;
                if (assetObj != null)
                {
                    byte[] text_byte = assetObj.bytes;
                    if (UtilTools.ArrayHeadIsWoDong(assetObj.bytes))
                    {
                        CMyEncryptFile _encrypte = new CMyEncryptFile();
                        text_byte = _encrypte.Decrypt(assetObj.bytes, assetObj.bytes.Length);
                    }
                    float start_time = Time.realtimeSinceStartup;
                    ParseXML(text_byte);
                    //Utils.LogSys.Log(string.Format("{0:0.00}", Time.realtimeSinceStartup - start_time) + " parse :" + currentTask._taskName);
                    //LogSys.Log("load config success :" + xmlPath);
                }
                else
                {
                    LogSys.LogError("load config failed:" + xmlPath);
                }
                _bLoadedXML = true;
            });
        }
    }