-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGraphController.cs
More file actions
50 lines (42 loc) · 1.32 KB
/
GraphController.cs
File metadata and controls
50 lines (42 loc) · 1.32 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
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System;
using UnityEngine;
public class GraphController : MonoBehaviour {
public GameObject point;
public Material[] colors;
public string filePath;
public int maxPoints = 100;
public float scale = 1f;
// Use this for initialization
void Start () {
GenerateGraph(filePath);
}
void GenerateGraph(string path)
{
StreamReader reader = new StreamReader(filePath, Encoding.Default);
string line;
int index = 0;
do
{
line = reader.ReadLine();
if (line != null)
{
float[] pos = Array.ConvertAll(line.Split(','), float.Parse);
SpawnPoint(new Vector3(pos[0] * scale, pos[1] * scale, pos[2] * scale/3), (int) pos[3], index);
}
index++;
}
while (line != null && index < maxPoints);
reader.Close();
}
void SpawnPoint(Vector3 pos, int color, int index)
{
GameObject newPoint = Instantiate(point, pos, Quaternion.identity, transform);
MeshRenderer renderer = newPoint.GetComponent<MeshRenderer>();
newPoint.GetComponent<PointController>().SetIndex(index);
renderer.material = colors[color%10];
}
}