Exemple #1
0
    /// <summary>
    /// 加载数据表
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="path">二进制路径</param>
    /// <returns></returns>
    public T LoadData <T>(string path) where T : ExcelBase
    {
        if (string.IsNullOrEmpty(path))
        {
            return(null);
        }

        if (m_AllExcelData.ContainsKey(path))
        {
            Debug.LogError("重复加载相同配置文件:" + path);
            return(m_AllExcelData[path] as T);
        }

        T data = BinarySerializeOpt.BinaryDeserialize <T>(path);

#if UNITY_EDITOR
        if (data == null)
        {
            Debug.Log(path + "不存在,从xml加载数据了!");
            string xmlPath = path.Replace("Binary", "Xml").Replace(".bytes", ".xml");
            data = BinarySerializeOpt.XmlDeserialize <T>(xmlPath);
        }
#endif

        if (data != null)
        {
            data.Init();
        }

        m_AllExcelData.Add(path, data);
        return(data);
    }
Exemple #2
0
    /// <summary>
    /// 加载data
    /// </summary>
    /// <param name="path">路径</param>
    /// <typeparam name="T">ExcelBase类</typeparam>
    /// <returns></returns>
    public T LoadData <T>(string path) where T : ExcelBase
    {
        if (string.IsNullOrEmpty(path))
        {
            return(null);
        }
        if (m_ExcelDataDic.ContainsKey(path))
        {
            return(m_ExcelDataDic[path] as T);
        }
        T data = null;

        data = BinarySerializeOpt.BinaryDeserialize <T>(path);
        //如果在编译器中 未生成二进制 转为xml读取
#if UNITY_EDITOR
        if (data == null)
        {
            Debug.LogWarning("LoadData 未生成Binary文件 path:" + path);
            path = path.Replace("Binary", "Xml").Replace(".bytes", ".xml");
            data = BinarySerializeOpt.XmlDeserialize <T>(path);
        }
#endif
        if (data != null)
        {
            data.Init();
        }
        return(data);
    }