Skip to content

Commit f177431

Browse files
committed
fix: saving method
1 parent 2e7103e commit f177431

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

Scripts/Editor/Core/CollectionSettings.cs

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public class CollectionSettings
2020
public bool WriteAddressableLoadingMethods;
2121

2222
private AssetImporter importer;
23-
private bool isDirty;
2423

2524
public CollectionSettings()
2625
{
@@ -56,7 +55,7 @@ public CollectionSettings(ScriptableObjectCollection targetCollection)
5655
WriteAsPartialClass = canBePartial;
5756
UseBaseClassForItems = false;
5857
EnforceIndirectAccess = false;
59-
isDirty = true;
58+
Save();
6059
}
6160

6261
public bool ShouldWriteAddressableLoadingMethods()
@@ -67,31 +66,27 @@ public bool ShouldWriteAddressableLoadingMethods()
6766
return WriteAddressableLoadingMethods;
6867
}
6968

70-
public void SetWriteAddressableLoadingMethods(bool shouldWriteAddressablesMethods)
71-
{
72-
if (WriteAddressableLoadingMethods == shouldWriteAddressablesMethods)
73-
return;
74-
75-
WriteAddressableLoadingMethods = shouldWriteAddressablesMethods;
76-
isDirty = true;
77-
}
78-
7969
public void SetImporter(AssetImporter targetImporter)
8070
{
8171
importer = targetImporter;
8272
}
8373

8474
public void Save()
8575
{
86-
if (!isDirty)
87-
return;
88-
8976
if (importer == null)
9077
return;
9178

9279
importer.userData = EditorJsonUtility.ToJson(this);
93-
importer.SaveAndReimport();
94-
isDirty = false;
80+
AssetDatabase.WriteImportSettingsIfDirty(importer.assetPath);
81+
}
82+
83+
public void SetWriteAddressableLoadingMethods(bool shouldWriteAddressablesMethods)
84+
{
85+
if (WriteAddressableLoadingMethods == shouldWriteAddressablesMethods)
86+
return;
87+
88+
WriteAddressableLoadingMethods = shouldWriteAddressablesMethods;
89+
Save();
9590
}
9691

9792
public void SetEnforceIndirectAccess(bool enforceIndirectAccess)
@@ -100,7 +95,7 @@ public void SetEnforceIndirectAccess(bool enforceIndirectAccess)
10095
return;
10196

10297
EnforceIndirectAccess = enforceIndirectAccess;
103-
isDirty = true;
98+
Save();
10499
}
105100

106101
public void SetStaticFilename(string targetNewName)
@@ -109,7 +104,7 @@ public void SetStaticFilename(string targetNewName)
109104
return;
110105

111106
StaticFilename = targetNewName;
112-
isDirty = true;
107+
Save();
113108
}
114109

115110
public void SetNamespace(string targetNamespace)
@@ -118,7 +113,7 @@ public void SetNamespace(string targetNamespace)
118113
return;
119114

120115
Namespace = targetNamespace;
121-
isDirty = true;
116+
Save();
122117
}
123118

124119
public void SetWriteAsPartialClass(bool writeAsPartial)
@@ -127,7 +122,7 @@ public void SetWriteAsPartialClass(bool writeAsPartial)
127122
return;
128123

129124
WriteAsPartialClass = writeAsPartial;
130-
isDirty = true;
125+
Save();
131126
}
132127

133128
public void SetUseBaseClassForItems(bool useBaseClass)
@@ -136,7 +131,7 @@ public void SetUseBaseClassForItems(bool useBaseClass)
136131
return;
137132

138133
UseBaseClassForItems = useBaseClass;
139-
isDirty = true;
134+
Save();
140135
}
141136

142137
public void SetParentFolderPath(string assetPath)
@@ -145,7 +140,7 @@ public void SetParentFolderPath(string assetPath)
145140
return;
146141

147142
ParentFolderPath = assetPath;
148-
isDirty = true;
143+
Save();
149144
}
150145
}
151146
}

0 commit comments

Comments
 (0)