| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| using System; |
| using System.Linq; |
| using System.Xml; |
| using UnityEngine; |
|
|
| namespace Mujoco { |
|
|
| public class MjUserSensor : MjBaseSensor { |
|
|
| public String Name; |
| public int Dimension = 0; |
| public String UserData; |
|
|
| protected override XmlElement ToMjcf(XmlDocument doc) { |
| if (Dimension == 0) { |
| throw new MissingFieldException("Dimension should be larger than 0."); |
| } |
| var mjcf = doc.CreateElement("user"); |
| mjcf.SetAttribute("name", Name); |
| mjcf.SetAttribute("dim", $"{Dimension}"); |
| if (!String.IsNullOrEmpty(UserData)) { |
| |
| mjcf.SetAttribute("user", UserData); |
| } |
| return mjcf; |
| } |
|
|
| protected override void FromMjcf(XmlElement mjcf) { |
| Name = mjcf.GetAttribute("name"); |
| int.TryParse(mjcf.GetAttribute("dim"), out Dimension); |
| UserData = mjcf.GetAttribute("user"); |
| } |
| } |
| } |
|
|