I've seen similar questions already asked, but none seemed to answer the core of my question, that is: is it possible to create a custom asset (i.e. an object extending `ScriptableObject`) and associate it with a specific file type?
As an example, if I have an object:
FooAsset.cs
using UnityEngine; public class FooAsset : ScriptableObject { public Object _asset; }
FooAssetEditor.cs
using UnityEditor; using UnityEngine; [CustomEditor(typeof(FooAsset))] public class FooAssetEditor : Editor { protected FooAsset _fooAsset; public override void OnInspectorGUI() { _fooAsset = (FooAsset) target; _fooAsset.Asset = (Object) EditorGUILayout.ObjectField( "Foo File", _fooAsset.Asset, typeof(Object)); } }
Is there any way that upon using the `EditorGUILayout.ObjectField(...)` method, or some other combination of methods/GUI objects that can I associate the `_asset` field on `FooAsset` with a completely arbitrary file type (e.g. `.foo`) that resides underneath my Assets folder?
I have a very simple custom editor right now doing what I want with the `ObjectField(...)` method, except that I can't see assets of type `.foo` within its selection window. (NB: my actual extension, not `.foo`, identifies a binary file--specifically an archive containing xml data. I haven't quite figured out how to even work with the file once I get it loaded in the manner I would like to load it in, but I'll cross that bridge when I come to it).
Any help is appreciated, if you can point me to projects, tutorials, or snippets of code that I may have missed in my search, I'd be forever grateful!
If there is no "easy" way to accomplish the above using what is already in Unity, perhaps someone can point me in the right direction for what I will need to customize?
I suspect I will have to do some combination of the following to achieve a custom field editor with behavior similar to that of the ObjectField:
- Create a custom editor which presents the user with a field (Drag-and-Drop enabled) to accept assets.
- A file browser/asset selection window that targets specifically only the file type (or types) I'm looking for, but is not necessarily confined to a specific folder (e.g. Resources).
So, what I've ended up doing so far is creating a preview window to load the asset from the file system which will read the custom asset through an EditorUtility.OpenFilePanel(...) call and then read in the bytes from the file. Its not quite as convenient as drag-and-drop, but it works. Now I just need to figure out how to return the loaded value. Once I have a complete solution I can post it.
– swquinnHi, I'm trying to read in the bytes from my file as well. Did you figure out how to get the loaded value?
– SONB@SONB I don't think I ever came up with a good way of registering a custom asset type with Unity 3D; I do have a "file loader" of sorts though. I forgot that I mentioned I was going to post a solution. Let me see if I can dig it up, I haven't touched that code recently. When I find it I'll post it as a possible answer.
– swquinnhi it's my first time to handle ScriptAbleObjects, I did Custom asset file and it works fine in a List<> but when i use hashtable() the hashtable is not found, i seems data is not stored when it comes to hash table..
– basil