AufSerializableData.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. using System.Linq;
  3. namespace Asset_Cleaner {
  4. [Serializable]
  5. class AufSerializableData {
  6. public const int CurrentVersion = 1;
  7. public int Version;
  8. public bool MarkRed;
  9. public int RebuildCacheOnDemand;
  10. public bool ShowInfoBox;
  11. public string IgnorePathContainsCombined;
  12. public bool IgnoreMaterial;
  13. public bool IgnoreScriptable;
  14. static int BoolToInt(bool val) {
  15. return val ? 2 : 1;
  16. }
  17. static bool IntToBool(int val, bool defaultVal) {
  18. switch (val) {
  19. case 2:
  20. return true;
  21. case 1:
  22. return false;
  23. default:
  24. return defaultVal;
  25. }
  26. }
  27. public static AufSerializableData Default() {
  28. return new AufSerializableData {
  29. Version = CurrentVersion,
  30. MarkRed = true,
  31. ShowInfoBox = true,
  32. IgnorePathContainsCombined = "Gizmos;Resources;Editor;Asset Cleaner;Asset Usage Finder;",
  33. IgnoreMaterial = false,
  34. IgnoreScriptable = true,
  35. RebuildCacheOnDemand = 2,
  36. };
  37. }
  38. public static void OnSerialize(in Config src, out AufSerializableData result) {
  39. result = new AufSerializableData();
  40. result.Version = CurrentVersion;
  41. result.MarkRed = src.MarkRed;
  42. result.ShowInfoBox = src.ShowInfoBox;
  43. result.IgnorePathContainsCombined = src.IgnorePathContainsCombined;
  44. result.IgnoreMaterial = src.IgnoreMaterial;
  45. result.IgnoreScriptable = src.IgnoreScriptable;
  46. result.RebuildCacheOnDemand = BoolToInt(src.RebuildCacheOnDemand);
  47. }
  48. public static void OnDeserialize(in AufSerializableData src, ref Config result) {
  49. var def = Default();
  50. result.MarkRed = src.MarkRed;
  51. result.IgnorePathContainsCombined = src.IgnorePathContainsCombined;
  52. result.ShowInfoBox = src.ShowInfoBox;
  53. result.IgnorePathContains = result.IgnorePathContainsCombined
  54. .Split(';')
  55. .Select(s => s.Trim())
  56. .Where(s => !string.IsNullOrWhiteSpace(s))
  57. .ToArray();
  58. result.IgnoreMaterial = src.IgnoreMaterial;
  59. result.IgnoreScriptable = src.IgnoreScriptable;
  60. result.RebuildCacheOnDemand = IntToBool(src.RebuildCacheOnDemand, def.RebuildCacheOnDemand == 2);
  61. }
  62. public bool Valid() {
  63. return Version == CurrentVersion || IgnorePathContainsCombined == null;
  64. }
  65. }
  66. }