示例#1
0
    /// <summary>
    /// 从 ali 云 获取热更新版本号
    /// </summary>
    /// <param name="onComplete"></param>
    public static void GetVersionUpdateControl(System.Action <int> onComplete)
    {
        MonoBehaviour   mono   = null;
        CoroutineResult result = new CoroutineResult();

        IEnumerator enumerator = result.WWWReConnect(Constants.UpdateVersionControlUrl, () =>
        {
            int InstantUpdate_UpdateVersionControlCode = 0;
            if (result._wwwResult != null && result._wwwResult.error == null)
            {
                int.TryParse(result._wwwResult.text, out InstantUpdate_UpdateVersionControlCode);
            }
            if (onComplete != null)
            {
                onComplete(InstantUpdate_UpdateVersionControlCode);
            }
        });

        if (Application.isPlaying)
        {
            mono = GetGameManager();
            mono.StartCoroutine(enumerator);
        }
        else
        {
            while (enumerator.MoveNext())
            {
                ;
            }
        }
    }
示例#2
0
    public IEnumerator WWWReconnect(string pUrl, string pName, WaitCoroutine done)
    {
        CoroutineResult tCorountineResult = new CoroutineResult();

        //Debug.Log(pUrl);
        yield return(tCorountineResult.WWWReConnect(pUrl));

        if (tCorountineResult.error != null)
        {
            yield return(StartCoroutine(PlatformGameDefine.playform.LoadConfByUser(pName)));

            //CallMethod("DoLoading",false);

            done.isDoneCoroutine = false;
            yield return(null);
        }

        done.isDoneCoroutine = true;
        done.DownWWW         = tCorountineResult._wwwResult;
    }
示例#3
0
    //private int m_CurReconnectCount;
    /* ------ Button Click ------ */
    IEnumerator DoChekcVersion()
    {
        UpdateSlider(LodaingStage.CheckVersion);
        mVersionCode = Mathf.Max(PlayerPrefs.GetInt("VersionCode", PlatformGameDefine.game.VersionCode), PlatformGameDefine.game.VersionCode);
        if (PlatformGameDefine.playform.VersionCode > 0 && mVersionCode >= PlatformGameDefine.playform.VersionCode)//不用更新, 这样做可以减少一次网络访问
        {
            StartCoroutine(DoLoading());
            yield break;
        }
        UnityEngine.Debug.Log("CK : ----------------------DoChekcVersion-------- name = " + 0);

        CoroutineResult coroutineResult = new CoroutineResult();

        //string test_version_url = "http://oss.aliyuncs.com/bak998899/test/version_All.txt";
        yield return(coroutineResult.WWWReConnect(PlatformGameDefine.game.ChekcVersionURL()));//test_version_url);//

        UnityEngine.Debug.Log("CK : ----------------------DoChekcVersion-------- coroutineResult.error = " + coroutineResult.error);
        if (coroutineResult.error != null)
        {
            StartCoroutine(DoLoading());
            yield break;
        }

        WWW www = coroutineResult._wwwResult; //HttpConnect.Instance.HttpRequestAli(PlatformGameDefine.game.ChekcVersionURL());

        if (Constants.isEditor)
        {
            UnityEngine.Debug.Log("CK : ------------------------------ www URL = " + www.url + ", txt = " + www.text);
        }

        //yield return www;
        HttpResult result = HttpConnect.Instance.BaseResult(www);

        if (HttpResult.ResultType.Sucess == result.resultType)
        {
            //JSONObject versionObj = (JSONObject)(result.resultObject);
            //mVersionCode = Mathf.Max (PlayerPrefs.GetInt ("VersionCode", PlatformGameDefine.game.VersionCode), PlatformGameDefine.game.VersionCode);
            //mNewVersionCode = int.Parse (versionObj["version_code"].str);
            JSONObject versionObj = (JSONObject)(result.resultObject);
            mNewVersionCode = 0;
            if (versionObj.IsAvailable() && versionObj["version_code"].IsAvailable() && !string.IsNullOrEmpty(versionObj["version_code"].str))
            {
                if (int.TryParse(versionObj["version_code"].str, out mNewVersionCode))
                {
                }
                else
                {
                    mNewVersionCode = 0;
                }
            }
            //Debug.Log("======1212======"+mNewVersionCode);
            UnityEngine.Debug.Log("CK : ------------------------------ mNewVersionCode = " + mNewVersionCode + ", mVersionCode = " + mVersionCode);

            if (mNewVersionCode > mVersionCode)
            {
                ShowUpdateView(versionObj);
            }
            else
            {
                if (System.IO.Directory.Exists(Constants.VersionUpdatePath))//不需要更新大版本,确保大版本文件(更新下载的)已删除
                {
                    System.IO.Directory.Delete(Constants.VersionUpdatePath, true);
                }

                StartCoroutine(DoLoading());
            }
        }
        else
        {
            StartCoroutine(DoLoading());
        }
    }
示例#4
0
    public static IEnumerator CompareConfig(string src, string des, List <string> gameModuleList, bool isUpdate, System.Action <JSONObject, JSONObject, string> onComplete)
    {
        yield return(0);

        string srcConfigFile = src + Constants.Config_File;
        string desConfigFile = des + Constants.Config_File;

        string error = null;

        JSONObject srcJson = null;
        JSONObject desJson = null;

        if ((isUpdate || Application.platform == RuntimePlatform.Android) && src != Constants.DownloadPath)
        {//从服务端更新 或者 是Android 平台,都需要用www
            #region 无超时判断, 不用了, 使用WWWReConnect代替
            //            WWW www = new WWW(srcConfigFile);
            //            yield return www;

            //            if (www.error != null)
            //            {//访问后台 或 Android下的 配置文件出错
            //#if UNITY_EDITOR
            //                error = "访问源目录下的配置文件出错@" + srcConfigFile + " : " + www.error;
            //#else
            //                error = "访问源目录下的配置文件出错@" + Constants.Config_File + " : " + www.error;
            //#endif
            //            }
            //            else
            //            {
            //                srcJson = new JSONObject(www.text);
            //            }
            #endregion 无超时判断, 不用了, 使用WWWReConnect代替


            CoroutineResult result = new CoroutineResult();
            yield return(result.WWWReConnect(srcConfigFile));

            if (result._wwwResult != null && result._wwwResult.error == null)
            {
                srcJson = new JSONObject(result._wwwResult.text);
                if (!srcJson.IsAvailable())
                {
                    error = "访问源目录下的配置文件出错@" + srcConfigFile + " : json 数据异常";
                }
            }
            else
            {
#if UNITY_EDITOR
                error = "访问源目录下的配置文件出错@" + srcConfigFile + " : " + result.error;
#else
                error = "访问源目录下的配置文件出错@" + Constants.Config_File + " : " + result.error;
#endif
            }
        }
        else
        {//从StreamingAssets目录更新 并且不是Android 平台
            if (File.Exists(srcConfigFile))
            {
                srcJson = new JSONObject(File.ReadAllText(srcConfigFile));
            }
            else
#if UNITY_EDITOR
            { error = "访问源目录下的配置文件出错@" + srcConfigFile; }
#else
            { error = "访问源目录下的配置文件出错@" + Constants.Config_File; }
#endif
        }

        if (error != null)
        {
            if (onComplete != null)
            {
                onComplete(null, null, error);
            }
            yield break;
        }

        ////对配置文件的版本信息进行判断//采用更新地址与大版本号相关的方式,不比较版本号,直接从对应的版本号地址更新
        //if (isUpdate)
        //{//去后台更新资源的时候,大版本必须相同才能更新//Extract的配置文件没有版本号信息
        //    if (srcJson["version"].IsAvailable())
        //    {

        //        if (string.Compare(srcJson["version"].str, Application.version) != 0)
        //        {
        //            error = "debug_only:发现新版本,请下载最新版本";//这里的错误不在界面显示
        //        }
        //    }
        //    else
        //    {
        //        error = "debug_only:配置文件出错,缺少版本信息";//如果配置文件没有版本信息,就不进行更新
        //    }

        //    if (error != null)
        //    {
        //        if (onComplete != null) onComplete(null, error);
        //        yield break;
        //    }
        //}

        if (File.Exists(desConfigFile))//在输出目录下存在 配置文件
        {
            desJson = new JSONObject(File.ReadAllText(desConfigFile));
        }
        else//在输出目录下不存在配置文件
        {
            desJson = null;
        }

        //if(srcJson != null) srcJson.RemoveField("version");
        //if(desJson != null) desJson.RemoveField("version");
        double srcVersionTime = srcJson[Constants.InstantUpdate_VersionTime].n;
        double desVersionTime = desJson.IsAvailable() && desJson[Constants.InstantUpdate_VersionTime].IsAvailable() ? desJson[Constants.InstantUpdate_VersionTime].n : 0;
        if (des == Constants.DownloadPath) //Constants.DownloadPath地址进行判断
        {                                  //热跟新下载的时候对版本时间进行判断, 如果不需要更新则不更新. 这样可以保证只更新最新版本,避免云端多个更新地址版本不一致,导致恶性循环下载问题.
            if (srcVersionTime < desVersionTime)
            {
                error = "源目录下的版本时间比目标目录下的版本时间小. 不进行更新";
                if (onComplete != null)
                {
                    onComplete(null, null, error);
                }
                yield break;
            }

            if (File.Exists(Constants.ClickDownload_Config_download))
            {
                File.Delete(Constants.ClickDownload_Config_download);
            }
            string clickDownload_Config_dir = Path.GetDirectoryName(Constants.ClickDownload_Config_download);
            if (!Directory.Exists(clickDownload_Config_dir))
            {
                Directory.CreateDirectory(clickDownload_Config_dir);
            }
            File.WriteAllText(Constants.ClickDownload_Config_download, srcJson.ToString());//把静默热更新的版本配置文件保存到  Constants.ClickDownload_Config_download 中
        }
        //InstantUpdate_VersionTime = System.Convert.ToInt64(srcVersionTime);
        JSONObject srcReservedConfig = new JSONObject();                                                       //预留 时间和code
        srcReservedConfig[Constants.InstantUpdate_VersionTime] = srcJson[Constants.InstantUpdate_VersionTime]; //预留versionTime
        srcReservedConfig[Constants.InstantUpdate_VersionCode] = srcJson[Constants.InstantUpdate_VersionCode]; //预留versionCode
        //移除预留的key (不进行md5值的比较)
        srcJson.RemoveField(Constants.InstantUpdate_VersionTime);
        srcJson.RemoveField(Constants.InstantUpdate_VersionCode);

        if (desJson.IsAvailable())
        {
            desJson.RemoveField(Constants.InstantUpdate_VersionTime);
        }
        if (onComplete != null)
        {
            onComplete(CompareConfig(srcJson, desJson, gameModuleList), srcReservedConfig, null);
        }
    }