From fcc8a789225a08c60a22d3ba3c6be150efb25318 Mon Sep 17 00:00:00 2001 From: Roy Theunissen Date: Sat, 24 May 2025 11:44:24 +0200 Subject: [PATCH 1/4] Fixed the incorrect namespace being assumed for collections --- Scripts/Editor/Core/CollectionSettings.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Scripts/Editor/Core/CollectionSettings.cs b/Scripts/Editor/Core/CollectionSettings.cs index eef3c01..6e6a331 100644 --- a/Scripts/Editor/Core/CollectionSettings.cs +++ b/Scripts/Editor/Core/CollectionSettings.cs @@ -29,7 +29,7 @@ public CollectionSettings(ScriptableObjectCollection targetCollection) { Guid = targetCollection.GUID; string targetNamespace = targetCollection.GetItemType().Namespace; - if (!string.IsNullOrEmpty(SOCSettings.Instance.NamespacePrefix)) + if (string.IsNullOrEmpty(targetNamespace) && !string.IsNullOrEmpty(SOCSettings.Instance.NamespacePrefix)) targetNamespace = $"{SOCSettings.Instance.NamespacePrefix}"; Namespace = targetNamespace; @@ -143,4 +143,4 @@ public void SetParentFolderPath(string assetPath) Save(); } } -} \ No newline at end of file +} From c7f09ca1cca26c8b33481e2e204d888987b9b23b Mon Sep 17 00:00:00 2001 From: Roy Theunissen Date: Sat, 24 May 2025 12:05:01 +0200 Subject: [PATCH 2/4] Fixed static access overwriting the collection definition --- Scripts/Editor/Core/CollectionSettings.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scripts/Editor/Core/CollectionSettings.cs b/Scripts/Editor/Core/CollectionSettings.cs index 6e6a331..241f16e 100644 --- a/Scripts/Editor/Core/CollectionSettings.cs +++ b/Scripts/Editor/Core/CollectionSettings.cs @@ -47,7 +47,7 @@ public CollectionSettings(ScriptableObjectCollection targetCollection) bool canBePartial = CodeGenerationUtility.CheckIfCanBePartial(targetCollection, ParentFolderPath); - if (!canBePartial) + if (canBePartial) StaticFilename = $"{targetCollection.GetType().Name}Static".FirstToUpper(); else StaticFilename = $"{targetCollection.GetType().Name}".FirstToUpper(); From 284f34af1527c11ff5e5316a40971ea3bc4e83f0 Mon Sep 17 00:00:00 2001 From: Roy Theunissen Date: Sat, 24 May 2025 12:12:12 +0200 Subject: [PATCH 3/4] Deprecated generated files are now deleted to prevent compile errors. --- Scripts/Editor/Core/CodeGenerationUtility.cs | 34 +++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/Scripts/Editor/Core/CodeGenerationUtility.cs b/Scripts/Editor/Core/CodeGenerationUtility.cs index 391e329..bb9a1cf 100644 --- a/Scripts/Editor/Core/CodeGenerationUtility.cs +++ b/Scripts/Editor/Core/CodeGenerationUtility.cs @@ -19,6 +19,8 @@ public static class CodeGenerationUtility private const string PrivateValuesName = "cachedValues"; private const string PublicValuesName = "Values"; private const string HasCachedValuesName = "hasCachedValues"; + private const string ExtensionOld = ".cs"; + private const string ExtensionNew = ".g.cs"; public static bool CreateNewScript( @@ -339,7 +341,19 @@ public static void GenerateIndirectAccessForCollectionItemType(string collection string fileName = $"{collectionName}IndirectReference"; AssetDatabaseUtils.CreatePathIfDoesntExist(targetFolder); - using (StreamWriter writer = new StreamWriter(Path.Combine(targetFolder, $"{fileName}.g.cs"))) + + string targetFileName = Path.Combine(targetFolder, fileName); + + // Delete any existing files that have the old deprecated extension. + string deprecatedFileName = targetFileName + ExtensionOld; + if (AssetDatabase.AssetPathExists(deprecatedFileName)) + { + Debug.Log($"Supposed to delete deprecated Indirect Access file '{deprecatedFileName}'"); + AssetDatabase.DeleteAsset(deprecatedFileName); + } + + targetFileName += ExtensionNew; + using (StreamWriter writer = new StreamWriter(targetFileName)) { int indentation = 0; List directives = new List(); @@ -385,7 +399,19 @@ public static void GenerateStaticCollectionScript(ScriptableObjectCollection col AssetDatabaseUtils.CreatePathIfDoesntExist(finalFolder); - using (StreamWriter writer = new StreamWriter(Path.Combine(finalFolder, $"{fileName}.g.cs"))) + + string finalFileName = Path.Combine(finalFolder, fileName); + + // Delete any existing files that have the old deprecated extension. + string deprecatedFileName = finalFileName + ExtensionOld; + if (File.Exists(deprecatedFileName)) + { + Debug.Log($"Supposed to delete deprecated Static Access file '{deprecatedFileName}'"); + AssetDatabase.DeleteAsset(deprecatedFileName); + } + + finalFileName += ExtensionNew; + using (StreamWriter writer = new StreamWriter(finalFileName)) { int indentation = 0; @@ -629,7 +655,7 @@ public static bool DoesStaticFileForCollectionExist(ScriptableObjectCollection c { return File.Exists(Path.Combine( AssetDatabase.GetAssetPath(SOCSettings.Instance.GetParentDefaultAssetScriptsFolderForCollection(collection)), - $"{SOCSettings.Instance.GetStaticFilenameForCollection(collection)}.g.cs")); + $"{SOCSettings.Instance.GetStaticFilenameForCollection(collection)}{ExtensionNew}")); } } -} \ No newline at end of file +} From 09d1fc919f891e8d69d2092bc5f708175f16679f Mon Sep 17 00:00:00 2001 From: Roy Theunissen Date: Sat, 24 May 2025 12:16:58 +0200 Subject: [PATCH 4/4] Updated the changelog --- CHANGELOG.MD | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.MD b/CHANGELOG.MD index 17311f2..16ffa55 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ## [2.3.9] - 19/02/2025 +## Changed + - Fixed generated static access code overwriting the collection definition + - Pre 2.3.0 collections will now be assumed to want a namespace setting that is the same namespace as its item type + - When generating static/indirect access code using the new `.g.cs` suffix, existing static/indirect access code that uses the old `.cs` suffix is now automatically removed to prevent compile errors + ## Changed - Added some general fixes to validate Collection and Items have unique `LongGuid` - Fixed issues when after some operation with the context menu on the CollectionEditor items would not refresh properly