SuperTiled2Unity icon indicating copy to clipboard operation
SuperTiled2Unity copied to clipboard

Add support for nested class types

Open FrankieF opened this issue 1 year ago • 2 comments

What?

Adds supports for nested custom type importing.

Why?

Tiled supports nested custom objects, but when imported with SuperTiled2Unity the object is put in a property with type class and the values are lost. In place of nested custom types we could just define each field on each custom property, but it is easier to use nested custom properties. For example

  • Character
    • CharacterDataId
    • FacingDirection
  • StrollingCharacter
    • Character (this includes the fields defined above)
      • CharacterDataId
      • FacingDirection
    • WalkDistanceX
    • WalkDistanceY

Now Character can be reused in many custom types in Tiled, but this data is not imported into Unity correctly.

How?

Adds a new CustomProperty type called ClassCustomProperty which contains a dictionary of values. When searching for a CustomProperty a new method GetCustomProperty is used which takes a key parameter. Regular CustomProperty ignore this parameter and return themselves, but the new ClassCustomProperty will search it's dictionary for the correct property.

Anything Else?

I'm aware this is not an ideal solution and the code is a little ugly. I saw on other PRs you are currently changing the code and converting this to use Unity's package manager system. I was unsure if this part of the code was affected. I'm more than happy to update the PR with any feedback or to change it to match your new code changes.

I think a better solution would have been to convert CustomProperty to some kind of holder class where the key is supplied and the holder finds the customer property. This would allow things like dictionary or list properties, but I do not think Tiled supports those things and it felt like overkill here.

I've also never used this XML library before so please let me know if there is a better way then calling Get Descendants.

FrankieF avatar Feb 11 '24 12:02 FrankieF

Any updates or thoughts?

FrankieF avatar Mar 02 '24 11:03 FrankieF

Hi there, @FrankieF. I'm sorry I haven't looked at this yet. One of the things I have planned to work on "soon" is a complete revamp of the custom properties in ST2U. I'd like to go with something that (automatically) generates C# classes from the Tiled project properties. That should make it a lot easier to work with custom properties in your Unity project.

Seanba avatar Mar 11 '24 17:03 Seanba