OnInspectorGUI selecting objects in the scene

Hi everyone,
this seems pretty basic stuff, but I can’t seem to get it to work for the life of me so I hoped maybe someone could show me the silly little thing I’m doing wrong to fix it.

I want to build a doubly-linked-list of GameObject nodes that can be placed in the world. Each node has a next node, and a previous node. When I set an objects “Next Node” or “Prev Node” I want both objects to automatically point to each other (the user shouldn’t have to go and change both nodes to correctly point to eachother). I can do this by hiding my NextNode and PrevNode members behind accessors, like so:

using UnityEngine;
using System.Collections;

public class CameraNode
	: MonoBehaviour 
{
	// public members //////////////////////////////////////////////
		
	// public methods ///////////////////////////////////////////////
	
	// public accessors /////////////////////////////////////////////
	public CameraNode NextNode
	{
		get { return m_nextNode; }
		set
		{
			m_nextNode = value;
			if( ( value != null ) 
			    ( value.PrevNode != this ) )
			{
				value.PrevNode = this;
			}
		}
	}
	
	public CameraNode PrevNode
	{
		get { return m_prevNode; }
		set
		{
			m_prevNode = value;
			if( ( value != null )  
			    ( value.NextNode != this ) )
			{
				value.NextNode = this;
			}
		}
	}
	
	// private methods ///////////////////////////////////////////////

	// private members //////////////////////////////////////////////
	private CameraNode m_nextNode;
	private CameraNode m_prevNode;
}

Now, I do want these nodes editable in the inspector. No worries, I can write an editor script. So I do:

using UnityEngine;
using UnityEditor;
using System.Collections;

[CustomEditor(typeof(CameraNode))]
public class CameraNodeEditor
	: Editor
{
  public override void OnInspectorGUI()
  {
    if( target.GetType() == typeof( CameraNode ) )
    {
      CameraNode editing = (CameraNode)target;
      GameObject nextNodeObj = (GameObject)EditorGUILayout.ObjectField( 
                          "Next Node"
                         , editing.NextNode
                         , typeof( CameraNode ) );

      if( nextNodeObj != null )
      {
        editing.NextNode = nextNodeObj.GetComponent<CameraNode>();
      }
			
      DrawDefaultInspector();
    }
  }
}

But here’s the problem, I’m expecting this (look at the highlighted Test)

  • I can select an object that only has a particular component.
  • I can select form objects in the world, or prefabs (assets)

But what I get is this:

  • I can only see assets?
  • It looks ugly in the inspector, and non standard.

Now I’ve seen other questions on the forums that ask this question too, and people recommended a TextField? But that’s not really what I want here. Surely this is a reusable component right? How did the Unity developers do it?

Thanks for your time,
-Howard

This is better suited for Unity Answers, so I moved the question to here:

http://answers.unity3d.com/questions/37318/oninspectorgui-using-the-default-object-selection-popup

Feel free to lock this thread!

Surprising thought it may sound, there is a function called EditorGUIUtility.LookLikeInspector that gives the GUI the same look as the built-in editors. You may be limited to using GameObject as the type for the choosable objects - I’m not sure if the function can be set up to filter objects by attached components, such as scripts.