diff --git a/CHANGELOG.MD b/CHANGELOG.MD index 2a7337b..dd52b99 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -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 @@ -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 diff --git a/Scripts/Editor/Core/CollectionCustomEditor.cs b/Scripts/Editor/Core/CollectionCustomEditor.cs index 183c8b9..83bb390 100644 --- a/Scripts/Editor/Core/CollectionCustomEditor.cs +++ b/Scripts/Editor/Core/CollectionCustomEditor.cs @@ -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); diff --git a/Scripts/Editor/Utils/CodeGenerationUtility.cs b/Scripts/Editor/Utils/CodeGenerationUtility.cs index 49353ad..0b6694a 100644 --- a/Scripts/Editor/Utils/CodeGenerationUtility.cs +++ b/Scripts/Editor/Utils/CodeGenerationUtility.cs @@ -306,7 +306,7 @@ 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); @@ -314,7 +314,7 @@ private static void WriteDirectAccessCollectionStatic(ScriptableObjectCollection string valuesName = $"Values"; AppendLine(writer, indentation, - $"public static {collection.GetType().Name} {valuesName}"); + $"public static {collection.GetType().FullName} {valuesName}"); AppendLine(writer, indentation, "{"); indentation++; @@ -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"); @@ -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--; diff --git a/package.json b/package.json index 9962739..f68dfc7 100644 --- a/package.json +++ b/package.json @@ -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": [