浏览代码

example custom sensor

/develop/custom-ray-sensor
Ruo-Ping Dong 4 年前
当前提交
02b35d77
共有 2 个文件被更改,包括 58 次插入0 次删除
  1. 47
      com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensorComponentCustom3D.cs
  2. 11
      com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensorComponentCustom3D.cs.meta

47
com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensorComponentCustom3D.cs


using UnityEngine;
using UnityEngine.Serialization;
namespace Unity.MLAgents.Sensors
{
public class CustomRayPerceptionOutput : RayPerceptionOutput
{
public CustomRayPerceptionOutput()
{
CustomObservationSizePerRay = 3;
}
public override void GetCustomObservationData(RayOutput rayOutput, float[] buffer)
{
var rb = rayOutput.HitGameObject.GetComponent<Rigidbody>();
if (rb != null)
{
buffer[0] = rb.velocity.x;
buffer[1] = rb.velocity.z;
buffer[2] = rb.mass;
}
}
}
/// <summary>
/// A component for Custom 3D Ray Perception.
/// </summary>
[AddComponentMenu("ML Agents/Custom Ray Perception Sensor 3D", (int)MenuGroup.Sensors)]
public class RayPerceptionSensorComponentCustom3D : RayPerceptionSensorComponent3D
{
public override ISensor[] CreateSensors()
{
var rayPerceptionInput = GetRayPerceptionInput();
var rayPerceptionOutput = new CustomRayPerceptionOutput();
m_RaySensor = new RayPerceptionSensor(SensorName, rayPerceptionInput, rayPerceptionOutput);
if (ObservationStacks != 1)
{
var stackingSensor = new StackingSensor(m_RaySensor, ObservationStacks);
return new ISensor[] { stackingSensor };
}
return new ISensor[] { m_RaySensor };
}
}
}

11
com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensorComponentCustom3D.cs.meta


fileFormatVersion: 2
guid: a1aeaa2bcb3974a44898e86dae3193d3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存