private void OnGUI()
        {
            if (wwwShader1 != null)
            {
                if (wwwShader1.isDone)
                {
                    string pathShader = "Assets/TextureWang/Shaders/TextureOps.shader";
                    pathShader = pathShader.Replace("/", "" + Path.DirectorySeparatorChar);

                    File.WriteAllBytes(pathShader, wwwShader1.bytes);
                    AssetDatabase.ImportAsset(pathShader, ImportAssetOptions.ForceSynchronousImport);
                    wwwShader1 = null;
                }
                Repaint();
                Debug.Log("repaint 2");
            }

            if (canvasCache.nodeCanvas.m_PreviewAnimation)
            {
                if (m_SW == null)
                {
                    m_SW = Stopwatch.StartNew();
                }
                m_AnimValue += (m_SW.ElapsedMilliseconds - m_LastTime) / 3000.0f;
                if (m_AnimValue < 0)
                {
                    m_AnimValue = 0;
                }
                m_LastTime = m_SW.ElapsedMilliseconds;
                if (m_AnimValue > 1.0f)
                {
                    m_AnimValue = 0.0f;
                }
                foreach (var x in canvasCache.nodeCanvas.nodes)
                {
                    if (x is InputNodeAnimated)
                    {
                        var ina = x as InputNodeAnimated;
                        ina.m_Value.Set(m_AnimValue);
                    }
                }
                NodeEditor.RecalculateAll(canvasCache.nodeCanvas);
                Repaint();
                Debug.Log("repaint 3");
            }
            else
            {
                m_AnimValue = 0;
            }

            if (m_ReplaceNode != null && !OverlayGUI.HasPopupControl() && ms_InputInfo != null)
            {
                NodeEditorInputSystem.ShowContextMenu(ms_InputInfo);
                ms_InputInfo = null;
            }

/*
 *          if (NodeEditor.curEditorState == null)
 *          {
 *              Debug.Log("OnGUI::TWWindow has no editor state " + NodeEditor.curEditorState+"actual editor state "+ canvasCache.editorState);
 *          }
 *          else if (NodeEditor.curEditorState.selectedNode == null)
 *          {
 *              Debug.Log("OnGUI::TWWindow has no Selected Node " + NodeEditor.curEditorState);
 *          }
 *          else
 *          {
 *              Debug.Log("OnGUI:: Selected Node " + NodeEditor.curEditorState.selectedNode);
 *          }
 */
            // Initiation
            NodeEditor.checkInit(true);
            if (NodeEditor.InitiationError)
            {
                GUILayout.Label("Node Editor Initiation failed! Check console for more information!");
                return;
            }
            AssureEditor();
            canvasCache.AssureCanvas();

            // Specify the Canvas rect in the EditorState
            canvasCache.editorState.canvasRect = canvasWindowRect;
            // If you want to use GetRect:
            //			Rect canvasRect = GUILayoutUtility.GetRect (600, 600);
            //			if (Event.current.type != EventType.Layout)
            //				mainEditorState.canvasRect = canvasRect;
            NodeEditorGUI.StartNodeGUI();

            // Perform drawing with error-handling
            try
            {
                if ((Event.current.keyCode >= KeyCode.A && Event.current.keyCode <= KeyCode.Z) || Event.current.keyCode == KeyCode.Escape)
                {
                    if (Event.current.keyCode == KeyCode.Escape)
                    {
                        PopupMenu.m_NameFilter = "";
                    }
                    else
                    {
                        int    ascii = ((int)Event.current.keyCode - (int)KeyCode.A) + 65;
                        string c     = Char.ConvertFromUtf32(ascii);
                        PopupMenu.m_NameFilter = c;
                    }

                    Debug.Log("m_NameFilter " + PopupMenu.m_NameFilter);
                    OverlayGUI.currentPopup = null;
                    NodeEditorInputInfo inputInfo = new NodeEditorInputInfo(canvasCache.editorState);

                    NodeEditorInputSystem.ShowContextMenu(inputInfo);
                }
                NodeEditor.DrawCanvas(canvasCache.nodeCanvas, canvasCache.editorState);


                if (canvasCache.editorState.selectedNode != null)
                {
                    if (canvasCache.editorState.selectedNode is TextureNode)
                    {
                        var tn = canvasCache.editorState.selectedNode as TextureNode;
                        if (tn.m_RequestRepaint)
                        {
                            tn.m_RequestRepaint = false;
                            Debug.Log("repaint 1");
                            Repaint();
                            m_InspectorWindow.Repaint();
                        }
                    }
                }


                if (wwwShader1 != null)
                {
                    GUI.Label(new Rect(100, 100, 500, 200), "One Time Shader Download in progress...");
                }
            }
            catch (UnityException e)
            { // on exceptions in drawing flush the canvas to avoid locking the ui.
                canvasCache.NewNodeCanvas();
                NodeEditor.ReInit(true);
                Debug.LogError("Unloaded Canvas due to an exception during the drawing phase!");
                Debug.LogException(e);
            }
            if (m_PostOnLoadCanvasFixup != null)
            {
//                m_PostOnLoadCanvasFixup.PostOnLoadCanvasFixup();
                m_PostOnLoadCanvasFixup = null;
            }


            // Draw Side Window
            //sideWindowWidth = Math.Min(600, Math.Max(200, (int)(position.width / 5)));
            //GUILayout.BeginArea(sideWindowRect, GUI.skin.box);
            //DrawSideWindow();
            //GUILayout.EndArea();


            NodeEditorGUI.EndNodeGUI();
//            if (Event.current.type == EventType.Repaint)
//                m_InspectorWindow.Repaint();

/*
 *          //if (Event.current.type == EventType.Repaint)
 *          {
 *              if (mainEditorState.selectedNode != mainEditorState.wantselectedNode)
 *              {
 *                  mainEditorState.selectedNode = mainEditorState.wantselectedNode;
 *                  NodeEditor.RepaintClients();
 *                  Repaint();
 *              }
 *
 *          }
 */

            if (!m_Docked && m_DockedRetry++ < 100 && m_InspectorWindow != null && m_NodeSelectionWindow != null)
            {
                try
                {
                    m_DockedRetry++;
                    Docker.Dock(this, m_InspectorWindow, Docker.DockPosition.Right);
                    Docker.Dock(this, m_NodeSelectionWindow, Docker.DockPosition.Left);
                }
                catch (Exception ex)
                {
                    Debug.LogError(" Dock failed " + ex);
                }
                m_Docked = true;
            }
        }
        private void OnGUI()
        {
            if (wwwShader1 != null)
            {
                if (wwwShader1.isDone)
                {
                    string pathShader = "Assets/TextureWang/Shaders/TextureOps.shader";
                    pathShader = pathShader.Replace("/", "" + Path.DirectorySeparatorChar);

                    File.WriteAllBytes(pathShader, wwwShader1.bytes);
                    AssetDatabase.ImportAsset(pathShader, ImportAssetOptions.ForceSynchronousImport);
                    wwwShader1 = null;
                }
                Repaint();
            }


            if (m_ReplaceNode != null && !OverlayGUI.HasPopupControl() && ms_InputInfo != null)
            {
                NodeEditorInputSystem.ShowContextMenu(ms_InputInfo);
                ms_InputInfo = null;
            }

/*
 *          if (NodeEditor.curEditorState == null)
 *          {
 *              Debug.Log("OnGUI::TWWindow has no editor state " + NodeEditor.curEditorState+"actual editor state "+ canvasCache.editorState);
 *          }
 *          else if (NodeEditor.curEditorState.selectedNode == null)
 *          {
 *              Debug.Log("OnGUI::TWWindow has no Selected Node " + NodeEditor.curEditorState);
 *          }
 *          else
 *          {
 *              Debug.Log("OnGUI:: Selected Node " + NodeEditor.curEditorState.selectedNode);
 *          }
 */
            // Initiation
            NodeEditor.checkInit(true);
            if (NodeEditor.InitiationError)
            {
                GUILayout.Label("Node Editor Initiation failed! Check console for more information!");
                return;
            }
            AssureEditor();
            canvasCache.AssureCanvas();

            // Specify the Canvas rect in the EditorState
            canvasCache.editorState.canvasRect = canvasWindowRect;
            // If you want to use GetRect:
            //			Rect canvasRect = GUILayoutUtility.GetRect (600, 600);
            //			if (Event.current.type != EventType.Layout)
            //				mainEditorState.canvasRect = canvasRect;
            NodeEditorGUI.StartNodeGUI();

            // Perform drawing with error-handling
            try
            {
                NodeEditor.DrawCanvas(canvasCache.nodeCanvas, canvasCache.editorState);


                if (canvasCache.editorState.selectedNode != null)
                {
                    if (canvasCache.editorState.selectedNode is TextureNode)
                    {
                        var tn = canvasCache.editorState.selectedNode as TextureNode;
                        if (tn.m_RequestRepaint)
                        {
                            tn.m_RequestRepaint = false;
                            Repaint();
                            m_InspectorWindow.Repaint();
                        }
                    }
                }
                if (wwwShader1 != null)
                {
                    GUI.Label(new Rect(100, 100, 500, 200), "One Time Shader Download in progress...");
                }
            }
            catch (UnityException e)
            { // on exceptions in drawing flush the canvas to avoid locking the ui.
                canvasCache.NewNodeCanvas();
                NodeEditor.ReInit(true);
                Debug.LogError("Unloaded Canvas due to an exception during the drawing phase!");
                Debug.LogException(e);
            }
            if (m_PostOnLoadCanvasFixup != null)
            {
//                m_PostOnLoadCanvasFixup.PostOnLoadCanvasFixup();
                m_PostOnLoadCanvasFixup = null;
            }


            // Draw Side Window
            //sideWindowWidth = Math.Min(600, Math.Max(200, (int)(position.width / 5)));
            //GUILayout.BeginArea(sideWindowRect, GUI.skin.box);
            //DrawSideWindow();
            //GUILayout.EndArea();


            NodeEditorGUI.EndNodeGUI();
//            if (Event.current.type == EventType.Repaint)
//                m_InspectorWindow.Repaint();

/*
 *          //if (Event.current.type == EventType.Repaint)
 *          {
 *              if (mainEditorState.selectedNode != mainEditorState.wantselectedNode)
 *              {
 *                  mainEditorState.selectedNode = mainEditorState.wantselectedNode;
 *                  NodeEditor.RepaintClients();
 *                  Repaint();
 *              }
 *
 *          }
 */

            if (!m_Docked && m_DockedRetry++ < 100 && m_InspectorWindow != null && m_NodeSelectionWindow != null)
            {
                try
                {
                    m_DockedRetry++;
                    Docker.Dock(this, m_InspectorWindow, Docker.DockPosition.Right);
                    Docker.Dock(this, m_NodeSelectionWindow, Docker.DockPosition.Left);
                }
                catch (Exception ex)
                {
                    Debug.LogError(" Dock failed " + ex);
                }
                m_Docked = true;
            }
        }