Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 30 additions & 4 deletions Scripts/Editor/Core/CodeGenerationUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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<string> directives = new List<string>();
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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}"));
}
}
}
}
6 changes: 3 additions & 3 deletions Scripts/Editor/Core/CollectionSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -143,4 +143,4 @@ public void SetParentFolderPath(string assetPath)
Save();
}
}
}
}