Esempio n. 1
0
        private void LoadGenerationRangesFromFile(string file)
        {
            TextAsset textAss = Resources.Load(file) as TextAsset;

            string[] fileLines = textAss.text.Split('}');
            //new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries
            foreach (string s in fileLines)
            {
                if (s == string.Empty || s == "\n")
                {
                    continue;
                }

                string sp = FixJSONline(s);

                try
                {
                    StarGenerationRange range = JsonUtility.FromJson <StarGenerationRange>(sp);
                    StarGenRanges.Add(new KeyValuePair <int, int>(range.SpectralType, range.LuminosityType), range);
                }
                catch
                {
                    Debug.Log("error");
                }
            }
        }
Esempio n. 2
0
        private bool GenerateStarData(ref Star star)
        {
            if (StarGenRanges.ContainsKey(new KeyValuePair <int, int>(star.SpectralType, star.LuminosityType)))
            {
                StarGenerationRange range = StarGenRanges[new KeyValuePair <int, int>(star.SpectralType, star.LuminosityType)];

                star.MassSuns          = RandomGenerator.GenerateDouble(range.SunMassesMin, range.SunMassesMax);
                star.RadiusSuns        = RandomGenerator.GenerateDouble(range.SunRadiusesMin, range.SunRadiusesMax);
                star.LuminositySuns    = RandomGenerator.GenerateDouble(range.SunLuminositiesMin, range.SunLuminositiesMax);
                star.LifetimeMyears    = range.LifetimeMyears;
                star.HabitableZoneAU   = RandomGenerator.GenerateDouble(range.HabitableZoneAUMin, range.HabitableZoneAUMax);
                star.TemperatureKelvin = RandomGenerator.GenerateInt(range.TemperatureKelvinMin, range.TemperatureKelvinMax);

                string sName = StarNamesBase[RandomGenerator.GenerateInt(0, StarNamesBase.Count)] + " - " + RandomGenerator.GenerateInt(0, 1000000);
                if (!UsedStarNames.Contains(sName))
                {
                    UsedStarNames.Add(sName);
                    star.Name = sName;
                }
                else
                {
                    do
                    {
                        sName = StarNamesBase[RandomGenerator.GenerateInt(0, StarNamesBase.Count)] + " - " + RandomGenerator.GenerateInt(0, 1000000);
                    } while (UsedStarNames.Contains(sName));

                    UsedStarNames.Add(sName);
                    star.Name = sName;
                }


                return(true);
            }

            return(false);
        }