Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public static CustomProperty CloneProperty(this CustomProperty property)
var cloned = new CustomProperty();
cloned.m_Name = property.m_Name;
cloned.m_Type = property.m_Type;
cloned.m_PropertyType = property.m_PropertyType;
cloned.m_Value = property.m_Value;

return cloned;
Expand All @@ -37,6 +38,43 @@ public static int CombineFromSource(this List<CustomProperty> list, List<CustomP
}

public static int AddPropertiesFromType(this List<CustomProperty> list, string typeName, SuperImportContext importContext)
{
return list.AddPropertiesFromType(typeName, ST2USettings.instance.m_CustomObjectTypes);
}

public static int ResolveEnumStorageTypes(this List<CustomProperty> list, List<CustomEnumType> enumTypes)
{
if (list == null || enumTypes.IsEmpty())
{
return 0;
}

int numResolved = 0;
foreach (var property in list)
{
if (string.IsNullOrEmpty(property.m_PropertyType))
{
continue;
}

CustomEnumType enumType;
if (!enumTypes.TryGetCustomEnumType(property.m_PropertyType, out enumType))
{
continue;
}

var storageType = string.IsNullOrEmpty(enumType.m_StorageType) ? "string" : enumType.m_StorageType;
if (!string.Equals(property.m_Type, storageType, StringComparison.OrdinalIgnoreCase))
{
property.m_Type = storageType;
numResolved++;
}
}

return numResolved;
}

public static int AddPropertiesFromType(this List<CustomProperty> list, string typeName, List<CustomObjectType> objectTypes)
{
if (list == null)
{
Expand All @@ -49,7 +87,7 @@ public static int AddPropertiesFromType(this List<CustomProperty> list, string t
}

CustomObjectType objectType;
if (ST2USettings.instance.m_CustomObjectTypes.TryGetCustomObjectType(typeName, out objectType))
if (objectTypes.TryGetCustomObjectType(typeName, out objectType))
{
return CombineFromSource(list, objectType.m_CustomProperties);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public void AddSuperCustomProperties(GameObject go, XElement xProperties, SuperT

// Add properties from our object type (this should be last)
properties.AddPropertiesFromType(typeName, SuperImportContext);
properties.ResolveEnumStorageTypes(ST2USettings.instance.m_CustomEnumTypes);

// Sort the properties alphabetically
component.m_Properties = properties.OrderBy(p => p.m_Name).ToList();
Expand Down Expand Up @@ -127,6 +128,7 @@ protected override void InternalOnImportAsset()

RendererSorter = new RendererSorter();
SuperImportContext = new SuperImportContext(AssetImportContext, m_PixelsPerUnit, m_EdgesPerEllipse);
RefreshCustomObjectTypes();
}

protected override void InternalOnImportAssetCompleted()
Expand Down Expand Up @@ -174,5 +176,16 @@ protected void AssignUnityLayer(SuperCustomProperties properties)
}
}
}

protected T GetClassPropertyAs<T>(string className, string propertyName, T defaultValue) where T : IConvertible
{
return TiledCustomTypesJson.GetClassPropertyAs(className, propertyName, defaultValue, ST2USettings.instance.m_CustomObjectTypes);
}

private void RefreshCustomObjectTypes()
{
ST2USettings.instance.RefreshCustomObjectTypes();
ST2USettings.instance.RegisterCustomTypeDependencies(AssetImportContext);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public static CustomProperty LoadCustomProperty(XElement xProperty)

property.m_Name = xProperty.GetAttributeAs("name", "");
property.m_Type = xProperty.GetAttributeAs("type", "string");
property.m_PropertyType = xProperty.GetAttributeAs("propertytype", "");

// In some cases, value may be in the default attribute
property.m_Value = xProperty.GetAttributeAs("default", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ private void ProcessAttributes(XElement xTileset)
}

m_SuperTileset.m_CustomProperties = CustomPropertyLoader.LoadCustomPropertyList(xTileset.Element("properties"));
m_SuperTileset.m_CustomProperties.ResolveEnumStorageTypes(ST2USettings.instance.m_CustomEnumTypes);
}

private void BuildTileset(XElement xTileset)
Expand Down Expand Up @@ -211,6 +212,7 @@ private void ProcessTileElement(XElement xTile)
// Tiles can have custom properties (and properties inherited from their Type)
tile.m_CustomProperties = CustomPropertyLoader.LoadCustomPropertyList(xTile.Element("properties"));
tile.m_CustomProperties.AddPropertiesFromType(tile.m_Type, m_Importer.SuperImportContext);
tile.m_CustomProperties.ResolveEnumStorageTypes(ST2USettings.instance.m_CustomEnumTypes);

// Does the tile have any animation data?
var xAnimation = xTile.Element("animation");
Expand Down Expand Up @@ -282,6 +284,7 @@ private void ProcessObjectGroupElement(SuperTile tile, XElement xObjectGroup)
// Are there any properties on the collision object?
collision.m_CustomProperties = CustomPropertyLoader.LoadCustomPropertyList(xObject.Element("properties"));
collision.m_CustomProperties.AddPropertiesFromType(collision.m_ObjectType, m_Importer.SuperImportContext);
collision.m_CustomProperties.ResolveEnumStorageTypes(ST2USettings.instance.m_CustomEnumTypes);

var xPolygon = xObject.Element("polygon");
var xPolyline = xObject.Element("polyline");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ public class CustomObjectType
public List<CustomProperty> m_CustomProperties;
}

[Serializable]
public class CustomEnumType
{
public string m_Name;
public string m_StorageType;
public List<string> m_Values;
public bool m_ValuesAsFlags;
}

public static class CustomObjectTypeExtensions
{
public static bool TryGetCustomObjectType(this List<CustomObjectType> list, string type, out CustomObjectType customObjectType)
Expand All @@ -27,4 +36,19 @@ public static bool TryGetCustomObjectType(this List<CustomObjectType> list, stri
return customObjectType != null;
}
}

public static class CustomEnumTypeExtensions
{
public static bool TryGetCustomEnumType(this List<CustomEnumType> list, string type, out CustomEnumType customEnumType)
{
if (list.IsEmpty())
{
customEnumType = null;
return false;
}

customEnumType = list.FirstOrDefault(o => o.m_Name.Equals(type, StringComparison.OrdinalIgnoreCase));
return customEnumType != null;
}
}
}
Loading