Initial release of the Unity plugin.
PiperOrigin-RevId: 425947505
This commit is contained in:
committed by
Saran Tunyasuvunakool
parent
8ec3dd97a4
commit
6de9eafa13
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using UnityEditor;
|
||||
using UnityEditor.PackageManager;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mujoco {
|
||||
public class MujocoBinaryRetriever {
|
||||
|
||||
[InitializeOnLoadMethod]
|
||||
static void SubscribeToEvent() {
|
||||
// This causes the method to be invoked after the Editor registers the new list of packages.
|
||||
Events.registeredPackages += RegisteredPackagesEventHandler;
|
||||
}
|
||||
|
||||
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.1.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.1.1/lib/libmujoco_nogl.so.2.1.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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user