LoadSettingsData.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Cristian Pop - https://boxophobic.com/
  2. using System.Globalization;
  3. using UnityEditor;
  4. namespace Boxophobic.Utils
  5. {
  6. public partial class SettingsUtils
  7. {
  8. public static string LoadSettingsData(string settingsPath, string defaultData)
  9. {
  10. var settings = AssetDatabase.LoadAssetAtPath<SettingsData>(settingsPath);
  11. if (settings != null)
  12. {
  13. return settings.data;
  14. }
  15. else
  16. {
  17. return defaultData;
  18. }
  19. }
  20. public static int LoadSettingsData(string settingsPath, int defaultData)
  21. {
  22. var settings = AssetDatabase.LoadAssetAtPath<SettingsData>(settingsPath);
  23. if (settings != null)
  24. {
  25. int value;
  26. if (int.TryParse(settings.data, out value))
  27. {
  28. return value;
  29. }
  30. else
  31. {
  32. return defaultData;
  33. }
  34. }
  35. else
  36. {
  37. return defaultData;
  38. }
  39. }
  40. public static float LoadSettingsData(string settingsPath, float defaultData)
  41. {
  42. var settings = AssetDatabase.LoadAssetAtPath<SettingsData>(settingsPath);
  43. if (settings != null)
  44. {
  45. float value;
  46. if (float.TryParse(settings.data, out value))
  47. {
  48. return float.Parse(settings.data, CultureInfo.InvariantCulture);
  49. }
  50. else
  51. {
  52. return defaultData;
  53. }
  54. }
  55. else
  56. {
  57. return defaultData;
  58. }
  59. }
  60. }
  61. }