Dear Unity Community,
I want to draw Diagrams, for example the relation between time and distance in uniform motion. (and later fill that diagram in runtime, while motion is working)
I have at the moment no Unity Pro, so I can’t use GL. And I don’t want to use any user objects. I prefer to stay near the GUI Objects.
I found the DrawLine script: http://www.unifycommunity.com/wiki/index.php?title=DrawLine
And now I have the following code:
public static void DrawingDiagram (Rect diagramArea, int xAxisValue, int yAxisValue,
string xAxisLabelName, string yAxisLabelName, Color xAxisColor, Color yAxisColor, Vector2[] values) {
int maxSize = (int) Mathf.Min(diagramArea.width, diagramArea.height) - 40 ;
int leftLabelSpace = 20;
GUILayout.BeginArea ( diagramArea) ;
// drawing xAxis
Drawing.DrawLine ( new Vector2 ( 0 + (maxSize * 0.5f ) + 1 + leftLabelSpace, maxSize ),
new Vector2 ( 0 + maxSize + ( maxSize * 0.5f ) + leftLabelSpace , maxSize ), xAxisColor, 2.0f ) ;
// drawing yAxis
Drawing.DrawLine ( new Vector2 ( leftLabelSpace, maxSize ), new Vector2 ( leftLabelSpace, 0 ), yAxisColor, 2.0f ) ;
// drawing labels
GUI.Label ( new Rect (0,0,20,20), xAxisLabelName ) ;
GUI.Label ( new Rect ( maxSize + 30, maxSize - 10, 20, 20 ), yAxisLabelName ) ;
GUILayout.EndArea () ;
} // Drawig Diagram
I call this in my OnGUI() function, two times, because I want to have two (or later more) diagrams.
That is the result:
http://img10.myimg.de/diagramProblem12a2a.png
As you can see, there is a problem!
The problem is the following: Always, when I call the DrawLine (), after already called GUI Element, lile Label for example, the DrawLine is not drawn correctly.
The first example only works, because the DrawDiagram() funtion is the first call in my OnGUI() function.
So, I would be very glad, if anybody could help me to understand this behaviour and to find a solution.
At least I have to say, I got to know with Unity 4 weeks ago. So my knowledge is still basic.
meanwhile many thanks
Josephina
