Unity打包的時候保存默認的輸出路徑,再次使用該路徑的時候讀取之


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Text;

public class BuildTool
{
    [MenuItem("BuildTool/BuildCloth/BuildSelect")]
    static void LgsTest()
    {
        string defaultPath = getDefaultPath();
        string buildPath = EditorUtility.SaveFolderPanel("Build Select Cloth", defaultPath, "");

        if (buildPath.Length > 0)
        {
            saveDefaultPath(buildPath);
        }
    }

    static void saveDefaultPath(string defaultPath)
    {
        string configPath = System.Environment.CurrentDirectory + "/path.init";
        using (FileStream fs = new FileStream(configPath, FileMode.Create))
        {
            using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
            {
                sw.Write(defaultPath);
            }
        }
    }

    static string getDefaultPath()
    {
        // System.Environment.CurrentDirectory : 在Unity中指工程的跟目錄,即與Assets目錄是平級的。
        string configPath = System.Environment.CurrentDirectory + "/path.init";
        string result = string.Empty;
        if (File.Exists(configPath))
        {
            using (FileStream fs = new FileStream(configPath, FileMode.Open))
            {
                using (StreamReader sr = new StreamReader(fs, Encoding.UTF8))
                {
                    result = sr.ReadToEnd();
                }
            }
        }
        else
        {
            //Application.dataPath 指Assets目錄
            result = Application.dataPath;
        }

        return result;
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM