Exemple #1
0
    public static void WriteFile(string filePath, string[] fileData)
    {
        if (string.IsNullOrEmpty(filePath))
        {
            return;
        }

        int count = 1;

        WriteFileProgresser.GetInstance().InitProgresser(fileData.Length, "CSV文件写入中");

        StreamWriter fileWriter = File.CreateText(filePath);

        if (fileWriter != null)
        {
            UniversalEditorUtility.MakeFileWriteable(filePath);
            foreach (var item in fileData)
            {
                fileWriter.WriteLine(item);
                WriteFileProgresser.GetInstance().UpdateProgress(count++);
            }
            fileWriter.Close();
            //File.WriteAllLines(filePath, fileData);
        }
    }
Exemple #2
0
    //Add by liteng for 发布工具改善 start
    public static void SetPublishMode(bool bIsDebugMode)
    {
        if (!Directory.Exists(Path.GetDirectoryName(m_ConfigXMLPath)))
        {
            Directory.CreateDirectory(Path.GetDirectoryName(m_ConfigXMLPath));
        }

        UniversalEditorUtility.MakeFileWriteable(m_ConfigXMLPath);

        XmlDocument docment = new XmlDocument();
        XmlElement  root    = docment.CreateElement("PublishModeConfig");

        docment.AppendChild(root);

        XmlElement nodeMode = docment.CreateElement("Mode");

        if (bIsDebugMode)
        {
            nodeMode.InnerText = "Debug";
        }
        else
        {
            nodeMode.InnerText = "Release";
        }
        root.AppendChild(nodeMode);

        docment.Save(m_ConfigXMLPath);

        debugMode = bIsDebugMode;
    }
Exemple #3
0
    public static string ReadReferenceResultPath()
    {
        string path = string.Empty;

        if (File.Exists(configPath))
        {
            UniversalEditorUtility.MakeFileWriteable(configPath);
            XmlDocument docment = new XmlDocument();
            docment.Load(configPath);
            XmlNode root = docment.SelectSingleNode("UIAtlasConfig");
            if (root != null)
            {
                XmlNode nodeReferenceResultPath = root.SelectSingleNode("ReferenceResultPath");
                if (nodeReferenceResultPath != null)
                {
                    path = nodeReferenceResultPath.InnerText;
                }
            }
        }

        if (!string.IsNullOrEmpty(path))
        {
            ReferenceResultPath = path;
        }

        return(path);
    }
Exemple #4
0
    public static string ReadExportPath()
    {
        string exportPath = null;

        if (File.Exists(m_ExportConfigPath))
        {
            UniversalEditorUtility.MakeFileWriteable(m_ExportConfigPath);
            XmlDocument docment = new XmlDocument();
            docment.Load(m_ExportConfigPath);
            XmlNode root = docment.SelectSingleNode("ExportInfoConfig");
            if (root != null)
            {
                XmlNode nodeExportPath = root.SelectSingleNode("ExportPath");
                if (nodeExportPath != null)
                {
                    exportPath = nodeExportPath.InnerText;
                }
            }
        }

        if ((exportPath != null) && (exportPath != ""))
        {
            ExportPath = exportPath;
        }

        return(exportPath);
    }
Exemple #5
0
    public static void WriteImageBasePath(string path)
    {
        if (string.IsNullOrEmpty(path))
        {
            return;
        }

        if (!File.Exists(configPath))
        {
            CreateXMLConifg(configPath);

            UniversalEditorUtility.MakeFileWriteable(configPath);

            XmlDocument docment = new XmlDocument();
            XmlElement  root    = docment.CreateElement("UIAtlasConfig");
            docment.AppendChild(root);

            XmlElement nodeImageBasePath = docment.CreateElement("ImageBasePath");
            nodeImageBasePath.InnerText = path;
            root.AppendChild(nodeImageBasePath);

            XmlElement nodeProjectPath = docment.CreateElement("ProjectPath");
            root.AppendChild(nodeProjectPath);

            docment.Save(configPath);
        }
        else
        {
            XmlDocument docment = new XmlDocument();
            docment.Load(configPath);
            XmlNode root = docment.SelectSingleNode("UIAtlasConfig");
            if (root != null)
            {
                XmlNode nodeImageBasePath = root.SelectSingleNode("ImageBasePath");
                if (nodeImageBasePath != null)
                {
                    nodeImageBasePath.InnerText = path;
                }
                else
                {
                    nodeImageBasePath           = docment.CreateElement("ImageBasePath");
                    nodeImageBasePath.InnerText = path;
                    root.AppendChild(nodeImageBasePath);
                }
            }
            else
            {
                root = docment.CreateElement("UIAtlasConfig");
                docment.AppendChild(root);

                XmlNode nodeImageBasePath = docment.CreateElement("ImageBasePath");
                nodeImageBasePath.InnerText = path;
                root.AppendChild(nodeImageBasePath);
            }
            docment.Save(configPath);
        }

        imageBasePath = path;
        onBasePathChange(path);
    }
Exemple #6
0
    public void OpenFilterConfigFile()
    {
        List <string> refTag = new List <string>();

        if (!File.Exists(m_configPath))
        {
            StreamWriter fileWriter = File.CreateText(m_configPath);
            UniversalEditorUtility.MakeFileWriteable(m_configPath);

            refTag.Add("正向引用过滤:" + Environment.NewLine);
            refTag.Add("反向引用过滤:" + Environment.NewLine);
            refTag.Add("无引用过滤:" + Environment.NewLine);

            foreach (var item in refTag)
            {
                fileWriter.WriteLine(item);
            }

            fileWriter.Close();
        }

        //System.Diagnostics.Process.Start(m_configPath);
        //UniversalEditorUtility.MakeFileWriteable(m_configPath);

        System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
        myProcess.StartInfo.FileName        = @m_configPath;
        myProcess.StartInfo.LoadUserProfile = true;
        myProcess.StartInfo.Verb            = "open";
        myProcess.Start();
        myProcess.WaitForExit(1);
        myProcess.Close();
        //myProcess = System.Diagnostics.Process.Start(@m_configPath);
    }
Exemple #7
0
    public static string ReadPublishPath()
    {
        FileStream   fileStream  = null;
        StreamReader streamR     = null;
        string       publishPath = null;

        if (File.Exists(m_PublishConfigPath))
        {
            UniversalEditorUtility.MakeFileWriteable(m_PublishConfigPath);
            fileStream = new FileStream(m_PublishConfigPath, FileMode.Open);
            streamR    = new StreamReader(fileStream);

            while (!streamR.EndOfStream)
            {
                publishPath += streamR.ReadLine();
            }

            streamR.Close();
            fileStream.Close();
        }

        if ((publishPath != null) && (publishPath != ""))
        {
            PublishPath = publishPath;
        }

        return(publishPath);
    }
Exemple #8
0
    public static void WriteManualPath(string path)
    {
        if (null == path)
        {
            return;
        }

        if (!File.Exists(m_ExportConfigPath))
        {
            CreateXMLConifg(m_ExportConfigPath);

            UniversalEditorUtility.MakeFileWriteable(m_ExportConfigPath);

            XmlDocument docment = new XmlDocument();
            XmlElement  root    = docment.CreateElement("ExportInfoConfig");
            docment.AppendChild(root);

            XmlElement nodeExportPath = docment.CreateElement("ExportPath");
            root.AppendChild(nodeExportPath);

            XmlElement nodeManualPath = docment.CreateElement("ManualPath");
            nodeManualPath.InnerText = path;
            root.AppendChild(nodeManualPath);

            docment.Save(m_ExportConfigPath);
        }
        else
        {
            XmlDocument docment = new XmlDocument();
            docment.Load(m_ExportConfigPath);
            XmlNode root = docment.SelectSingleNode("ExportInfoConfig");
            if (root != null)
            {
                XmlNode nodeExportPath = root.SelectSingleNode("ManualPath");
                if (nodeExportPath != null)
                {
                    nodeExportPath.InnerText = path;
                }
                else
                {
                    nodeExportPath           = docment.CreateElement("ManualPath");
                    nodeExportPath.InnerText = path;
                    root.AppendChild(nodeExportPath);
                }
            }
            else
            {
                root = docment.CreateElement("ExportInfoConfig");
                docment.AppendChild(root);

                XmlNode nodeExportPath = docment.CreateElement("ManualPath");
                nodeExportPath.InnerText = path;
                root.AppendChild(nodeExportPath);
            }

            docment.Save(m_ExportConfigPath);
        }

        ManualPath = path;
    }
Exemple #9
0
    public void WirteEditorLayoutInfo(string baseDir, EditorRoot root)
    {
        if (
            (null == root) ||
            string.IsNullOrEmpty(baseDir)
            )
        {
            return;
        }

        object obj = GetSerializeObject(root);

        if (null == obj)
        {
            return;
        }

        string eidtorLayoutInfoPath = baseDir + root.editorName + "/" + "EditorLayoutInfo.layout";

        if (!Directory.Exists(baseDir + root.editorName))
        {
            Directory.CreateDirectory(baseDir + root.editorName);
        }

        UniversalEditorUtility.MakeFileWriteable(eidtorLayoutInfoPath);

        StreamWriter yamlWriter     = File.CreateText(eidtorLayoutInfoPath);
        Serializer   yamlSerializer = new Serializer();

        yamlSerializer.Serialize(yamlWriter, obj);

        yamlWriter.Close();
    }
Exemple #10
0
    public void WriteRecentOpenProjectPath(string path)
    {
        if (string.IsNullOrEmpty(path))
        {
            return;
        }

        if (!File.Exists(recentOpenProjectConfigPath))
        {
            if (!Directory.Exists(Path.GetDirectoryName(recentOpenProjectConfigPath)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(recentOpenProjectConfigPath));
            }

            UniversalEditorUtility.MakeFileWriteable(recentOpenProjectConfigPath);

            XmlDocument docment = new XmlDocument();
            XmlElement  root    = docment.CreateElement("UIAtlasMaker");
            docment.AppendChild(root);

            XmlElement nodeRecentOpenProjectPath = docment.CreateElement("RecentOpenProject");
            nodeRecentOpenProjectPath.InnerText = path;
            root.AppendChild(nodeRecentOpenProjectPath);


            docment.Save(recentOpenProjectConfigPath);
        }
        else
        {
            XmlDocument docment = new XmlDocument();
            docment.Load(recentOpenProjectConfigPath);
            XmlNode root = docment.SelectSingleNode("UIAtlasMaker");
            if (root != null)
            {
                XmlNode nodeRecentOpenProjectPath = root.SelectSingleNode("RecentOpenProject");
                if (nodeRecentOpenProjectPath != null)
                {
                    nodeRecentOpenProjectPath.InnerText = path;
                }
                else
                {
                    nodeRecentOpenProjectPath           = docment.CreateElement("RecentOpenProject");
                    nodeRecentOpenProjectPath.InnerText = path;
                    root.AppendChild(nodeRecentOpenProjectPath);
                }
            }
            else
            {
                root = docment.CreateElement("UIAtlasMaker");
                docment.AppendChild(root);

                XmlNode nodeRecentOpenProjectPath = docment.CreateElement("RecentOpenProject");
                nodeRecentOpenProjectPath.InnerText = path;
                root.AppendChild(nodeRecentOpenProjectPath);
            }
            docment.Save(recentOpenProjectConfigPath);
        }
    }
Exemple #11
0
    public bool SaveXMLConfig()
    {
        bool bRet = true;

        if (IsPackageInfoNull())
        {
            ErrorType = PACKAGE_FAILED_TYPE.PACKAGE_FAILED_UNKNOW_ERROR;
            return(false);
        }

        if (string.IsNullOrEmpty(PackageExportConfig.AssetsConfigPath))
        {
            ErrorType = PACKAGE_FAILED_TYPE.PACKAGE_FAILED_XMLCONFIG_PATH_ERROR;
            return(false);
        }

        if (!IsSubPackageVersionValid())
        {
            ErrorType = PACKAGE_FAILED_TYPE.PACKAGE_FAILED_VERSION_NONE_ERROR;
            return(false);
        }

        PackageExportConfig.CreateXMLConifg(PackageExportConfig.AssetsConfigPath);
        UniversalEditorUtility.MakeFileWriteable(PackageExportConfig.AssetsConfigPath);

        XmlDocument docment = new XmlDocument();
        XmlElement  root    = docment.CreateElement("ExportPackageConfig");

        docment.AppendChild(root);

        XmlElement nodeVersion = docment.CreateElement("Version");

        UpdatePackageVersion();
        nodeVersion.InnerText = m_Assets.PackageInfo.VersionNum;
        root.AppendChild(nodeVersion);

        XmlElement nodePath = docment.CreateElement("Path");

        root.AppendChild(nodePath);
        foreach (string sPath in m_Assets.PackageInfo.ExportAssets)
        {
            XmlElement node = docment.CreateElement("Item");
            node.InnerText = sPath;
            nodePath.AppendChild(node);
        }

        try
        {
            docment.Save(PackageExportConfig.AssetsConfigPath);
        }
        catch (System.Exception e)
        {
            bRet = false;
            Debug.Log("保存打包工具配置文件失败: " + e.Message);
        }

        return(bRet);
    }
    public void Save()
    {
        _TouchConfigDir();
        UniversalEditorUtility.MakeFileWriteable(_GetConfigFilePath());
        var        configWriter  = File.CreateText(_GetConfigFilePath());
        Serializer yamlSerialzer = new Serializer();

        yamlSerialzer.Serialize(configWriter, Paths);
        configWriter.Close();
    }
Exemple #13
0
    public void Save()
    {
        _TouchCacheFolder();
        UniversalEditorUtility.MakeFileWriteable(_GetCacheFilePath());
        StreamWriter yamlWriter     = File.CreateText(_GetCacheFilePath());
        Serializer   yamlSerializer = new Serializer();
        object       obj            = _GetSerializeObject();

        yamlSerializer.Serialize(yamlWriter, obj);
        yamlWriter.Close();
    }
Exemple #14
0
    public static void WritePublishPath(string path)
    {
        FileStream   fileStream = null;
        StreamWriter streamW    = null;

        fileStream = new FileStream(m_PublishConfigPath, FileMode.Create);
        UniversalEditorUtility.MakeFileWriteable(m_PublishConfigPath);

        streamW = new StreamWriter(fileStream);
        streamW.Write(path);

        streamW.Close();
        fileStream.Close();

        PublishPath = path;
    }
    public void SaveAtlasSerializeObject(string filePath, object obj)
    {
        if (
            string.IsNullOrEmpty(filePath) ||
            (null == obj)
            )
        {
            return;
        }

        UniversalEditorUtility.MakeFileWriteable(filePath);
        StreamWriter yamlWriter     = File.CreateText(filePath);
        Serializer   yamlSerializer = new Serializer();

        //将持久化对象写入工程文件
        yamlSerializer.Serialize(yamlWriter, obj);
        yamlWriter.Close();
    }
Exemple #16
0
    private void DeleteTempFiles()
    {
        do
        {
            if (string.IsNullOrEmpty(PackageExportConfig.ExportPath))
            {
                break;
            }

            if (string.IsNullOrEmpty(PackageExportConfig.PackageName))
            {
                break;
            }

            if (File.Exists(PackageExportConfig.ExportPath + PackageExportConfig.PackageName))
            {
                UniversalEditorUtility.MakeFileWriteable(PackageExportConfig.ExportPath + PackageExportConfig.PackageName);
                File.Delete(PackageExportConfig.ExportPath + PackageExportConfig.PackageName);
            }
        } while (false);
    }
Exemple #17
0
    public string ReadRecentOpenProjectPath()
    {
        string projectPath = string.Empty;

        if (File.Exists(recentOpenProjectConfigPath))
        {
            UniversalEditorUtility.MakeFileWriteable(recentOpenProjectConfigPath);
            XmlDocument docment = new XmlDocument();
            docment.Load(recentOpenProjectConfigPath);
            XmlNode root = docment.SelectSingleNode("UIAtlasMaker");
            if (root != null)
            {
                XmlNode nodeRecentOpenProjectPath = root.SelectSingleNode("RecentOpenProject");
                if (nodeRecentOpenProjectPath != null)
                {
                    projectPath = nodeRecentOpenProjectPath.InnerText;
                }
            }
        }

        return(projectPath);
    }
    //public bool UnloadTexture(string path)
    //{//卸载纹理
    //    bool bRet = true;

    //    if(path == null)
    //    {
    //        return false;
    //    }

    //    foreach (var textureInfo in textureCache)
    //    {
    //        if (textureInfo.Key == path)
    //        {
    //            AssetDatabase.DeleteAsset(textureInfo.Value.TempPath);
    //            AssetDatabase.DeleteAsset(textureInfo.Value.TempPathZoom);

    //            textureCache.Remove(path);
    //            bRet = true;
    //            break;
    //        }
    //    }

    //    return bRet;
    //}

    public Texture2D ZoomTexture(string spritePath, string atlasPath, float scaleFactor)
    {//缩放纹理
        Texture2D       tex        = null;
        TempTextureInfo spriteInfo = null;

        if ((string.IsNullOrEmpty(spritePath)) || (string.IsNullOrEmpty(atlasPath)) ||
            ((-0.000001f < scaleFactor) && (scaleFactor < 0.000001f)))
        {
            return(null);
        }

        if (IsSpriteInfoInCache(spritePath, atlasPath, out spriteInfo))
        {
            spriteInfo.ZoomTexture = ScaleTextureBilinear(spriteInfo.Texture, scaleFactor);
            spriteInfo.ZoomScale   = scaleFactor;

            byte[] bytes     = spriteInfo.ZoomTexture.EncodeToPNG();
            string newPath   = Path.GetFileNameWithoutExtension(spriteInfo.TempPath);
            string extension = Path.GetExtension(spriteInfo.TempPath);
            newPath = GetAtlasTempDir(atlasPath) + newPath + m_zoomStr + extension;

            UniversalEditorUtility.MakeFileWriteable(newPath);
            System.IO.File.WriteAllBytes(newPath, bytes);

            bytes = null;

            AssetDatabase.ImportAsset(newPath);
            MakeTextureReadable(newPath, false);
            AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);

            spriteInfo.ZoomTexture = AssetDatabase.LoadAssetAtPath(newPath, typeof(Texture)) as Texture2D;

            tex = spriteInfo.ZoomTexture;
        }

        return(tex);
    }
    public Texture2D LoadTexture(string spritePath, string atlasPath, float scaleFactor)
    {
        if (
            string.IsNullOrEmpty(spritePath) ||
            string.IsNullOrEmpty(atlasPath) ||
            ((-0.000001f < scaleFactor) && (scaleFactor < 0.000001f))
            )
        {
            return(null);
        }

        _TouchTempDir();

        string tempAtlasDir = CreateAtlasTempDir(atlasPath);

        if (string.IsNullOrEmpty(tempAtlasDir))
        {
            return(null);
        }

        TempTextureInfo spriteInfo = null;

        string fileName           = Path.GetFileName(spritePath);
        string extension          = Path.GetExtension(spritePath);
        string fileNameWithoutext = Path.GetFileNameWithoutExtension(spritePath);
        string zoomedName         = string.Empty;

        bool isNeedRename = false;
        bool needCopy     = false;

        if (!IsEnableTextureFile(fileName))
        {
            return(null);
        }

        if (!File.Exists(spritePath))
        {
            DeleteUnuseAsset(spritePath, atlasPath);
            return(null);
        }

        if (IsSpriteInTempFloder(spritePath, atlasPath, out isNeedRename))
        {
            if (!IsSouceSpriteFileNoChange(spritePath, atlasPath))
            {
                needCopy = true;
            }
        }
        else
        {
            needCopy = true;
        }

        if (needCopy)
        {
            if (isNeedRename)
            {
                fileName   = fileNameWithoutext + "副本" + extension;
                zoomedName = fileNameWithoutext + "副本" + m_zoomStr + extension;
            }
            else
            {
                zoomedName = fileNameWithoutext + m_zoomStr + extension;
            }

            string absTempAtlasDir = EditorHelper.GetProjectPath() + tempAtlasDir;

            UniversalEditorUtility.MakeFileWriteable(absTempAtlasDir + fileName);
            File.Copy(spritePath, absTempAtlasDir + fileName, true);

            UniversalEditorUtility.MakeFileWriteable(absTempAtlasDir + zoomedName);
            File.Copy(spritePath, absTempAtlasDir + zoomedName, true);

            AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);
        }


        //TempTextureInfo retTexInfo = null;
        if (!IsSpriteInfoInCache(spritePath, atlasPath, out spriteInfo))
        {//还未载入内存
            AssetDatabase.ImportAsset(tempAtlasDir + fileName);
            MakeTextureReadable(tempAtlasDir + fileName, false);
            TempTextureInfo newTexInfo = new TempTextureInfo();
            newTexInfo.SourcePath   = spritePath;
            newTexInfo.TempPath     = tempAtlasDir + fileName;
            newTexInfo.TempPathZoom = tempAtlasDir + zoomedName;
            newTexInfo.Texture      = AssetDatabase.LoadAssetAtPath(newTexInfo.TempPath, typeof(Texture)) as Texture2D;
            newTexInfo.ZoomScale    = scaleFactor;

            AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);

            if (newTexInfo.Texture != null)
            {
                newTexInfo.ZoomTexture = newTexInfo.Texture;
                AddSpriteInCache(spritePath, atlasPath, newTexInfo);

                if (scaleFactor != 1.0f)
                {
                    ZoomTexture(spritePath, atlasPath, scaleFactor);
                }
            }
        }


        return(GetSpriteTexture(spritePath, atlasPath));
    }
Exemple #20
0
    public static void CreateXMLConfigWithNode(string path, string NodeType, string NodeValue)
    {
        if (!Directory.Exists(Path.GetDirectoryName(path)))
        {
            Directory.CreateDirectory(Path.GetDirectoryName(path));
        }

        UniversalEditorUtility.MakeFileWriteable(configPath);

        XmlDocument docment = new XmlDocument();
        XmlElement  root    = docment.CreateElement("UIAtlasConfig");

        docment.AppendChild(root);

        XmlElement nodeImageBasePath = docment.CreateElement("ImageBasePath");

        root.AppendChild(nodeImageBasePath);

        XmlElement nodeProjectPath = docment.CreateElement("ProjectPath");

        root.AppendChild(nodeProjectPath);

        XmlElement nodeConsistencyResultPath = docment.CreateElement("ConsistencyResultPath");

        root.AppendChild(nodeConsistencyResultPath);

        XmlElement nodeConsistencyPrefabPath = docment.CreateElement("ConsistencyPrefabPath");

        root.AppendChild(nodeConsistencyPrefabPath);

        XmlElement nodeReferencePrefabPath = docment.CreateElement("ReferencePrefabPath");

        root.AppendChild(nodeReferencePrefabPath);

        XmlElement nodeReferenceScenePath = docment.CreateElement("ReferenceScenePath");

        root.AppendChild(nodeReferenceScenePath);

        XmlElement nodeReferenceResultPath = docment.CreateElement("ReferenceResultPath");

        root.AppendChild(nodeReferenceResultPath);

        switch (NodeType)
        {
        case "ImageBasePath":
            nodeImageBasePath.InnerText = NodeValue;
            break;

        case "ProjectPath":
            nodeProjectPath.InnerText = NodeValue;
            break;

        case "ConsistencyResultPath":
            nodeConsistencyResultPath.InnerText = NodeValue;
            break;

        case "ConsistencyPrefabPath":
            nodeConsistencyPrefabPath.InnerText = NodeValue;
            break;

        case "ReferencePrefabPath":
            nodeReferencePrefabPath.InnerText = NodeValue;
            break;

        case "ReferenceScenePath":
            nodeReferenceScenePath.InnerText = NodeValue;
            break;

        case "ReferenceResultPath":
            nodeReferenceResultPath.InnerText = NodeValue;
            break;

        default:
            break;
        }

        docment.Save(configPath);
    }