// use this function when you need to open and close in the same way.
    public bool TogglePanelByName(string name)
    {
        PanelInstance page = null;

        for (int i = 0; i < Pages.Length; i++)
        {
            if (Pages [i].name == name)
            {
                page = Pages [i];
                break;
            }
        }
        if (page == null)
        {
            return(false);
        }

        if (page.gameObject.activeSelf)
        {
            ClosePanel(page);
            return(false);
        }
        else
        {
            page.PanelBefore = currentPanel;
            currentPanel     = page;
            CloseAllPanels();
            page.OpenPanel(true);
            return(true);
        }
    }
    // close panel by object PanelInstance
    public void ClosePanel(PanelInstance page)
    {
        if (page == null)
        {
            return;
        }

        currentPanel = null;
        page.OpenPanel(false);
        StartCoroutine(DisablePanelDeleyed(page));
    }
    // open panel by object PanelInstance
    public void OpenPanel(PanelInstance page)
    {
        if (page == null)
        {
            return;
        }

        page.PanelBefore = currentPanel;
        currentPanel     = page;

        CloseAllPanels();
        page.OpenPanel(true);
    }
 // use this function when you need to open previous panel
 public void OpenPreviousPanel()
 {
     if (setPreviousPanel != null)
     {
         CloseAllPanels();
         setPreviousPanel.OpenPanel(true);
         currentPanel     = setPreviousPanel;
         setPreviousPanel = null;
     }
     else
     {
         //Debug.Log ("open previous "+currentPanel.PanelBefore);
         if (currentPanel && currentPanel.PanelBefore)
         {
             CloseAllPanels();
             currentPanel.PanelBefore.OpenPanel(true);
             currentPanel = currentPanel.PanelBefore;
         }
     }
 }
    // close panel by name.
    public void ClosePanelByName(string name)
    {
        PanelInstance page = null;

        for (int i = 0; i < Pages.Length; i++)
        {
            if (Pages [i].name == name)
            {
                page = Pages [i];
                break;
            }
        }
        if (page == null)
        {
            return;
        }

        currentPanel = null;
        page.OpenPanel(false);
        StartCoroutine(DisablePanelDeleyed(page));
    }
    // use this function when you need to open panel without saving a previous.
    // so you can't use OpenPreviousPanel to open a previous panel again.
    public void OpenPanelByNameNoPreviousSave(string name)
    {
        PanelInstance page = null;

        for (int i = 0; i < Pages.Length; i++)
        {
            if (Pages [i].name == name)
            {
                page = Pages [i];
                break;
            }
        }
        if (page == null)
        {
            return;
        }

        currentPanel = page;

        CloseAllPanels();
        page.OpenPanel(true);
    }