Esempio n. 1
0
    public static bool ConvertToBinaryXml(string path)
    {
        //if (path.StartsWith(Application.dataPath))
        {
            string saveToDir = ResourcePath.GetLocalConfigPath();

            if (!Directory.Exists(saveToDir))
            {
                Directory.CreateDirectory(saveToDir);
            }

            if (path.ToLower().EndsWith(".xml"))
            {
                try
                {
                    FileInfo        fileInfo   = new FileInfo(path);
                    string          fileName   = fileInfo.Name.Substring(0, fileInfo.Name.Length - fileInfo.Extension.Length);
                    TbXmlSerializer serializer = new TbXmlSerializer();

                    path = path.Replace(Application.dataPath, "");
                    path = "Assets/Config/" + path;
                    byte[] bytes = serializer.SerializeXmlString((AssetDatabase.LoadMainAssetAtPath(path) as TextAsset).text);

                    string topath = Path.Combine(Path.Combine("../ClientRes", UUtility.GetPlatformName() + "/config/"), "");
                    topath = topath + fileName + ".bytes";
                    File.WriteAllBytes(topath, bytes);

                    return(true);
                }
                catch (System.Exception exception)
                {
                    Debug.LogError("Error:" + path);
                    //Debug.LogError(exception.Message);
                    //Debug.LogError(exception.StackTrace);
                    //Debug.LogError("");
                }
            }
            else
            {
                if (!path.ToLower().EndsWith(".meta"))
                {
                    FileInfo fileInfo = new FileInfo(path);
                    File.Copy(path, saveToDir + "/" + fileInfo.Name, true);
                    return(true);
                }
            }
        }
        return(false);
    }
Esempio n. 2
0
    public static bool ConvertToBinaryXml(string path)
    {
        if (path.StartsWith("Assets/Resources/Config/"))
        {
            string saveToDir = Application.dataPath + "/Resources/ConfigBytes";
            if (!Directory.Exists(saveToDir))
            {
                Directory.CreateDirectory(saveToDir);
            }

            if (path.ToLower().EndsWith(".xml"))
            {
                try
                {
                    FileInfo fileInfo = new FileInfo(path);
                    string   fileName = fileInfo.Name.Substring(0, fileInfo.Name.Length - fileInfo.Extension.Length);

                    TbXmlSerializer serializer = new TbXmlSerializer();
                    byte[]          bytes      = serializer.SerializeXmlString((AssetDatabase.LoadMainAssetAtPath(path) as TextAsset).text);

                    File.WriteAllBytes(saveToDir + "/" + fileName + ".bytes", bytes);
                    return(true);
                }
                catch (System.Exception exception)
                {
                    //Debug.LogError("Error:" + path);
                    //Debug.LogError(exception.Message);
                    //Debug.LogError(exception.StackTrace);
                    //Debug.LogError("");
                }
            }
            else
            {
                if (!path.ToLower().EndsWith(".meta"))
                {
                    FileInfo fileInfo = new FileInfo(path);
                    File.Copy(path, saveToDir + "/" + fileInfo.Name, true);
                    return(true);
                }
            }
        }
        return(false);
    }