robotron2084 / animation-retargeting

An animation retargeting utility for the Unity game engine.
MIT License
83 stars 15 forks source link

Upgraded package for newer Unity versions and fixed issues with the IMGUI codepath #3

Open NPatch opened 9 months ago

NPatch commented 9 months ago

There are two issues with the package currently. 1) In newer versions AnimationRetargetingData does not persist when manipulated by the EditorWindow (#1) 2) Newer Unity versions have converted to UI Toolkit mostly (or are in the process).

About 1), not entirely sure how it happened. Usually you call serializedObject.Update in the start of OnGUI and ApplyModifiedProperties at the end. I know that you technically create the serializedObject every time so it's akin to Update, but somehow the changes made within the Drawers were not communicated back from the Drawers to the serializedObject in order to actually ApplyModifiedProperties. To counter that, we Update and Apply within each Drawer and also in the EditorWindow's OnGUI.

For 2), created a UI Toolkit version of the tool. Tried to reuse as much as possible.

To allow for backwards compatibility, there's some use of preprocessor conditionals. By default it uses the IMGUI version, but whoever wishes can switch to the UI Toolkit version by adding the ANIMATION_RETARGETING_UTILITY_UITOOLKIT definition in Project Settings -> Scripting Define Symbols.

Let me know what you think about this.

NPatch commented 9 months ago

Switched to draft because I noticed an issue with the IMGUI version not showing the correct AnimRetargetData when it's a preset.

NPatch commented 9 months ago

Did you ever look at AnimationUtility class? Specifically AnimationUtility.GetCurveBindings and AnimationUtility.GetEditorCurve and SetEditorCurve.

Path and Attribute names are given in the EditorCurveBinding class which can be altered through SetEditorCurve.

I'm thinking you don't have to do straight up SerializedProperty lookups with .Next etc.