Merge pull request #947 from Balint-H:feature/unity-export

PiperOrigin-RevId: 545261978
Change-Id: I9b4b7eb8dc8fc58581a83435c31bd96384c11a55
This commit is contained in:
Copybara-Service
2023-07-03 12:14:10 -07:00
3 changed files with 81 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: bb205616ac4ad592abaf06c8e97f8bb0
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,62 @@
// Copyright 2019 DeepMind Technologies Limited
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System.IO;
using System.Text;
using System.Xml;
using UnityEditor;
using UnityEngine;
namespace Mujoco
{
// Mujoco scenes exporter window.
public class MjExporterEditorWindow : EditorWindow
{
[MenuItem("Assets/Export MuJoCo Scene")]
public static void Apply()
{
if (Application.isPlaying || MjScene.InstanceExists)
{
Debug.LogWarning("MJCF exporting only available outside Play mode, and with no MjScene in the hierarchy.");
return;
}
string path = EditorUtility.SaveFilePanel("Save MJCF model", "", "model", "xml");
if (string.IsNullOrEmpty(path)) return;
// Due to singleton pattern, this creates a MjScene GameObject we need to remove at the end.
var mjcf = MjScene.Instance.CreateScene(skipCompile: true);
try
{
using (var stream = File.Open(path, FileMode.Create))
{
using (var writer = new XmlTextWriter(stream, new UTF8Encoding(false)))
{
writer.Formatting = Formatting.Indented;
mjcf.WriteContentTo(writer);
Debug.Log($"MJCF saved to {path}");
}
}
}
catch (IOException ex)
{
Debug.LogWarning("Failed to save Xml to a file: " + ex.ToString());
}
// Removing the added MjScene.
DestroyImmediate(MjScene.Instance.gameObject);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7695f261c02fdc343a09b219c92a6aab
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: