Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
ValueRangePlotter.cs
Go to the documentation of this file.
1 using System;
2 using UnityEngine;
3 
4 #if UNITY_2019_1_OR_NEWER
5 
6 namespace droid.Runtime.Utilities.GameObjects.Plotting {
7  [ExecuteInEditMode]
8  public class ValueRangePlotter : MonoBehaviour {
9  Material _material;
10  [SerializeField] Shader _shader = null;
11  [SerializeField] Bounds _value_range = new Bounds(Vector3.zero, Vector3.one * 2);
12  static readonly Int32 _range = Shader.PropertyToID("_Range");
13 
14  void OnDestroy() {
15  if (this._material != null) {
16  if (Application.isPlaying) {
17  Destroy(this._material);
18  } else {
19  DestroyImmediate(this._material);
20  }
21  }
22  }
23 
24  public void OnRenderObject() {
25  if (this._material == null) {
26  this._material = new Material(this._shader);
27  this._material.hideFlags = HideFlags.DontSave;
28  }
29 
30  this._material.SetVector(_range,
31  new Vector4(this._value_range.min.x,
32  this._value_range.max.x,
33  this._value_range.center.y,
34  this._value_range.extents.y + this._value_range.center.y));
35 
36  this._material.SetPass(0);
37  Graphics.DrawProceduralNow(MeshTopology.LineStrip, 512);
38  }
39  }
40 }
41 #endif