From e8a9db82b8a95aff45966b12450122c129447bf9 Mon Sep 17 00:00:00 2001 From: Tom Erez Date: Sun, 17 Jul 2022 20:47:29 -0700 Subject: [PATCH] Retrieve the binary only when the MuJoCo package is installed. PiperOrigin-RevId: 461524833 Change-Id: Ie8ca9dda71b35262f99688d02f71be77c251ea3e --- .../Runtime/Bindings/MujocoBinaryRetriever.cs | 52 ++++++++++--------- unity/package.json | 3 +- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/unity/Runtime/Bindings/MujocoBinaryRetriever.cs b/unity/Runtime/Bindings/MujocoBinaryRetriever.cs index e4b4d84d..c0055008 100644 --- a/unity/Runtime/Bindings/MujocoBinaryRetriever.cs +++ b/unity/Runtime/Bindings/MujocoBinaryRetriever.cs @@ -30,30 +30,34 @@ public class MujocoBinaryRetriever { static void RegisteredPackagesEventHandler( PackageRegistrationEventArgs packageRegistrationEventArgs) { - var mujocoPath = packageRegistrationEventArgs.added[0].assetPath; - if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { - if (AssetDatabase.LoadMainAssetAtPath(mujocoPath + "/mujoco.dylib") == null) { - File.Copy( - "/Applications/MuJoCo.app/Contents/Frameworks" + - "/mujoco.framework/Versions/Current/libmujoco.2.2.1.dylib", - mujocoPath + "/mujoco.dylib"); - AssetDatabase.Refresh(); - } - } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { - if (AssetDatabase.LoadMainAssetAtPath(mujocoPath + "/libmujoco.so") == null) { - File.Copy( - Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + - "/.mujoco/mujoco-2.2.1/lib/libmujoco.so.2.2.1", - mujocoPath + "/libmujoco.so"); - AssetDatabase.Refresh(); - } - } else { - if (AssetDatabase.LoadMainAssetAtPath(mujocoPath + "/mujoco.dll") == null) { - File.Copy( - Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + - "\\MuJoCo\\bin\\mujoco.dll", - mujocoPath + "\\mujoco.dll"); - AssetDatabase.Refresh(); + foreach (var packageInfo in packageRegistrationEventArgs.added) { + if (packageInfo.name.Equals("org.mujoco")) { + var mujocoPath = packageInfo.assetPath; + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { + if (AssetDatabase.LoadMainAssetAtPath(mujocoPath + "/mujoco.dylib") == null) { + File.Copy( + "/Applications/MuJoCo.app/Contents/Frameworks" + + "/mujoco.framework/Versions/Current/libmujoco.2.2.1.dylib", + mujocoPath + "/mujoco.dylib"); + AssetDatabase.Refresh(); + } + } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { + if (AssetDatabase.LoadMainAssetAtPath(mujocoPath + "/libmujoco.so") == null) { + File.Copy( + Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + + "/.mujoco/mujoco-2.2.1/lib/libmujoco.so.2.2.1", + mujocoPath + "/libmujoco.so"); + AssetDatabase.Refresh(); + } + } else { + if (AssetDatabase.LoadMainAssetAtPath(mujocoPath + "/mujoco.dll") == null) { + File.Copy( + Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + + "\\MuJoCo\\bin\\mujoco.dll", + mujocoPath + "\\mujoco.dll"); + AssetDatabase.Refresh(); + } + } } } } diff --git a/unity/package.json b/unity/package.json index 20deded3..7ee0cd94 100644 --- a/unity/package.json +++ b/unity/package.json @@ -12,5 +12,6 @@ "changelogUrl": "https://mujoco.readthedocs.io/en/latest/changelog.html", "documentationUrl": "https://mujoco.readthedocs.io/en/latest/unity.html", "license": "Apache-2.0", - "licensesUrl": "https://github.com/deepmind/mujoco/blob/main/LICENSE" + "licensesUrl": "https://github.com/deepmind/mujoco/blob/main/LICENSE", + "hideInEditor": false }