- Home /
Is it possible to reference a custom file type in the inspector?
Hi guys,
For context, I'm working on a strange project right now where all of the 3D models, bone layouts and animations are in formats not native to Unity. I've written custom asset importers for all of the file types, but now I'd like to link them up in a way that creates an easy workflow.
How can I reference a file that is NOT a UnityEngine.Object or .asset file in a script? For example, is it possible in code to have an inspector field that is looking for file types of .png, .jpg, .xx, .random, ect? If not, are there any workarounds?
Thanks in advance!
An EditorGUILayout.ObjectField can accept any type. It could be as simple as supplying the asset's type to the field's type argument.
Edit: I see you're looking for files, not imported assets. Not sure how to expose a field for those. I'd be interested to see, too.
No this doesn't work for object types that unity does not support.
However, I've created custom editor windows for editing and creating non-unity objects and storing/loading them through binary formatters. It is quite simple, but it doesn't work the way a normal inspector does. This is a habit I developed from working outside Unity, since all programs have data objects that need created/edited. Or at least most do.
@Tyler$$anonymous$$orton I think that he means to USE the custom file type. Just as an example, I have a crap ton of $$anonymous$$$$anonymous$$P files. They contain points and identification for each point. I would want the inspector to be able to display and edit the points and their IDs. Each ID referencing a model or effect area.
Answer by Arkaid · May 11, 2017 at 05:59 AM
AFAIK. No. However, unity takes files "as is", if they end with .bytes, and then you can read it with TextAsset.bytes
So, it might be a bit annoying, but you could do it so files add an extra extension so it ends in bytes. For example, say you had myfile.random
, you could make it so it's myfile.random.bytes
, and then work from there. It's bothersome, but it's the only workaround I can think of.
This still cannot be inspected in the inspector, only Resources can read .bytes files and it HAS TO of been formatted with a binary formatter, or the .bytes extension is meaningless.
I don't get what you want to do. You said "referenced" in the inspector. I made a test project and I can take any file (even a text file), slap the .bytes extension and assign it to a GameObject's script, then read it with TextAsset like so
public class TestAsset : $$anonymous$$onoBehaviour
{
public TextAsset theFile;
private void Start()
{
// do something here with theFile.bytes;
}
}
You don't need to use Resources this way. It just reads it when the project runs.
Sorry, yeah they can be referenced, I meant they cannot be inspected. However this still does not solve the OP's issue unless he is willing to binary format every one of his custom objects, which may not even be possible considering the [System.Serializable] limitation.
Thanks, this is exactly what I was looking for. Awesome!