コガネブログ

平日更新を目標に Unity や C#、Visual Studio、ReSharper などのゲーム開発アレコレを書いていきます

【Unity】区切り文字にスラッシュを使用してパスを連結する関数

using System.IO;

public static class PathUtils
{
    /// <summary>
    /// 2 つの文字列を 1 つのパスに結合します
    /// </summary>
    public static string Combine( string path1, string path2 )
    {
        return Path
            .Combine( path1, path2 )
            .Replace( "\\", "/" );
    }
}
Path.Combine( "Prefabs", "Player.prefab" ); // Prefabs\\Player.prefab
PathUtils.Combine( "Prefabs", "Player.prefab" ); // Prefabs/Player.prefab

関連記事