public bool TryLoadHeights(string objsDir, char sep) { CategoryToScales = new Dictionary <string, List <HeightInformation> >(); string filename = objsDir + "/../heights.csv"; if (!File.Exists(filename)) { return(false); } var fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read); using (var streamReader = new StreamReader(fileStream, Encoding.UTF8)) { string line; while ((line = streamReader.ReadLine()) != null) { HeightInformation heightInformation = new HeightInformation(line, sep); if (!CategoryToScales.ContainsKey(heightInformation.Category)) { CategoryToScales.Add(heightInformation.Category, new List <HeightInformation>()); } CategoryToScales[heightInformation.Category].Add(heightInformation); } } return(true); }
/// <summary> /// Get the height of the category (e.g. plant) of a specific object. /// </summary> /// <param name="entry"></param> /// <returns></returns> public float GetHeight(ObjectEntry entry) { List <HeightInformation> heights = CategoryToScales[entry.Category]; // first entry of the heights contains a scale fallback height for the whole category HeightInformation categoryInformation = heights[0]; // fallback height of that category float height = UnityEngine.Random.Range(categoryInformation.Height.x, categoryInformation.Height.y); // try to find a specific height for the object of that category // take fallback height if nothing will be found foreach (HeightInformation heightInformation in heights) { if (!entry.FileName.Contains(heightInformation.ObjectClass)) { continue; } CultureInfo cultureInfo = new CultureInfo("en-US"); int idx = cultureInfo.CompareInfo.IndexOf(entry.FileName, heightInformation.ObjectClass, CompareOptions.IgnoreCase); if (idx == -1) { continue; } else { height = UnityEngine.Random.Range(heightInformation.Height.x, heightInformation.Height.y); break; } } return(height); }