/
InfoWindowController.cs
139 lines (108 loc) · 3.44 KB
/
InfoWindowController.cs
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class InfoWindowController : MonoBehaviour {
public CameraBehaviour camBeh;
public StarBehaviour sb;
public Star star;
public Text textName;
public Text textSpectralType;
public Text textDistance;
public Text textConstelation;
public Text textLuminosity;
public Text textPlanetCount;
public Text textPlanetInfo;
public TextAsset planetData;
//test
public string hipp;
// Use this for initialization
void Start () {
if( planetData == null )
planetData = Resources.Load<TextAsset>("exoplanets");
}
// Update is called once per frame
void Update () {
}
void OnEnable(){
LoadInformation();
}
public void LoadInformation()
{
if( camBeh.target != null ) sb = camBeh.target.GetComponent<StarBehaviour>(); else Debug.Log("Null target!");
if( sb != null ) star = sb.star; else Debug.Log ("Star behaviour was null!");
if( star != null )
{
textName.text = star.name;
textDistance.text = "Distance: " + star.dist + "pc";
textSpectralType.text = "Spectral Type: " + star.spectralType;
textLuminosity.text = "Luminosity: " + star.luminosity + "suns";
textConstelation.text = "Constelation: " + star.constelation;
if( star.planetTextLoaded )
{
textPlanetInfo.text = star.planetText;
textPlanetCount.text = "Known Planets: " + star.planetCount;
textPlanetInfo.rectTransform.sizeDelta = new Vector2(textPlanetInfo.rectTransform.rect.width, star.planetCount*210);
}
else
{
if( star.has_planets )
{
if( star.hipp != null && star.hipp.Length > 0 )
{
StartCoroutine(loadPlanets ());
}
else
{
textPlanetCount.text = "Known Planets: 0";
textPlanetInfo.text = "";
}
}
else
{
textPlanetCount.text = "Known Planets: 0";
textPlanetInfo.text = "";
}
}
}
else Debug.Log ("StarBehaviour.star was null!");
}
IEnumerator loadPlanets()
{
if( planetData.text.Length <= 0 )
Debug.Log("Planet Data is missing!");
string [] f_content = planetData.text.Split('\n');//System.IO.File.ReadAllLines(Application.persistentDataPath + "/exoplanets.csv");
star.planetText = "\r";
textPlanetInfo.text = "Loading...";
textPlanetCount.text = "Known Planets: ...";
float height = 20;
int count = 0;
for( int i = 0; i < f_content.Length; i++ )
{
string[] row = f_content[i].Split(',');
if( row.Length >= 15 )
{
if( row[15].Length > 0 && star.hipp.TrimEnd().Length > 0 )
{
if( row[15].TrimEnd() == star.hipp.TrimEnd() || row[13] == star.name.TrimEnd() || row[14] == star.name.TrimEnd() )
{
star.planetText += row[0] + "\nClass: " + row[2] + " " + row[1] + "\nComposition: " + row[3] + "\nAtmosphere: " + row[4] + "\nMass: " + row[6] + "earths\nRadius: " + row[7] + "earth radii\nRelative Density: " + row[8] + "\nGravity: " + row[9] + "g\nOrbital Period: " + row[10] + "days\nOrbital Distance: " + row[12] + "au\nEccentricity: " + row[11] + "\nHabitable: " + row[5] + "\n\n";
count++;
height += 270;
yield return null;
}
}
}
}
star.planetCount = count;
star.planetTextLoaded = true;
textPlanetInfo.rectTransform.sizeDelta = new Vector2(textPlanetInfo.rectTransform.rect.width, height);
textPlanetInfo.text = star.planetText;
textPlanetCount.text = "Known Planets: " + count;
yield return null;
}
public void ButtonExit()
{
CameraBehaviour.guiTouch = true;
gameObject.SetActive(false);
}
}