Skip to content

Commit

Permalink
add: fix for namespace generation
Browse files Browse the repository at this point in the history
  • Loading branch information
brunomikoski committed Oct 25, 2022
1 parent 0f98396 commit 0555c95
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

# [1.9.3]
### Add
- Automatically define namespace for static collection generated file based on `CollectionItem`

### Changed
- Fixed static static file generation to use `Type.FullName` instead of `Type.Name`

# [1.9.2]
### Changed
- Fixed compatibility issues with Unity 2021
Expand Down Expand Up @@ -349,6 +356,7 @@ public bool IsValidConsumable(Consumable consumable)
- First initial working version


[1.9.3]: https://github.com/badawe/ScriptableObjectCollection/releases/tag/v1.9.3
[1.9.2]: https://github.com/badawe/ScriptableObjectCollection/releases/tag/v1.9.2
[1.9.1]: https://github.com/badawe/ScriptableObjectCollection/releases/tag/v1.9.1
[1.9.0]: https://github.com/badawe/ScriptableObjectCollection/releases/tag/v1.9.0
Expand Down
13 changes: 13 additions & 0 deletions Scripts/Editor/Core/CollectionCustomEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,19 @@ private void DrawGeneratedFileName()
private void DrawGeneratedFileNamespace()
{
SerializedProperty fileNamespaceSerializedProperty = serializedObject.FindProperty("generateStaticFileNamespace");
if (string.IsNullOrEmpty(fileNamespaceSerializedProperty.stringValue))
{
if (collection != null)
{
string targetNamespace = collection.GetItemType().Namespace;
if (!string.IsNullOrEmpty(targetNamespace))
{
fileNamespaceSerializedProperty.stringValue = targetNamespace;
fileNamespaceSerializedProperty.serializedObject.ApplyModifiedProperties();
}
}
}

using (EditorGUI.ChangeCheckScope changeCheck = new EditorGUI.ChangeCheckScope())
{
string newFileName = EditorGUILayout.DelayedTextField("Namespace", fileNamespaceSerializedProperty.stringValue);
Expand Down
8 changes: 4 additions & 4 deletions Scripts/Editor/Utils/CodeGenerationUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,15 +306,15 @@ private static void WriteDirectAccessCollectionStatic(ScriptableObjectCollection
ScriptableObjectCollectionItem collectionItem = collection.Items[i];
Type type = useBaseClass ? collection.GetItemType() : collectionItem.GetType();
AppendLine(writer, indentation,
$"private static {type.Name} {collectionItem.name.Sanitize().FirstToLower()};");
$"private static {type.FullName} {collectionItem.name.Sanitize().FirstToLower()};");
}

AppendLine(writer, indentation);

string valuesName = $"Values";

AppendLine(writer, indentation,
$"public static {collection.GetType().Name} {valuesName}");
$"public static {collection.GetType().FullName} {valuesName}");

AppendLine(writer, indentation, "{");
indentation++;
Expand Down Expand Up @@ -343,7 +343,7 @@ private static void WriteDirectAccessCollectionStatic(ScriptableObjectCollection
Type type = useBaseClass ? collection.GetItemType() : collectionItem.GetType();

AppendLine(writer, indentation,
$"public static {type.Name} {collectionNameFirstUpper}");
$"public static {type.FullName} {collectionNameFirstUpper}");
AppendLine(writer, indentation, "{");
indentation++;
AppendLine(writer, indentation, "get");
Expand All @@ -353,7 +353,7 @@ private static void WriteDirectAccessCollectionStatic(ScriptableObjectCollection
AppendLine(writer, indentation, $"if ({privateStaticName} == null)");
indentation++;
AppendLine(writer, indentation,
$"{privateStaticName} = ({type.Name}){valuesName}.GetItemByGUID(\"{collectionItem.GUID}\");");
$"{privateStaticName} = ({type.FullName}){valuesName}.GetItemByGUID(\"{collectionItem.GUID}\");");
indentation--;
AppendLine(writer, indentation, $"return {privateStaticName};");
indentation--;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.brunomikoski.scriptableobjectcollection",
"displayName": "Scriptable Object Collection",
"version": "1.9.2",
"version": "1.9.3",
"unity": "2018.4",
"description": "A library to help improve the usability of Unity3D Scriptable Objects by grouping then into a collection and exposing then by code or nice inspectors!",
"keywords": [
Expand Down

0 comments on commit 0555c95

Please sign in to comment.