Retrieve the binary only when the MuJoCo package is installed.

PiperOrigin-RevId: 461524833
Change-Id: Ie8ca9dda71b35262f99688d02f71be77c251ea3e
This commit is contained in:
Tom Erez
2022-07-17 20:47:29 -07:00
committed by Copybara-Service
parent 0180d839a9
commit e8a9db82b8
2 changed files with 30 additions and 25 deletions
+28 -24
View File
@@ -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();
}
}
}
}
}
+2 -1
View File
@@ -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
}