public static void LogError(string message) { #if DEBUG Logging.LogError(PREFIX + "Error: " + message); #endif // DEBUG }
// Load settings from file public static void LoadSettings(string filepath) { Logging.Debug.Log("Accessing Settings at " + filepath); // Try to read file contents into string // If no file exists, create one string settings = ""; if (!System.IO.File.Exists(filepath)) { // No settings file found, create one Logging.Debug.LogWarning("Settings file not found, creating one..."); try { System.IO.File.Create(filepath); } // If that fails then shit just hit the fan. React accordingly catch (Exception e) { Logging.LogError("Something went wrong while creating a settings file... :("); Logging.LogError(e.Message); Logging.LogError(e.StackTrace); return; } } // Read file to string try { settings = System.IO.File.ReadAllText(filepath); } // Something incredibly weird just happened catch (Exception e) { Logging.LogError("Something went wrong while reading a settings file... :("); Logging.LogError(e.Message); Logging.LogError(e.StackTrace); return; } // Empty settings dictionary m_settings.Clear(); // Splice settings string by newline characters, to get each line into a new array member string[] lines = settings.Split('\n'); foreach (string line in lines) // Loop through all lines { if (line == "") // If line is empty, ignore it (some editors add newlines when saving, this will combat that) { continue; } string[] vals = line.Split('='); // Split each line by the = character, to get a key and a value m_settings.Add(vals[0], Int32.Parse(vals[1])); // Store key and value in settings dictionary } Logging.Log("Settings loaded."); }