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
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "com.chebanovdd.unityuxmlgenerator",
"displayName": "Unity Uxml Generator",
"author": { "name": "ChebanovDD", "url": "https://github.com/ChebanovDD" },
"version": "0.0.1",
"version": "0.0.2",
"unity": "2018.4",
"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.",
"keywords": [ "uxml", "source", "generator" ]
Expand Down
17 changes: 10 additions & 7 deletions src/UnityUxmlGenerator/UxmlGenerator.Traits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private static UxmlAttributeInfo GetAttributeInfo(GeneratorExecutionContext cont

var info = new UxmlAttributeInfo
{
TypeIdentifier = GetPropertyTypeIdentifier(context, property, out var typeSyntax),
TypeIdentifier = GetPropertyTypeIdentifier(context, property, out var typeSyntax, out var typeNamespace),
PrivateFieldName = propertyName.ToPrivateFieldName(),
AttributeUxmlName = propertyName.ToDashCase()
};
Expand Down Expand Up @@ -168,31 +168,33 @@ private static UxmlAttributeInfo GetAttributeInfo(GeneratorExecutionContext cont
return info;
}

info.DefaultValueAssignmentExpression = IdentifierName(uxmlAttributeDefaultValue);
info.DefaultValueAssignmentExpression = IdentifierName($"global::{typeNamespace}.{uxmlAttributeDefaultValue}");
return info;
}

private static string GetPropertyTypeIdentifier(GeneratorExecutionContext context,
BasePropertyDeclarationSyntax property, out TypeSyntax? typeSyntax)
BasePropertyDeclarationSyntax property, out TypeSyntax? typeSyntax, out string? typeNamespace)
{
switch (property.Type)
{
case PredefinedTypeSyntax predefinedType:
{
var propertyTypeIdentifier = predefinedType.Keyword.Text.FirstCharToUpper();

typeSyntax = predefinedType;
typeNamespace = default;

var propertyTypeIdentifier = predefinedType.Keyword.Text.FirstCharToUpper();

return $"Uxml{propertyTypeIdentifier}AttributeDescription";
}

case IdentifierNameSyntax customTypeSyntax:
{
typeSyntax = customTypeSyntax;
typeNamespace = customTypeSyntax.GetTypeNamespace(context);

var type = customTypeSyntax.Identifier.Text;
var typeNamespace = customTypeSyntax.GetTypeNamespace(context);
var propertyTypeText = $"global::{typeNamespace}.{type}";

typeSyntax = customTypeSyntax;

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

default:
typeSyntax = default;
typeNamespace = default;
return property.Type.GetText().ToString().Trim();
}
}
Expand Down