示例#1
0
    // Privats
    IEnumerator Start()
    {
        if (instance != this)
        {
            Destroy(gameObject);
            yield break;
        }
#if UNITY_EDITOR
        //HACK:为了让编辑器工作可以正常运作
        //如果出现了无法下载更新包的情况要递增这个版本数字,强制客户端清空Cache下载包
        if (!PlayerPrefs.HasKey(FORCE_DOWNLOAD_PREFSKEY) ||
            PlayerPrefs.GetInt(FORCE_DOWNLOAD_PREFSKEY) < FORCE_DOWNLOAD_VERSION)
        {
            CleanCache();
            PlayerPrefs.SetInt(FORCE_DOWNLOAD_PREFSKEY, FORCE_DOWNLOAD_VERSION);
        }
#endif
        // Initial download urls
        initRootUrl();

        //从本机缓存的数据中读取数据
        int lastBMDataVersion = 0;
        if (PlayerPrefs.HasKey(BMDATA_VERSION_PREFSKEY))
        {
            lastBMDataVersion = PlayerPrefs.GetInt(BMDATA_VERSION_PREFSKEY);
#if UNITY_EDITOR && ALWAYS_UPDATE_LOCAL
            //在编辑器模式下可能开发者中也会打包,这样会导致开发过程中本机缓存的包版本数字和主干的版本数字产生冲突
            //所以编辑器模式下无视版本数字缓存
            lastBMDataVersion = 0;
#endif
        }
        CurrentVesion = lastBMDataVersion;

        if (BMUtility.IsPersistentDataExists(DOWNLOAD_INFO_CACHE_NAME) &&
            BMUtility.IsPersistentDataExists(CONFIGER_CACHE_NAME))
        {
            bundles    = BMUtility.LoadFromPersistentData <List <BundleDownloadInfo> >(DOWNLOAD_INFO_CACHE_NAME);
            bmConfiger = BMUtility.LoadFromPersistentData <BMConfiger>(CONFIGER_CACHE_NAME);
        }



        //如果读取数据中出现问题,则清空所有缓存,之后可以从LoadRootUrl重新生成数据
        if (bundles == null || bmConfiger == null)
        {
            DownloadManager.CleanCache();
            CurrentVesion = 0;
            bundles       = new List <BundleDownloadInfo>();
            bmConfiger    = new BMConfiger();
        }
        refreshBundleDict();

        //尝试从LoadDownloadUrl下载版本信息
        //玩家更新客户端后可能LoadDownLoadUrl中版本会成为最新版本,这种情况同样需要mergeVersion和从本地更新下载
        if (string.IsNullOrEmpty(localRootUrl))
        {
        }
        else
        {
            var localVersionInfo = new VersionInfo(localRootUrl);
            yield return(StartCoroutine(downloadVersionInfoCo(localVersionInfo)));

            if (localVersionInfo.isValue)
            {
                CleanCache();
                bundles = new List <BundleDownloadInfo>();
                mergeVersion(localVersionInfo);
                refreshBundleDict();
                CurrentVesion = localVersionInfo.listVersion;
                PlayerPrefs.SetInt(BMDATA_VERSION_PREFSKEY, CurrentVesion);
            }
        }

        //Validation
        if (bundles == null)
        {
            Debug.LogError("{BM} Cannot get bundle list.");
            yield break;
        }
        if (bmConfiger == null)
        {
            Debug.LogError("{BM} Fail to load BMConfiger.");
        }

        initializationFinished = true;

        //Start download for requests before init
        foreach (var request in requestedBeforeInit)
        {
            download(request);
        }
    }
示例#2
0
    // Privats
    IEnumerator Start()
    {
        if (instance != this)
        {
            Destroy(gameObject);
            yield break;
        }
#if UNITY_EDITOR
        //HACK:Ϊ���ñ༭������������������
        //����������޷����ظ��°������Ҫ��������汾���֣�ǿ�ƿͻ������Cache���ذ�
        if (!PlayerPrefs.HasKey(FORCE_DOWNLOAD_PREFSKEY) ||
            PlayerPrefs.GetInt(FORCE_DOWNLOAD_PREFSKEY) < FORCE_DOWNLOAD_VERSION)
        {
            CleanCache();
            PlayerPrefs.SetInt(FORCE_DOWNLOAD_PREFSKEY, FORCE_DOWNLOAD_VERSION);
        }
#endif
        // Initial download urls
        initRootUrl();

        //�ӱ�������������ж�ȡ����
        int lastBMDataVersion = 0;
        if (PlayerPrefs.HasKey(BMDATA_VERSION_PREFSKEY))
        {
            lastBMDataVersion = PlayerPrefs.GetInt(BMDATA_VERSION_PREFSKEY);
#if UNITY_EDITOR && ALWAYS_UPDATE_LOCAL
            //�ڱ༭��ģʽ�¿��ܿ�������Ҳ�����������ᵼ�¿��������б�������İ��汾���ֺ����ɵİ汾���ֲ�����ͻ
            //���Ա༭��ģʽ�����Ӱ汾���ֻ���
            lastBMDataVersion = 0;
#endif
        }
        CurrentVesion = lastBMDataVersion;

        if (BMUtility.IsPersistentDataExists(DOWNLOAD_INFO_CACHE_NAME) &&
            BMUtility.IsPersistentDataExists(CONFIGER_CACHE_NAME))
        {
            bundles    = BMUtility.LoadFromPersistentData <List <BundleDownloadInfo> >(DOWNLOAD_INFO_CACHE_NAME);
            bmConfiger = BMUtility.LoadFromPersistentData <BMConfiger>(CONFIGER_CACHE_NAME);
        }



        //�����ȡ�����г������⣬��������л��棬֮����Դ�LoadRootUrl������������
        if (bundles == null || bmConfiger == null)
        {
            DownloadManager.CleanCache();
            CurrentVesion = 0;
            bundles       = new List <BundleDownloadInfo>();
            bmConfiger    = new BMConfiger();
        }
        refreshBundleDict();

        //���Դ�LoadDownloadUrl���ذ汾��Ϣ
        //��Ҹ��¿ͻ��˺����LoadDownLoadUrl�а汾���Ϊ���°汾���������ͬ����ҪmergeVersion�ʹӱ��ظ�������
        if (string.IsNullOrEmpty(localRootUrl))
        {
        }
        else
        {
            var localVersionInfo = new VersionInfo(localRootUrl);
            yield return(StartCoroutine(downloadVersionInfoCo(localVersionInfo)));

            if (localVersionInfo.isValue)
            {
                CleanCache();
                bundles = new List <BundleDownloadInfo>();
                mergeVersion(localVersionInfo);
                refreshBundleDict();
                CurrentVesion = localVersionInfo.listVersion;
                PlayerPrefs.SetInt(BMDATA_VERSION_PREFSKEY, CurrentVesion);
            }
        }

        //Validation
        if (bundles == null)
        {
            Debug.LogError("{BM} Cannot get bundle list.");
            yield break;
        }
        if (bmConfiger == null)
        {
            Debug.LogError("{BM} Fail to load BMConfiger.");
        }

        initializationFinished = true;

        //Start download for requests before init
        foreach (var request in requestedBeforeInit)
        {
            download(request);
        }
    }