@@ -19,6 +19,8 @@ public static class CodeGenerationUtility
1919 private const string PrivateValuesName = "cachedValues" ;
2020 private const string PublicValuesName = "Values" ;
2121 private const string HasCachedValuesName = "hasCachedValues" ;
22+ private const string ExtensionOld = ".cs" ;
23+ private const string ExtensionNew = ".g.cs" ;
2224
2325
2426 public static bool CreateNewScript (
@@ -339,7 +341,19 @@ public static void GenerateIndirectAccessForCollectionItemType(string collection
339341 string fileName = $ "{ collectionName } IndirectReference";
340342
341343 AssetDatabaseUtils . CreatePathIfDoesntExist ( targetFolder ) ;
342- using ( StreamWriter writer = new StreamWriter ( Path . Combine ( targetFolder , $ "{ fileName } .g.cs") ) )
344+
345+ string targetFileName = Path . Combine ( targetFolder , fileName ) ;
346+
347+ // Delete any existing files that have the old deprecated extension.
348+ string deprecatedFileName = targetFileName + ExtensionOld ;
349+ if ( AssetDatabase . AssetPathExists ( deprecatedFileName ) )
350+ {
351+ Debug . Log ( $ "Supposed to delete deprecated Indirect Access file '{ deprecatedFileName } '") ;
352+ AssetDatabase . DeleteAsset ( deprecatedFileName ) ;
353+ }
354+
355+ targetFileName += ExtensionNew ;
356+ using ( StreamWriter writer = new StreamWriter ( targetFileName ) )
343357 {
344358 int indentation = 0 ;
345359 List < string > directives = new List < string > ( ) ;
@@ -385,7 +399,19 @@ public static void GenerateStaticCollectionScript(ScriptableObjectCollection col
385399
386400
387401 AssetDatabaseUtils . CreatePathIfDoesntExist ( finalFolder ) ;
388- using ( StreamWriter writer = new StreamWriter ( Path . Combine ( finalFolder , $ "{ fileName } .g.cs") ) )
402+
403+ string finalFileName = Path . Combine ( finalFolder , fileName ) ;
404+
405+ // Delete any existing files that have the old deprecated extension.
406+ string deprecatedFileName = finalFileName + ExtensionOld ;
407+ if ( File . Exists ( deprecatedFileName ) )
408+ {
409+ Debug . Log ( $ "Supposed to delete deprecated Static Access file '{ deprecatedFileName } '") ;
410+ AssetDatabase . DeleteAsset ( deprecatedFileName ) ;
411+ }
412+
413+ finalFileName += ExtensionNew ;
414+ using ( StreamWriter writer = new StreamWriter ( finalFileName ) )
389415 {
390416 int indentation = 0 ;
391417
@@ -629,7 +655,7 @@ public static bool DoesStaticFileForCollectionExist(ScriptableObjectCollection c
629655 {
630656 return File . Exists ( Path . Combine (
631657 AssetDatabase . GetAssetPath ( SOCSettings . Instance . GetParentDefaultAssetScriptsFolderForCollection ( collection ) ) ,
632- $ "{ SOCSettings . Instance . GetStaticFilenameForCollection ( collection ) } .g.cs ") ) ;
658+ $ "{ SOCSettings . Instance . GetStaticFilenameForCollection ( collection ) } { ExtensionNew } ") ) ;
633659 }
634660 }
635- }
661+ }
0 commit comments