Search Unity

CustomEditor: how to expose a source script for click navigation?

Discussion in 'Scripting' started by JFR, Oct 25, 2014.

  1. JFR

    JFR

    Joined:
    Feb 21, 2014
    Posts:
    65
    Hiya guys,

    Using a custom editor for a script is great, except for the fact that you loose the 'Script' field, where you could just click on it and have Unity navigate directly to that location in the Project Window. So I'm trying to add a custom field to achieve the same result, to no avail.

    Something like:

    Code (CSharp):
    1. m_cSourceScript = EditorGUILayout.("Source Script", m_cSourceScript, typeof(component), false) as component;
    But that's not working. Any ideas?
     
  2. JFR

    JFR

    Joined:
    Feb 21, 2014
    Posts:
    65
    Nevermind, figured it out. In case someone is interested, fairly simple.
    Code (CSharp):
    1.  
    2. MonoScript m_cSourceScript;
    3.  
    4. public override void OnEnable()
    5. {
    6.         m_cSourceScript = MonoScript.FromMonoBehaviour(TargetScriptClass);
    7. }
    8.  
    9. public override void OnInspectorGUI()
    10. {
    11.     m_cSourceScript = EditorGUILayout.ObjectField("Source Script", m_cSourceScript, typeof(MonoScript), false) as MonoScript;
    12. }
    13.  
     
    Last edited: Oct 25, 2014