Exemple #1
0
    /// <summary>
    /// 加载某个csv
    /// </summary>
    public static CsvFile Load(string csvName)
    {
        try
        {
            // 载入资源
            string assetPath = ConfigMgr.ETC_PATH + "/" + csvName + CSV_EXT;
            byte[] csvBytes  = ResourceMgr.Instance.LoadByte(assetPath);

            // 资源不存在
            if (csvBytes == null || csvBytes.Length == 0)
            {
                return(null);
            }

            // 反序列化
            MemoryStream csvStr = new MemoryStream(csvBytes, 0, csvBytes.Length, true, true);
            CsvFile      csv    = CsvFileMgr.Deserialize(csvStr);
            csvStr.Close();

            // 返回数据
            return(csv);
        }
        catch (Exception e)
        {
            NIDebug.Log(e.Message);
            return(null);
        }
        finally
        {
            // do something
        }
    }
Exemple #2
0
    /// <summary>
    /// 载入地资源映射目录
    /// </summary>
    private static IEnumerator LoadResourceDictFile()
    {
        // 本地版本文件不存在
        string filePath = string.Format("{0}/{1}.bytes", ConfigMgr.ASSETBUNDLES_PATH, RESOURCE_DICT);

        if (!File.Exists(filePath))
        {
            NIDebug.Log("找不到本地资源映射目录。");
            yield break;
        }

        // 载入本地版本文件
        try
        {
            // 读取文件
            byte[] verData = File.ReadAllBytes(filePath);

            // 反序列化
            MemoryStream csvStr = new MemoryStream(verData, 0, verData.Length, true, true);
            mResourceDictCsv = CsvFileMgr.Deserialize(csvStr);
            csvStr.Close();
            verData = null;
        }
        catch (Exception e)
        {
            NIDebug.LogException(e);
        }
    }
Exemple #3
0
    /// <summary>
    /// 载入随包资源版本
    /// </summary>
    /// <returns>The streaming version file.</returns>
    public static IEnumerator LoadStreamingVersionFile()
    {
        // 重新new一个数据
        mNewVersionCsv = new CsvFile("new_version");

        // 载入文件
        WWW www = new WWW(ConfigMgr.GetStreamingPathWWW(string.Format("{0}.bytes", VERSION_NAME)));

        yield return(www);

        // 等待资源加载完成
        while (!www.isDone)
        {
            yield return(null);
        }

        // 文件载入失败, 获取文件不存在
        if (!string.IsNullOrEmpty(www.error) || www.bytes.Length <= 0)
        {
            yield break;
        }

        // 反序列化
        MemoryStream csvStr = new MemoryStream(www.bytes, 0, www.bytes.Length, true, true);

        mNewVersionCsv = CsvFileMgr.Deserialize(csvStr);
        csvStr.Close();

        // 释放www
        www.Dispose();
    }
Exemple #4
0
    /// <summary>
    /// 下载远程版本文件
    /// </summary>
    private static IEnumerator UpdateNewVersionFile(int urlIndex)
    {
        // 获取配置的ab下载地址
        IList abUrls = (IList)ConfigMgr.Get <JsonData>("ab_urls", null);

        if (abUrls == null || abUrls.Count == 0)
        {
            NIDebug.Log("获取assetbundle资源路径失败");
            isVersionFileLoadSuccess = true;
            yield break;
        }

        // 尝试载入服务器上的版本文件
        string versionUrl = string.Format("{0}/{1}.bytes", abUrls[urlIndex], VERSION_NAME);
        WWW    www        = new WWW(versionUrl);

        yield return(www);

        // 下载文件失败,切换其他地址下载
        if (!string.IsNullOrEmpty(www.error))
        {
            // 切换ab更新地址
            Coroutine.DispatchService(UpdateNewVersionFile(urlIndex >= abUrls.Count - 1 ? 0 : ++urlIndex));

            NIDebug.Log("{0}超时或错误", versionUrl);
            yield break;
        }

        // 反序列化
        MemoryStream csvStr = new MemoryStream(www.bytes, 0, www.bytes.Length, true, true);

        mNewVersionCsv = CsvFileMgr.Deserialize(csvStr);
        csvStr.Close();
        isVersionFileLoadSuccess = true;

        // 释放www
        www.Dispose();

        NIDebug.Log("下载版本文件成功");

        yield break;
    }
Exemple #5
0
    /// <summary>
    /// 载入版本文件
    /// </summary>
    private static CsvFile LoadVersion(string path)
    {
        string versionPath = string.Format("{0}version_tree.bytes", path);

        // 如果文件不存在不处理
        if (!File.Exists(versionPath))
        {
            return(new CsvFile("version_tree"));
        }

        // 获取byte信息
        byte[] csvBytes = File.ReadAllBytes(versionPath);

        // 反序列化
        MemoryStream csvStr = new MemoryStream(csvBytes, 0, csvBytes.Length, true, true);
        CsvFile      csv    = CsvFileMgr.Deserialize(csvStr);

        csvStr.Close();

        // 返回配置信息
        return(csv);
    }
Exemple #6
0
    /// <summary>
    /// 载入本地版本文件
    /// </summary>
    public static IEnumerator LoadVersionFile()
    {
        // 本地版本文件不存在
        string filePath = string.Format("{0}/{1}.bytes", ConfigMgr.ASSETBUNDLES_PATH, VERSION_NAME);

        if (!File.Exists(filePath))
        {
            NIDebug.Log("找不到本地版本文件");
            yield break;
        }

        // 载入文件
        WWW www = new WWW(ConfigMgr.GetLocalRootPathWWW(string.Format("{0}/{1}.bytes", ConfigMgr.ASSETBUNDLES_NAME, VERSION_NAME)));

        yield return(www);

        // 等待资源加载完成
        while (!www.isDone)
        {
            yield return(null);
        }

        // 文件载入失败, 获取文件不存在
        if (!string.IsNullOrEmpty(www.error) || www.bytes.Length <= 0)
        {
            yield break;
        }

        // 反序列化
        MemoryStream csvStr = new MemoryStream(www.bytes, 0, www.bytes.Length, true, true);

        mVersionCsv = CsvFileMgr.Deserialize(csvStr);
        csvStr.Close();

        // 释放www
        www.Dispose();
    }