Menu Item in Unity

Dear Members,

I am creating a menu item as editor extension in unity. I have four small issues to solve.

  1. I need to get Tools/Panel ON/OFF. But ON/OFF gives OFF as extra menu. How to solve this?

  2. Once I click on Tools/Panel ON/OFF, a panel gets opened and when i again click on the same Tools/Panel ON/OFF it should close. How to achieve this?

  3. Is it possible to put image on the left side of menu item? I mean like Tools/(image) Panel ON/OFF. If yes, How?

  4. Can we create same menu item on toolbar? How?

Please help. This is urgent.

Thanks & regards,

1 and 2 - may be code below can help.

Create the folder Assets/Editor, then put here script like this:

using UnityEngine;
using UnityEditor;

class MyPanel : EditorWindow 
    static bool ShowPanelOnClick = true;
    EditorWindow window;

    [MenuItem ("Tools/Panel On-Off")]
    public static void  ShowPanel () 
      if (ShowPanelOnClick)
        window = EditorWindow.GetWindow(typeof(MyPanel));
         if (window != null) window.Close();
      ShowPanelOnClick = !ShowPanelOnClick;
    void OnGUI () 
        //code for your panel

You can learn more here: Unity Connect