Search Unity

Is this possible? Drag-and-drop in editor for resource path only, not object reference

Discussion in 'Immediate Mode GUI (IMGUI)' started by Archie888, May 3, 2015.

  1. Archie888

    Archie888

    Joined:
    May 17, 2014
    Posts:
    41
    Hi,

    Could some sort of editor property type be made, where, when you drag a resource object into it, the property, the actual field of which would be a string value, would be set to the resource path, and not as a reference to that resource?

    My motive is that as I do know that any resources, when they are scene-linked to components, the resource will actually be loaded to memory when the object is loaded, and I would like to avoid this. However, I would like to have the visually explanative, designer-friendly power of the component configurations in-editor, instead of configurations being hidden deep into nested classes in code, or in some external files that you need to open and investigate, etc. etc.

    Also, if it would be possible to have the resource highlighted when pressing on the editor field would be absolutely great.

    Any info on this?

    Cheers,
    -A888
     
    tiantian-kaixin likes this.
  2. BMayne

    BMayne

    Joined:
    Aug 4, 2014
    Posts:
    186
    Hey there,

    Yes this is quite easy to do in fact. You can see the example I attached. You just keep your paths as string references but when you look at the object the inspector uses Resources.Load or AssetDatabase.load and displays an object field.If the user changes the object you get the path of the new object and save it to the string path reference.

    You can take this one step further and and check if the path is valid (if it's in the resources folder) and even try to find the object if it has moved.

    Cheers,
     

    Attached Files:

  3. Lauwisme

    Lauwisme

    Joined:
    Apr 1, 2014
    Posts:
    2
    Sorry to dig up this old post, but is this post maybe missing your code example? I for one would like to see it :)
     
  4. BMayne

    BMayne

    Joined:
    Aug 4, 2014
    Posts:
    186
    This is a super old thread but I get questions about it all the time. So I just made a public Github repository for AssetPathAttribute.

    Cheers,
    Byron
     
    tiantian-kaixin, sier_ua and dugmcdug like this.
  5. Nodrap

    Nodrap

    Joined:
    Nov 4, 2011
    Posts:
    83
    Oooo this was so close to what I was after. I don't suppose anyone would know if this can be tweaked to work with Scene files? Tried using a Scene type but it just returns null on the Object when selected (which I guess makes sense). I want to set up levels by dragging in the scene that it uses and just can't find a solution.
     
  6. BMayne

    BMayne

    Joined:
    Aug 4, 2014
    Posts:
    186
    Well a little late now but yes there is now a `SceneReference` type in the repo.
     
    tiantian-kaixin and sier_ua like this.
  7. sier_ua

    sier_ua

    Joined:
    Jan 19, 2017
    Posts:
    6
    Thank you for the great asset!
     
  8. praleks0000

    praleks0000

    Joined:
    Jan 4, 2013
    Posts:
    6
    Does it work for arrays?
     
  9. praleks0000

    praleks0000

    Joined:
    Jan 4, 2013
    Posts:
    6
    Just checked. Its great! Thanks for your job.