Search Unity

CustomEditor on prefab no more appears

Discussion in 'Prefabs' started by iperov, Sep 14, 2018.

  1. iperov

    iperov

    Joined:
    Dec 13, 2015
    Posts:
    36
    I have some custom logic on inspector prefabs , which instantiates prefabs on specific parent and focuses on it via button,
    Code (CSharp):
    1. [CustomEditor(typeof(SUIWindow), true)]
    2.         public class SUIWindowEditor : Editor
    3.         {
    4.             public override void OnInspectorGUI()
    5.             {            
    6.                 SUIWindow wnd = this.target as SUIWindow;
    7.  
    8.                 PrefabType prefab_type = PrefabUtility.GetPrefabType(wnd);
    9.                 if (prefab_type == PrefabType.Prefab)
    10.                 {
    11.                     if ( GUILayout.Button ("Instantiate") )
    12.                     {
    13.  
    14.                         SUIWindow inst_wnd = SUIWindow.create(wnd.GetType());
    15.                         Selection.activeObject = inst_wnd.gameObject;
    16.                     }
    17.                 } else
    but in new beta version this is no more works.
    and there is only one "Open prefab" button
    before:
    Unity_2018-09-14_18-15-50.jpg
    after:
    Unity_2018-09-14_17-37-53.jpg
     
    Last edited: Sep 14, 2018
    Deeeds likes this.
  2. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    old prefab system is just gone, as crazy as it sounds.
     
  3. iperov

    iperov

    Joined:
    Dec 13, 2015
    Posts:
    36
    ok, how I can make custom logic on NEW prefab system ?

    I need custom button near "Open prefab"
     
  4. iperov

    iperov

    Joined:
    Dec 13, 2015
    Posts:
    36
    cool beta support ! (no)
     
  5. iperov

    iperov

    Joined:
    Dec 13, 2015
    Posts:
    36
    anybody knows how to extend ".prefab" inspector GUI ?
     
  6. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,311
  7. iperov

    iperov

    Joined:
    Dec 13, 2015
    Posts:
    36
  8. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Adding a vote here, please expose this Unity. Need to be able to detect if the "prefab" is just selected in Project view and not in Scene view.
     
  9. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    So all that your script is doing is to instantiate prefab in the scene?

    I does seem a little wasteful to me that you would add a component to the prefab simply for editor tooling. This component will be included in the runtime which does not seem to be necessary .

    Maybe if you could explain a little more about your use case and tooling?
     
  10. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    You weren't talking to me, but I need the same thing. For me, here's my case.

    It's not a component on the prefab, it's an editor script for a Custom Inspector, for a component that's on the prefab. I don't add any components to the prefab for editor tooling.

    Here's why I made the button, for Core GameKit.
    -We have a prefabs folder in our Asset Store plugin. Some users who don't know any better just drag that prefab into their Scene and start modifying it (adding waves and spawners, etc). But it's still linked to the prefab in our plugins folder, which will be overwritten the next time they upgrade the plugin. They will lose all changes. Yes they could roll back if they use source control. A lot of users don't know that they need to make their own prefab in a different folder so unlink it from our "base" one so it won't get overwritten. This happened to a few customers and they were quite upset when it happened. Maybe no source control. I like to protect inexperienced users from doing such mistakes.

    So the solution we came up with, which worked until 2018.3, is:

    1) Detect that the prefab is selected not in a Scene, but in Project View so we can show the warning "do not drag this into your Scene. Click the Create button below". That button instantiates (which isn't linked to any prefab) the prefab, and you can make a prefab out of it, or not.

    The project view detection code was:
    if (PrefabUtility.GetPrefabAssetType(gObject) == PrefabType.Prefab) {
    // show warning and button.
    // abort.
    }
    // else normal inspector code

    Also wanted the mention that my editor script is quite long, handling the custom inspector for the script with all its sections. It aborts early and doesn't show any of that (just the warning and the button) if it's selected in Project View though. We did not add a custom inspector only for the button. That's only a tiny fraction of what it does - but that's the part that doesn't work any more.
     
    Last edited: Sep 20, 2018
    OliverVSmith likes this.
  11. SugoiDev

    SugoiDev

    Joined:
    Mar 27, 2013
    Posts:
    395
    Chiming in to say we also have a few things very similar to what @jerotas described.
     
  12. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,129
    Sadly currently it's not possible to do that anymore. I think the way to solve this problem at the moment is Unity make it directly enter prefab mode when selecting prefab at Project tab and directly exit prefab when selecting something other than prefab at Project tab or the blank area at Project tab. It also needs to provide configurable hotkey to allow quickly exit prefab mode.
     
    Last edited: Sep 21, 2018
  13. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    That would make it a little better. Upvoting your suggestion!
     
  14. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    I think that would be bad UX, you can use the standard OS keyboard shortcut when navigating in the Project Browser. On macOS "CMD+ArrowDown" or on Windows "Enter" will open the prefab.
     
  15. fidelsoto

    fidelsoto

    Joined:
    Aug 7, 2012
    Posts:
    87
    I want to add buttons below the "open prefab" button.
     
    OliverVSmith likes this.
  16. OliverVSmith

    OliverVSmith

    Joined:
    Nov 7, 2017
    Posts:
    51
    We're building a lot of custom workflows within the editor so we don't have to dig into menus everytime we want to create a new Data file based upon a prefab (for our modable props system).
    Not being able to extend or override the first level Prefab window is more than a little infuriating and if anything, ruins our UX