-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphExampleInGameErr.cs
More file actions
81 lines (64 loc) · 2.01 KB
/
GraphExampleInGameErr.cs
File metadata and controls
81 lines (64 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using UnityEngine;
using Rapid.Tools;
/// <summary>
/// This is a simple example of how you could draw graphs in-game.
/// </summary>
public class GraphExampleInGameErr : MonoBehaviour
{
GraphLogStyle _style;
GraphLogBuffer _buffer;
GraphGridInGame _drawer;
public Vector3 Amount = Vector3.up;
public Material RenderMaterial;
int _screenWidth = -1;
bool _wasScreenSpace = true;
void Awake()
{
_style = new GraphLogStyle("MyStyle", Color.white, Color.cyan, new []{Color.red, Color.green, Color.blue});
int bufferSize = 300;
_buffer = new GraphLogBuffer("MyGraph", "", 2, new []{"x","y"}, null, LogTimeMode.TimeSinceStartup, _style, bufferSize);
_drawer = new GraphGridInGame(camera, RenderMaterial, false, _buffer);
_drawer.SetGridColor(Color.white);
_drawer.Rows = 4;
_wasScreenSpace = !_drawer.ScreenSpace;
}
void UpdateAreaScreenSpace()
{
Vector2 inset = Vector2.one * 2f;
_drawer.SetArea(new Vector2(40f, 300f), new Vector2(Screen.width-400f, Screen.height-60f), inset, inset);
//_drawer.SetArea(new Vector2(Screen.width-400f, 300f), new Vector2(40f, Screen.height-40f), inset, inset); //goes to different direction
_screenWidth = Screen.width;
_drawer.Columns = _screenWidth / 100;
}
void UpdateAreaWorldSpace()
{
Vector2 inset = new Vector2(0.1f, 0.1f);
_drawer.SetArea(new Vector2(-8f, -2f), new Vector2(8f, 2f), inset, inset);
_drawer.Columns = 10;
}
void Update()
{
if(_drawer.ScreenSpace)
{
if(!_wasScreenSpace || _screenWidth != Screen.width)
UpdateAreaScreenSpace();
}
else if(_wasScreenSpace)
{
UpdateAreaWorldSpace();
}
_wasScreenSpace = _drawer.ScreenSpace;
transform.Rotate(Amount * Time.smoothDeltaTime);
Vector2 mousePos = Input.mousePosition;
_buffer.Log(mousePos.x, mousePos.y);
_drawer.SetTimeValueBounds(_buffer.TimeStart, _buffer.TimeLast, _buffer.Min, _buffer.Max);
}
void OnPostRender()
{
_drawer.Draw();
}
void OnGUI()
{
_drawer.ScreenSpace = GUILayout.Toggle(_drawer.ScreenSpace, "Screen space");
}
};