Unity Editorの拡張コードを書いているとフルパスとAssetsから始まるパスを使う時があり、この変数はどちらのパスだっけ?と混乱するときが出てきます。それを回避するための関数を作りました。
基本的に変数にはフルパスを入れておき、Assetsパスが必要なときにこの関数を使うイメージです。
|
1 2 3 4 5 6 7 8 9 10 11 |
public string GetAssetsPath(string fullPath) { int startIndex = fullPath.IndexOf("Assets/", StringComparison.Ordinal); if (startIndex == -1) startIndex = fullPath.IndexOf("Assets\\", StringComparison.Ordinal); if (startIndex == -1) return ""; string assetPath = fullPath.Substring(startIndex); return assetPath; } |




![Unity – [Editor拡張] HierarchyにあるGameObjectの元Prefabのパスを返す方法](https://i0.wp.com/mizutanikirin.net/blog/wp-content/uploads/2015/09/unity1-150x150.jpg?resize=150%2C150&ssl=1)


コメントを残す