Skip to content

Commit

Permalink
Changed GetRos2ForUnityPath() to allow dynamic directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert-DEMCON committed Sep 15, 2023
1 parent 010d9e5 commit 896a9ba
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/Ros2ForUnity/Scripts/ROS2ForUnity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,24 @@ private string GetEnvPathVariableValue()
public static string GetRos2ForUnityPath()
{
char separator = Path.DirectorySeparatorChar;
string appDataPath = Application.dataPath;
string pluginPath = appDataPath;
string pluginPath = "";

if (InEditor()) {
pluginPath += separator + ros2ForUnityAssetFolderName;
var assets = AssetDatabase.FindAssets($"t:Script {nameof(ROS2ForUnity)}");
if (assets.Length == 1)
{
var assetPath = AssetDatabase.GUIDToAssetPath(assets[0]);
pluginPath = Path.GetDirectoryName(Path.GetDirectoryName(assetPath));
// We found "Ros2ForUnity/Scripts/[file].cs", go up two levels
}
else
{
pluginPath = Application.dataPath;
if (InEditor())
{
pluginPath += separator + ros2ForUnityAssetFolderName;
}
}

return pluginPath;
}

Expand Down

0 comments on commit 896a9ba

Please sign in to comment.