Search Unity

Editor: Selection of custom objects/script from a custom inspector

Discussion in 'Scripting' started by Sprocket, Mar 12, 2011.

  1. Sprocket

    Sprocket

    Joined:
    Sep 18, 2010
    Posts:
    31
    When making a custom inspector how do I create a way to select a particular instance of one of my game scripts?

    I tried using EditorGUILayout.ObjectField which is the kind of "drop" field I want, however this only allows me to drop assets there - I want to be able to drop script instances. This functionality exists in the standard inspector - i just don't know how to replicate it in my custom inspector.


    What I have so far:

    I have written a custom editor inspector for editing paths for a game I'm helping out with. Each level in the game has several paths - one for the player and several more for the opponents. The paths are a custom class I have created.

    Part of my custom inspector draws a preview of the playing field with the selected path on top. So far so good.


    Challenge:

    Now the game designer want each path-preview for an opponent to show not only the opponents path, but also the player path. So somehow custom inspector needs to get hold of the data from the player path.

    I have added an extra Path field (named "player") to the Path class. If I run the standard inspector I can drag the game object that has the player-path into this "player" on each opponent and all is good. However I don't know how to do replicate this behavior in my custom inspector.
     
  2. Fenrisul

    Fenrisul

    Joined:
    Jan 2, 2010
    Posts:
    618
    use type: MonoBehaviour (or just Behaviour) as the Type value for ObjectField

    this should accept instances.

    As for showing the player path and the opponent path: you could take the easy way out :)
    Open 2 inspectors and Lock one of them to the Player object :p
     
    Last edited: Mar 12, 2011