UrdfPlugin.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. © Siemens AG, 2018
  3. Author: Suzannah Smith (suzannah.smith@siemens.com)
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. <http://www.apache.org/licenses/LICENSE-2.0>.
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. */
  14. using System.Xml;
  15. using UnityEngine;
  16. namespace RosSharp.Urdf
  17. {
  18. public class UrdfPlugin : MonoBehaviour
  19. {
  20. [TextArea(maxLines: 8, minLines: 4)]
  21. public string PluginText;
  22. public static void Create(Transform parent, Plugin plugin = null)
  23. {
  24. UrdfPlugin urdfPlugin = parent.gameObject.AddComponent<UrdfPlugin>();
  25. if (plugin != null)
  26. urdfPlugin.PluginText = plugin.text;
  27. }
  28. public Plugin ExportPluginData()
  29. {
  30. if (PluginText == null || PluginText == "") return null;
  31. try
  32. {
  33. XmlDocument xDoc = new XmlDocument();
  34. xDoc.LoadXml(PluginText);
  35. return new Plugin(PluginText);
  36. }
  37. catch (XmlException e)
  38. {
  39. Debug.LogWarning("UrdfPlugin contains invalid XML. The contents of this plugin will not be " +
  40. "written to the URDF file.\nXML Error: " + e.Message, this);
  41. return null;
  42. }
  43. }
  44. }
  45. }