Skip to content

Instantly share code, notes, and snippets.

@nkjzm
Created August 28, 2018 09:11
Show Gist options
  • Save nkjzm/d0c5fcf48627d6d8fa3f30b656f0242f to your computer and use it in GitHub Desktop.
Save nkjzm/d0c5fcf48627d6d8fa3f30b656f0242f to your computer and use it in GitHub Desktop.
System.IO.Path.DirectorySeparatorCharの値をリフレクションで書き換える方法
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Reflection;
[InitializeOnLoad]
public class PathReplacer
{
static PathReplacer()
{
typeof(Path).GetField("DirectorySeparatorChar", BindingFlags.Static | BindingFlags.Public).SetValue(null, '/');
Debug.Log(Path.DirectorySeparatorChar); // Output=> \
System.Func<char> getValue = () => Path.DirectorySeparatorChar;
Debug.Log(getValue()); // Output=> /
Debug.Log(Path.Combine("A", "B")); // Output=> A\B
}
}
@nkjzm
Copy link
Author

nkjzm commented Aug 28, 2018

これ多分char型なんでJITの最適化でアセンブラのコードに埋め込まれちゃって反映されてませんね。
SetValueの後、
Func<char> getValue = () => Path.DirectorySeparatorChar;
Debug.Log(getValue);
とかに書き換えたらもしかしたら反映後の値が読めるかも。やってないので分からないですが。

— あきら☎︎@VMC0.10 (@sh_akira) 2018年8月28日
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>

教えていただきました~~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment