Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Custom asset types

Discussion in 'Scripting' started by DryerLint, May 9, 2019.

  1. DryerLint

    DryerLint

    Joined:
    Feb 7, 2016
    Posts:
    68
    I am curious about what the formal workflow is for custom asset types, or custom data formats.

    Suppose I've made my own file format for indexed 4-bit (16 color) graphics, where each byte contains two pixels of image data. Let's call it "16C" format (e.g., a file might be called image.16C). How do I go about loading such a file into Unity? I don't want to simply convert the file into a .PNG and represent it as a Texture2D. I want my own class to represent it. Is this possible?

    Ideally, I would like Unity Editor's asset folder to recognize my special format, and perhaps even produce a thumbnail representing it (I expect I'd have to write my own thumbnail rendering function).

    Is this even possible? Do I use ScriptableWizard? Or perhaps ScriptableObject? Or something else?

    Thanks for any advice!
     
  2. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,903
  3. DryerLint

    DryerLint

    Joined:
    Feb 7, 2016
    Posts:
    68
    Thanks Lurking-Ninja!

    I'm actually familiar with ScriptedImporters. I made a mistake in my first post, I intended to mention them instead of ScriptableWizards.

    Anyway, that was the answer I sought. I was using them before, but I wasn't sure if they were well-suited to some data types.
     
  4. OlegHCP

    OlegHCP

    Joined:
    Mar 7, 2017
    Posts:
    44
    How to implement full texture inspector (like default one)? Or maybe there is a way to teach builtin TextureImporter to load a custom image format? It's editor is already implemented.

     
  5. fleity

    fleity

    Joined:
    Oct 13, 2015
    Posts:
    289
    @Hargrim_
    I don't have an exact answer for you but two possible approaches:
    1. Use reflection to get the built in importer and inspector, use those and add your custom stuff on top
    2. In the quite new UI toolkit Sample project I've noticed a drop down menu at the top of the texture importer to select between the regular texture importer, the psd / psb importer and an overriden version of the psd importer.. As I just recently discovered that myself I haven't really looked at the files yet to figure out how to use this feature but override importers sounds exactly like what you are looking for.
     
  6. OlegHCP

    OlegHCP

    Joined:
    Mar 7, 2017
    Posts:
    44
    I tried make something like that but unsuccessfully. For example CreateEditor(..) function returns null in this case. Maybe i did something wrong.
     
  7. fleity

    fleity

    Joined:
    Oct 13, 2015
    Posts:
    289
    I've used that CreateEditor in the past succesfully for extending built in component inspectors but indeed in this case (maybe even in general) the override approach from the ui sample project seems like the best way to pursue.

    I remember coming across this, looked promising as well: https://github.com/sr4dev/Unity-SpriteAssist
     
  8. OlegHCP

    OlegHCP

    Joined:
    Mar 7, 2017
    Posts:
    44
    Well, looks painful...