Search Unity

[SOLVED]Editor GUI prefab select button

Discussion in 'Immediate Mode GUI (IMGUI)' started by kinetifex, Sep 13, 2009.

  1. kinetifex

    kinetifex

    Joined:
    Nov 4, 2008
    Posts:
    8
    Is there a way to make an editor button that will select prefab objects?

    I made a simple editor window that lists prefab objects and their properties in a table format to save me some clicks for editing values. I want to be able to click a button for a listed object that will then select the prefab.

    Unfortunately the Selection class only returns the current selections and I can't find any methods to actually set the selection:
    http://unity3d.com/support/documentation/ScriptReference/Selection.html

    Any ideas?
     
  2. kinetifex

    kinetifex

    Joined:
    Nov 4, 2008
    Posts:
    8
    Also on this custom editor subject, when I change a property value using my editor window, the prefab updates fine and all is well. However, when I quit and re-open that value is lost. Only property values that I change in the inspector stick between Unity sessions.

    What do I need to do to make values in a custom editor stick?
     
  3. kinetifex

    kinetifex

    Joined:
    Nov 4, 2008
    Posts:
    8
  4. the_gnoblin

    the_gnoblin

    Joined:
    Jan 10, 2009
    Posts:
    722
    You can make a button that instantiates a prefab so you can drag it around in scene.

    Also, I hope this helps:
    Code (csharp):
    1.  
    2. Object found_asset = EditorUtility.FindAsset(asset_path, typeof(Object));
    3.                 if (found_asset != null)
    4.                 {
    5.  
    6.                      Selection.activeObject = found_asset;
    7. }
     
  5. kinetifex

    kinetifex

    Joined:
    Nov 4, 2008
    Posts:
    8
    Ah, thanks for the response gnoblin. You answered my question in the snippet. I didn't think to try actually setting the Selection.activeObject variable. The docs only say it Returns the active object so I assumed it only would be read-only... This probably means other class variables are actually settable, too.

    Well now I know, thanks!

    -Andrew