Skip to content

Commit c694489

Browse files
authored
Merge pull request #6 from LibraStack/develop
Fix #5. Enum default value issue.
2 parents d54635d + 8c8b63e commit c694489

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

src/UnityUxmlGenerator.UnityPackage/Assets/Plugins/UnityUxmlGenerator/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "com.chebanovdd.unityuxmlgenerator",
33
"displayName": "Unity Uxml Generator",
44
"author": { "name": "ChebanovDD", "url": "https://github.com/ChebanovDD" },
5-
"version": "0.0.1",
5+
"version": "0.0.2",
66
"unity": "2018.4",
77
"description": "The Unity Uxml Generator allows you to generate 'UxmlFactory' and 'UxmlTraits' source code for a custom 'VisualElement'. Just mark elements with [UxmlElement] and [UxmlAttribute] attributes.",
88
"keywords": [ "uxml", "source", "generator" ]

src/UnityUxmlGenerator/UxmlGenerator.Traits.cs

+10-7
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private static UxmlAttributeInfo GetAttributeInfo(GeneratorExecutionContext cont
130130

131131
var info = new UxmlAttributeInfo
132132
{
133-
TypeIdentifier = GetPropertyTypeIdentifier(context, property, out var typeSyntax),
133+
TypeIdentifier = GetPropertyTypeIdentifier(context, property, out var typeSyntax, out var typeNamespace),
134134
PrivateFieldName = propertyName.ToPrivateFieldName(),
135135
AttributeUxmlName = propertyName.ToDashCase()
136136
};
@@ -168,31 +168,33 @@ private static UxmlAttributeInfo GetAttributeInfo(GeneratorExecutionContext cont
168168
return info;
169169
}
170170

171-
info.DefaultValueAssignmentExpression = IdentifierName(uxmlAttributeDefaultValue);
171+
info.DefaultValueAssignmentExpression = IdentifierName($"global::{typeNamespace}.{uxmlAttributeDefaultValue}");
172172
return info;
173173
}
174174

175175
private static string GetPropertyTypeIdentifier(GeneratorExecutionContext context,
176-
BasePropertyDeclarationSyntax property, out TypeSyntax? typeSyntax)
176+
BasePropertyDeclarationSyntax property, out TypeSyntax? typeSyntax, out string? typeNamespace)
177177
{
178178
switch (property.Type)
179179
{
180180
case PredefinedTypeSyntax predefinedType:
181181
{
182-
var propertyTypeIdentifier = predefinedType.Keyword.Text.FirstCharToUpper();
183-
184182
typeSyntax = predefinedType;
183+
typeNamespace = default;
184+
185+
var propertyTypeIdentifier = predefinedType.Keyword.Text.FirstCharToUpper();
185186

186187
return $"Uxml{propertyTypeIdentifier}AttributeDescription";
187188
}
188189

189190
case IdentifierNameSyntax customTypeSyntax:
190191
{
192+
typeSyntax = customTypeSyntax;
193+
typeNamespace = customTypeSyntax.GetTypeNamespace(context);
194+
191195
var type = customTypeSyntax.Identifier.Text;
192-
var typeNamespace = customTypeSyntax.GetTypeNamespace(context);
193196
var propertyTypeText = $"global::{typeNamespace}.{type}";
194197

195-
typeSyntax = customTypeSyntax;
196198

197199
return propertyTypeText == UnityColorTypeFullName
198200
? UxmlColorAttributeDescription
@@ -201,6 +203,7 @@ private static string GetPropertyTypeIdentifier(GeneratorExecutionContext contex
201203

202204
default:
203205
typeSyntax = default;
206+
typeNamespace = default;
204207
return property.Type.GetText().ToString().Trim();
205208
}
206209
}

0 commit comments

Comments
 (0)