Skip to content

Commit 896a9ba

Browse files
author
Robert Roos
committed
Changed GetRos2ForUnityPath() to allow dynamic directory
1 parent 010d9e5 commit 896a9ba

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/Ros2ForUnity/Scripts/ROS2ForUnity.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,24 @@ private string GetEnvPathVariableValue()
8686
public static string GetRos2ForUnityPath()
8787
{
8888
char separator = Path.DirectorySeparatorChar;
89-
string appDataPath = Application.dataPath;
90-
string pluginPath = appDataPath;
89+
string pluginPath = "";
9190

92-
if (InEditor()) {
93-
pluginPath += separator + ros2ForUnityAssetFolderName;
91+
var assets = AssetDatabase.FindAssets($"t:Script {nameof(ROS2ForUnity)}");
92+
if (assets.Length == 1)
93+
{
94+
var assetPath = AssetDatabase.GUIDToAssetPath(assets[0]);
95+
pluginPath = Path.GetDirectoryName(Path.GetDirectoryName(assetPath));
96+
// We found "Ros2ForUnity/Scripts/[file].cs", go up two levels
97+
}
98+
else
99+
{
100+
pluginPath = Application.dataPath;
101+
if (InEditor())
102+
{
103+
pluginPath += separator + ros2ForUnityAssetFolderName;
104+
}
94105
}
106+
95107
return pluginPath;
96108
}
97109

0 commit comments

Comments
 (0)