freezy / VisualPinball.Engine

:video_game: Visual Pinball Engine for Unity
https://docs.visualpinball.org
GNU General Public License v3.0
415 stars 62 forks source link

Handling VPE specific prefabs tags metadata (could be extended to all metadata and all assets) #348

Closed Vroonsh closed 2 years ago

Vroonsh commented 2 years ago

This issue shows up while starting to work on the Prefab Library Editor.

Here's a view of a really early draft of the Prefab Library. PrefabLibrary_v0

This library works by looking for all PrefabLibrarySettingsAsset into the AssetDatabase and populate all prefabs from the directories pointed by all those settings assets.

For now i thought about 3 solutions which could match those requests :

  1. The tags are globally stored in the PrefabLibrarySettingsAssets.
    • Pros :
      • easy to setup and manage (all tags are together at the same place)
    • Cons :
      • specific solution for prefabs & tags only
      • need a directories monitoring to synchronize tags with any asset move/delete
      • the monitoring can be only done by the Editor or any other manager knowing all the PrefabLibrarySettingsAssets to transfer tags data alongside assets.
  2. The tags are stored into the userData field of the .meta file attached to the prefab, i made some tests with a Json serializable PinballMetaData class hosting a polymorphic list of PinballMetadataExtension (the first one is a PrefabLibraryExtension hosting a tag list).
    • Pros :
      • tags are following their prefabs
      • could work with other assets
      • PinballMetadata could be extended with other extensions if needed
      • another editor could expose the PinballMetaData embedded into any asset's userData
      • could be a real VPE specific metadata management, specifically made for our project
    • Cons :
      • have to be sure asset duplication is also duplicating the .meta userData (didn't find any Copy/Paste feature for assets in the editor, have to try while duplicating asset through scripts)
      • could collide with another userData usage (shouldn't happen)
      • need specific edition for this custom metadata system (probably mimic the current label edtion from Unity)
  3. The tags are stored as Unity labels into the .meta file.

    • Pros :

      • already editable through the asset properties editor, still didn't found a way to edit those outside from the Assets base directory (like in the HDRP package)

        image

      • stored as labels in the .meta file, already handled by Unity

      • should also be viewable in the Unity Asset Store (tbc)

    • Cons :
      • cannot edit elsewhere than Unity usual labels edition because of the internal protection of all label edition classes in UnityEditor, or classes has to be mirrored into VPE.Unity.Editor (which lead to nearly a custom edition solution).
      • cannot monitor & correct labels formatting in a convenient way, will have to be hooked when the asset is saved probably.
      • no categories supported in the edition, will rely on tag formatting with separator like those shown in the asset properties editor screenshot, no real label filtering so our labels will be aside the other default ones in lists.
      • Asset Properties Editor hide labels as long as the asset is not in the Assets/ hierarchy, cancel any edition/viewing of labels for package prefabs using this editor.

I'm not really found of the first solution (it was my first thought, the lazy one :)) I like the second one, maybe not easily traceable, could lead to data loss in case of weird assets manipulation, will probably need some heavy custom edition effort. The third one is kinda integrated into the Unity ecosystem but will have to be heavily customized (UnityEditor classes duplication) if we want to have a slightly different user experience while dealing with VPE assets.

While thinking about this particular topic I thought that it could be a wider discussion about VPE asset's metadata. What's your opinion on that ?

Cheers !

freezy commented 2 years ago

Good stuff. Sorry for the delayed response, was busy drawing plastics this weekend. ;)

I'd go for option 2. It's how Unity works, if you rename or move files outside of Unity, you're usually in trouble. Most obvious example are textures, where you typically adapt the import settings, which are reflected in the .meta file.

You can duplicate assets in the editor with Ctrl+D. It should copy the meta data as well.

Vroonsh commented 2 years ago

Yup agreed,

Just validated that userData is transfered when duplicating an asset (was quite confident on that :))

Was still wondering if the userData approach is the only valid one for extending already existing asset types or if extending importers could also works, will dig a little further.

Was also wondering if the multi-extension pinballmetadata i was planning wasn't quite overpowered, especially if we don't plan to mix several together in the same userData.

I've just the TagsMetadataExtension in mind for now, don't know if it could be mixed with another type of VPE specific metadata and also if it could be used on other asset types than prefabs, if not maybe it's too complicated, but well...it's upgradable :).