unityEditor 打开文件

using System;
using System.Diagnostics;
using UnityEditor;
using UnityEngine;

/// 
/// 打开文件夹相关的实用函数。
/// 
public static class OpenFolder
{
    /// 
    /// 打开 Data Path 文件夹。
    /// 
    [MenuItem("Tools/Open Folder/Data Path", false, 10)]
    public static void OpenFolderDataPath()
    {
        Execute(Application.dataPath);
    }

    /// 
    /// 打开 Persistent Data Path 文件夹。
    /// 
    [MenuItem("Tools/Open Folder/Persistent Data Path", false, 11)]
    public static void OpenFolderPersistentDataPath()
    {
        Execute(Application.persistentDataPath);
    }

    /// 
    /// 打开 Streaming Assets Path 文件夹。
    /// 
    [MenuItem("Tools/Open Folder/Streaming Assets Path", false, 12)]
    public static void OpenFolderStreamingAssetsPath()
    {
        Execute(Application.streamingAssetsPath);
    }

    /// 
    /// 打开 Temporary Cache Path 文件夹。
    /// 
    [MenuItem("Tools/Open Folder/Temporary Cache Path", false, 13)]
    public static void OpenFolderTemporaryCachePath()
    {
        Execute(Application.temporaryCachePath);
    }

    /// 
    /// 打开指定路径的文件夹。
    /// 
    /// 要打开的文件夹的路径。
    public static void Execute(string folder)
    {
        folder = string.Format("\"{0}\"", folder);
        switch (Application.platform)
        {
            case RuntimePlatform.WindowsEditor:
                Process.Start("Explorer.exe", folder.Replace('/', '\\'));
                break;

            case RuntimePlatform.OSXEditor:
                Process.Start("open", folder);
                break;

            default:
                throw new Exception(string.Format("Not support open folder on '{0}' platform.",
                    Application.platform.ToString()));
        }
    }
}

你可能感兴趣的:(c#,unity)