private IEnumerator InitializeGroup() { if (this._initializableObjects == null) { yield break; } var enumerator = this._initializableObjects.GetEnumerator(); while (enumerator.MoveNext()) { if (enumerator.Current == null) { TimiDebug.LogErrorColor("Initializable object list in group " + this._groupName + " has a null object", LogColor.red); continue; } IInitializable initializable = enumerator.Current.GetComponent <IInitializable>(); if (initializable == null) { TimiDebug.LogErrorColor(enumerator.Current.name + " has no " + typeof(IInitializable).Name, LogColor.red); continue; } TimiDebug.LogColor("Initializing " + enumerator.Current.name, LogColor.green); initializable.StartInitialize(); if (this._serialLoad) { while (!initializable.IsFullyInitialized) { yield return(null); } } } }
private void Import(string inputFilePath, string outputFilePath, float apparentMagnitudeCutoff) { CSVReader.CSVResult csvResult = CSVReader.ReadCSVFile(inputFilePath); if (csvResult == null) { return; } int numStarsImported = 0; StarsData starsData = new StarsData(); starsData.stars = new List <StarData>(); var enumerator = csvResult.items.GetEnumerator(); while (enumerator.MoveNext()) { CSVReader.CSVItem item = enumerator.Current; float apparentMagnitude = float.Parse(item.values[APPARENT_MAGNITUDE_KEY]); if (apparentMagnitude > apparentMagnitudeCutoff) { continue; } ++numStarsImported; StarData starData = new StarData(); starData.common_name = item.values[COMMON_NAME_KEY]; starData.right_ascension = float.Parse(item.values[RIGHT_ASCENSION_KEY]); starData.declination = float.Parse(item.values[DECLINATION_KEY]); starData.distance_in_parsecs = float.Parse(item.values[DISTANCE_PARSEC_KEY]); starData.apparent_magnitude = float.Parse(item.values[APPARENT_MAGNITUDE_KEY]); starData.absolute_magnitude = float.Parse(item.values[ABSOLUTE_MAGNITUDE_KEY]); starData.constellation_name = item.values[CONSTELLATION_KEY]; starData.luminosity = float.Parse(item.values[LUMINOSITY_KEY]); starsData.stars.Add(starData); } FileStream fileStream = FileUtils.OpenFileStream(outputFilePath, FileMode.Create, FileAccess.Write); if (fileStream == null) { return; } Serializer.Serialize <StarsData>(fileStream, starsData); fileStream.Flush(); FileUtils.CloseFileStream(fileStream); TimiDebug.LogColor("Success! Imported " + numStarsImported.ToString() + " stars", LogColor.green); }
// TODO: Remove. This is only for debugging the star position calculations private void GenerateOneStar(MeshFilter meshFilter) { StarData star = AppDataModel.Instance.StarsData.GetStarDataByCommonName("Megrez"); TimiDebug.LogColor(star.right_ascension + " " + star.declination, LogColor.black); int numStars = 1; Vector3[] vertices = new Vector3[4 * numStars]; int[] triangles = new int[6 * numStars]; Vector2[] uvs = new Vector2[4 * numStars]; GenerateVerticesForOneStar(star, 0, vertices, triangles, uvs); Mesh mesh = new Mesh(); mesh.vertices = vertices; mesh.triangles = triangles; mesh.uv = uvs; meshFilter.mesh = mesh; }
// Use this for initialization private void Start() { if (AppDataModel.Instance.StarsData == null || AppDataModel.Instance.StarsData.GetAllStars() == null) { TimiDebug.LogErrorColor("No stars loaded", LogColor.red); } TimiDebug.LogColor("Loaded " + AppDataModel.Instance.StarsData.GetAllStars().Count + " stars", LogColor.cyan); var enumerator = AppDataModel.Instance.StarsData.GetAllStars().GetEnumerator(); while (enumerator.MoveNext()) { if (enumerator.Current.common_name.ToLower() == "sirius") { TimiDebug.LogColor(enumerator.Current.apparent_magnitude.ToString(), LogColor.cyan); } // if (!string.IsNullOrEmpty(enumerator.Current.common_name)) { // float apparentMagnitudeNormalized = Mathf.InverseLerp(this._apparentMagnitudeDimmest, this._apparentMagnitudeBrightest, enumerator.Current.apparent_magnitude); // TimiDebug.LogColor(enumerator.Current.common_name + ": " + enumerator.Current.apparent_magnitude + ", " + apparentMagnitudeNormalized, color); // } } }
private IEnumerator SerialInitialize() { if (this._initializables == null || this._initializables.Count == 0) { yield break; } float startTimeInSeconds = Time.fixedTime; var enumerator = this._initializables.GetEnumerator(); while (enumerator.MoveNext()) { IInitializable initializable = enumerator.Current as IInitializable; if (initializable == null) { GameObject asGO = enumerator.Current as GameObject; initializable = asGO.GetComponent <IInitializable>(); } if (initializable == null) { TimiDebug.LogErrorColor("Unable to convert " + enumerator.Current.name + " to " + typeof(IInitializable).Name, LogColor.red); continue; } TimiDebug.LogColor("Initializing " + initializable.GetName, LogColor.green); initializable.StartInitialize(); while (!initializable.IsFullyInitialized) { if ((Time.fixedTime - startTimeInSeconds) > MAX_TIMEOUT_IN_SECONDS) { TimiDebug.LogErrorColor("Initialization timed out waiting for: " + initializable.GetName, LogColor.red); yield break; } yield return(null); } } TimiDebug.LogColor("Initialization complete", LogColor.green); }