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 editor button

Discussion in 'Scripting' started by nbg_yalta, Jun 15, 2014.

  1. nbg_yalta

    nbg_yalta

    Joined:
    Oct 3, 2012
    Posts:
    378
    Hi, is there a way to add elements like button etc. to this pannel?
     
  2. smitchell

    smitchell

    Joined:
    Mar 12, 2012
    Posts:
    702
    There's a video from one of the unite events called advanced editor scripting, the dude shows you how to use reflection to do things within the editor like you want. So the answer to your question is yes you can do it as far as Im aware
     
  3. nbg_yalta

    nbg_yalta

    Joined:
    Oct 3, 2012
    Posts:
    378
    thnx, will check it up
     
  4. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,716
    Really? I checked how it's done inside, and it's all internal methods. Do you have a link to that dude who manage to add button there?
     
  5. smitchell

    smitchell

    Joined:
    Mar 12, 2012
    Posts:
    702
    Sure: https://www.youtube.com/watch?feature=player_detailpage&v=itkm-emb5tg#t=3253

    He doesn't actually show you how to do it but he talks about it, and if you watch the entire video he shows you how to use reflection to do things in the editor that aren't easily accessible
     
  6. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,716
    Trust me, I know how powerful reflection is... However, there's limit to it without falling into method injection.

    ARG! I just wasted I dunno how much time watching that video...
     
    Last edited: Jun 16, 2014
  7. nbg_yalta

    nbg_yalta

    Joined:
    Oct 3, 2012
    Posts:
    378
    So there is no a simple way to do something like this? To be honest, I don't know what is reflection and how to use it in this case, should I just forget about this idea? :D
     
  8. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,613
    If you give up when faced with a little method injection then you'll never get anything done, LightStriker :p

    There's no easy way to do this, yes. (If you want to add a button to the Scene View, then it's pretty easy by comparison).
     
  9. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,716
    Yeah... No.

    How many times have you done method hooking/injection on Unity's library?

    Just the GAC part is giving headache.
     
    Last edited: Jun 16, 2014
  10. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,716


    I managed to do it... But I probably ended up breaking just about every possible user agreements in existence. I'm 100% sure it could never be released on the Asset Store.

    Combination of CIL injection with event reflection.

    Right now, I can only add stuff on top of the existing items.
     
    Magiichan and smitchell like this.
  11. smitchell

    smitchell

    Joined:
    Mar 12, 2012
    Posts:
    702
    Oh it looks so weird ha! Just looks wrong, awesome for figuring it out tho :)
     
  12. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,716
    Maybe it looks weird because I didn't work much into placing the buttons properly. :p
     
  13. smitchell

    smitchell

    Joined:
    Mar 12, 2012
    Posts:
    702
    Ha I didn't even mean it like that, I'm just so used to that area being empty, been using unity too long ha!
     
  14. nbg_yalta

    nbg_yalta

    Joined:
    Oct 3, 2012
    Posts:
    378
    Awesome! Any chance you will share this?
     
  15. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,716
    I'm not sure yet how I would package that. Frankly, it's probably more related to a jailbreak than anything else.

    Basically, I create a .exe that take UnityEditor.dll and add stuff in it. In every class that has a OnGUI method, I added a OnBeforeGUI and OnAfterGUI events at the start and at the end of the method.

    This way, even if the class is internal, sealed or whatever, I can register a delegate to those events by reflection and draw stuff before and after the internal OnGUI.

    Now that I got my hand into editing an existing DLL, I just wonder how much I can go edit in there. Since I have access to every single OnGUI, I could basically add stuff... well... everywhere.

    Maybe it could be an open source project, because I sure can't sell that on the Asset Store. :p