Skip to content

Commit a4342d7

Browse files
authored
Merge pull request #168 from brunomikoski/feature/smoother-migration-to-2-3-0
Feature/smoother migration to 2 3 0
2 parents 05f4f07 + 09d1fc9 commit a4342d7

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

CHANGELOG.MD

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88
## [2.3.9] - 19/02/2025
9+
## Changed
10+
- Fixed generated static access code overwriting the collection definition
11+
- Pre 2.3.0 collections will now be assumed to want a namespace setting that is the same namespace as its item type
12+
- 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
13+
914
## Changed
1015
- Added some general fixes to validate Collection and Items have unique `LongGuid`
1116
- Fixed issues when after some operation with the context menu on the CollectionEditor items would not refresh properly

Scripts/Editor/Core/CodeGenerationUtility.cs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

Scripts/Editor/Core/CollectionSettings.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public CollectionSettings(ScriptableObjectCollection targetCollection)
2929
{
3030
Guid = targetCollection.GUID;
3131
string targetNamespace = targetCollection.GetItemType().Namespace;
32-
if (!string.IsNullOrEmpty(SOCSettings.Instance.NamespacePrefix))
32+
if (string.IsNullOrEmpty(targetNamespace) && !string.IsNullOrEmpty(SOCSettings.Instance.NamespacePrefix))
3333
targetNamespace = $"{SOCSettings.Instance.NamespacePrefix}";
3434

3535
Namespace = targetNamespace;
@@ -47,7 +47,7 @@ public CollectionSettings(ScriptableObjectCollection targetCollection)
4747

4848
bool canBePartial = CodeGenerationUtility.CheckIfCanBePartial(targetCollection, ParentFolderPath);
4949

50-
if (!canBePartial)
50+
if (canBePartial)
5151
StaticFilename = $"{targetCollection.GetType().Name}Static".FirstToUpper();
5252
else
5353
StaticFilename = $"{targetCollection.GetType().Name}".FirstToUpper();
@@ -143,4 +143,4 @@ public void SetParentFolderPath(string assetPath)
143143
Save();
144144
}
145145
}
146-
}
146+
}

0 commit comments

Comments
 (0)