Custom Inspector or import script that creates serialised representation.

Hey - anyone know if this can be done? Two ideas for a solution, 1 solution needed.

Preferred idea 1:
idea 1

Create a Unity importer that can decode a json encoded file into a serialised blob - let’s say the blob is of type LevelStruct that has the following form (class or struct, not fussed):

public struct LevelStruct
{
    string name;
    float[] xPositions;
    float[] yPositions;
    float width;
    float height;
}

So I drop some files into the Project explorer and Unity converts my files (eg, myLevel_jsonfile.json_level) into decoded instances of LevelStruct that I can reference elsewhere ?

OR idea 2:

idea 2

Let’s say I have:

    [Serializable]
    public class WorldDescriptor
    {
        public string name;
        public List<TextAsset> levels;
    }

    public List<WorldDescriptor> worlds;

And in the inspector this looks like:

Inspector visualisation:

worlds
  size: 2
    world1
      name: world1
      levels:
        element1: 000_level1_json_text_asset
        element2: 001_level2_json_text_asset
        element3: 002_level3_json_text_asset
        .
        .
        .
        element100: 099_level100_json_text_asset
    world2
      name: world2
      levels:
        element1: 000_level1_json_text_asset
        element2: 001_level2_json_text_asset
        element3: 002_level3_json_text_asset
        .
        .
        .
        element100: 099_level100_json_text_asset

What’d I’d like to do is when I drop the json text files into the levels slots - is to process the json, process it and turn it into an array of structs the are a decoded version of the text assets (json).

So, I’d expose the

public List<WorldDescriptor> worlds;

To get populated in the editor inspector.

And and in editor script convert that into:

[Serializable]
public class WorldDescriptor_Decoded
{
  public string name;
  public List<LevelStruct> levels;
}

Where LevelStruct is:

public struct LevelStruct
{
    string name;
    float[] xPositions;
    float[] yPositions;
    float width;
    float height;
}

Then I can avoid the cost of doing the conversion at runtime.

Any ideas?

So I solved this using idea (2). Works well.

Is there any way to do idea (1)?