浏览代码

Implement custom cameras in Monitor (#1076)

/develop-generalizationTraining-TrainerController
Arthur Juliani 6 年前
当前提交
2eb5c66d
共有 1 个文件被更改,包括 37 次插入6 次删除
  1. 43
      unity-environment/Assets/ML-Agents/Scripts/Monitor.cs

43
unity-environment/Assets/ML-Agents/Scripts/Monitor.cs


static bool isInstantiated;
static GameObject canvas;
static Dictionary<Transform, Dictionary<string, DisplayValue>> displayTransformValues;
/// <summary>
/// Camera used to calculate GUI screen position relative to the target
/// transform.
/// </summary>
static Dictionary<Transform, Camera> transformCamera;
static Color[] barColors;
struct DisplayValue

/// <param name="value">The string value you want to display.</param>
/// <param name="target">The transform you want to attach the information to.
/// </param>
/// <param name="camera">Camera used to calculate GUI position relative to
/// the target. If null, `Camera.main` will be used.</param>
Transform target = null)
Transform target = null,
Camera camera = null)
{
if (!isInstantiated)
{

{
target = canvas.transform;
}
transformCamera[target] = camera;
if (!displayTransformValues.Keys.Contains(target))
{

/// <param name="value">The float value you want to display.</param>
/// <param name="target">The transform you want to attach the information to.
/// </param>
/// <param name="camera">Camera used to calculate GUI position relative to
/// the target. If null, `Camera.main` will be used.</param>
Transform target = null)
Transform target = null,
Camera camera = null)
{
if (!isInstantiated)
{

{
target = canvas.transform;
}
transformCamera[target] = camera;
if (!displayTransformValues.Keys.Contains(target))
{

/// <param name="displayType">The type of display.</param>
/// <param name="target">The transform you want to attach the information to.
/// </param>
/// <param name="camera">Camera used to calculate GUI position relative to
/// the target. If null, `Camera.main` will be used.</param>
DisplayType displayType = DisplayType.INDEPENDENT
DisplayType displayType = DisplayType.INDEPENDENT,
Camera camera = null
)
{
if (!isInstantiated)

{
target = canvas.transform;
}
transformCamera[target] = camera;
if (!displayTransformValues.Keys.Contains(target))
{

displayTransformValues = new Dictionary<Transform,
Dictionary<string, DisplayValue>>();
transformCamera = new Dictionary<Transform, Camera>();
}
/// <summary> <inheritdoc/> </summary>

continue;
}
// get camera
Camera cam = transformCamera[target];
if (cam == null)
{
cam = Camera.main;
}
float widthScaler = (Screen.width / 1000f);
float keyPixelWidth = 100 * widthScaler;
float keyPixelHeight = 20 * widthScaler;

Screen.width / 2 - keyPixelWidth, Screen.height);
if (!(target == canvas.transform))
{
Vector3 cam2obj = target.position - Camera.main.transform.position;
Vector3 cam2obj = target.position - cam.transform.position;
20f / (Vector3.Dot(cam2obj, Camera.main.transform.forward)));
Vector3 worldPosition = Camera.main.WorldToScreenPoint(
20f / (Vector3.Dot(cam2obj, cam.transform.forward)));
Vector3 worldPosition = cam.WorldToScreenPoint(
target.position + new Vector3(0, verticalOffset, 0));
origin = new Vector3(
worldPosition.x - keyPixelWidth * scale, Screen.height - worldPosition.y);

正在加载...
取消
保存