Browser.DrawBrowser C# (CSharp) Méthode

DrawBrowser() public méthode

public DrawBrowser ( int windowID ) : void
windowID int
Résultat void
    void DrawBrowser(int windowID)
    {
        Event E = Event.current;
        Rect bottom = new Rect(5, BrowserRect.height-40, BrowserRect.width-10, 4);
        GUI.Box(bottom, "");
        bottom.x=10;    //Get bottom bar rect.
        bottom.y+=10;
        bottom.width = 120;
        bottom.height = 20;
        if(creatingFolder) // Folder creation tool.
        {
            folderName = GUI.TextField(bottom, folderName);
            bottom.x += bottom.width+5;
            bottom.width = 52;
            if(GUI.Button(bottom, "Create"))
            {
                String newDirectory;
                if( Directory.Exists(OpenPaths[OpenPaths.Length-1]) )
                    newDirectory = OpenPaths[OpenPaths.Length-1] + "/" + folderName;
                else
                    newDirectory = OpenPaths[OpenPaths.Length-2] + "/" + folderName;

                if(!Directory.Exists(newDirectory))
                {
                    Directory.CreateDirectory(newDirectory);
                    GetAllSubDirectoriesAndFiles( MainFolder );
                }
                creatingFolder = false;
            }
        } else
            if(GUI.Button(bottom, "Create New Folder"))
        {
            folderName = "";
            creatingFolder = true;
        }

        bottom.width = 12; // Draw resize handle
        bottom.height = 12;
        bottom.x = BrowserRect.width-bottom.width-5;
        bottom.y+=12;
        GUI.Box(bottom, "");
        Rect realBottom = bottom;
        realBottom.x += BrowserRect.x;
        realBottom.y += BrowserRect.y;
        if( Input.GetMouseButtonDown(0) && realBottom.Contains(GetMouseCord()) )
        {
            DragStat.Dragging = true;
            DragStat.startMouse = GetMouseCord();
            DragStat.startPosition = new Vector2(BrowserRect.width, BrowserRect.height);
            DragStat.type = DragType.WindowScaler;
        } else
            if(DragStat.Dragging && DragStat.type==DragType.WindowScaler)
        {
            Vector2 MouseCord = GetMouseCord();
            Vector2 newScale = DragStat.startPosition - new Vector2(    DragStat.startMouse.x - MouseCord.x,
                                                                    DragStat.startMouse.y - MouseCord.y);
            BrowserRect.width = newScale.x;
            BrowserRect.height = newScale.y;
            if(BrowserRect.width < minWindowScale.x) BrowserRect.width = minWindowScale.x;
            if(BrowserRect.height < minWindowScale.y) BrowserRect.height = minWindowScale.y;
        }

        // Draw Open/Save Cancel buttons, and make them function:
        bottom.y-=12;
        bottom.height = 20;
        bottom.width = 42;
        bottom.x -= bottom.width+5;
        if(WinType == WindowType.Open && GUI.Button(bottom, "Open"))
        {
            String FileToOpen = OpenPaths[OpenPaths.Length-1];
            if(File.Exists(FileToOpen) || Directory.Exists(FileToOpen))
            {
                //////////////////////////////////////////////////////////////////////////////////////////////////////////
                //                                                                                                      //
                //    Run Your Open file code here! Have your open file code in a function that accepts a path (string) //
                //                                    and pass to it: FileToOpen.                                       //
                //                                                                                                      //
                //////////////////////////////////////////////////////////////////////////////////////////////////////////
                Debug.Log("Opening File: " + FileToOpen);
            }
            else Debug.LogError("The File you are trying to open must have gotten moved, or deleated.");

            WindowOpen = false;
        }
        if(WinType == WindowType.Save && GUI.Button(bottom, "Save"))
        {
            if(File.Exists(FileToSave) || Directory.Exists(FileToSave))
            {
                //NameOfFileToSave
                String SaveLocation = OpenPaths[OpenPaths.Length-1];
                if(Directory.Exists( SaveLocation ))
                    OverwriteDuplicates(FileToSave, SaveLocation+"/"+NameOfFileToSave);
                else
                {
                    if(File.Exists(SaveLocation)) // If the user chooses a file instead of a folder the parent folder will be used.
                    {
                        SaveLocation = (new FileInfo(SaveLocation)).DirectoryName;
                        OverwriteDuplicates(FileToSave, SaveLocation+"/"+NameOfFileToSave);
                    }
                    else Debug.LogError("The directory you're trying to save in no longer exists");
                }
            }
            else Debug.LogError("The file/folder your trying to save no longer exists.");
            WindowOpen = false;
        }
        bottom.width = 52;
        bottom.x -= bottom.width+5;
        if(GUI.Button(bottom, "Cancel"))
        {
            if(WinType == WindowType.Save)
            {
                if(File.Exists(FileToSave))
                    File.Delete(FileToSave); // Deleate FileToSave if the user chooses cancel.
                if(Directory.Exists(FileToSave))
                    Directory.Delete(FileToSave, true); // Deleate FileToSave if the user chooses cancel.
                Debug.Log("Deleate: " + FileToSave);
            }
            //Directory.Delete(FileToSave, true); // Deleate the file to save if the user chooses cancel.
            WindowOpen = false;
        }
        if(WinType == WindowType.Save)
        {
            bottom.width = 130;
            bottom.x -= bottom.width+5;
            NameOfFileToSave = GUI.TextField(bottom, NameOfFileToSave);
        }

        //////////////////////////////////////////////////////////////////
        // The rest of OnGUI is to draw the columns part of the window. //
        //////////////////////////////////////////////////////////////////
        const int verticalSpace = 2;
        const int horiznontalSpace = 10;

        Rect OuterPosition = BrowserRect;
        OuterPosition.x=5;
        OuterPosition.y=20;
        OuterPosition.width-=10;
        OuterPosition.height-=67;
        Rect OuterViewRect = OuterPosition;

        OuterViewRect.height-=17;
        OuterViewRect.width = 0;
        for(int i=0; i<ScrollPositions.Length; ++i) OuterViewRect.width += horiznontalSpace+Widths[i];
        OuterViewRect.width += 15;
        //OuterPosition.width = 0;
        //for(int i=0; i<Widths.Length; ++i) OuterPosition.width += 12+Widths[i];

        // Makes scroll wheel on columns view scroll horizontally, as well allowing vertical scrolling in each column.
        if(!Input.GetMouseButton(0))
        {
            DragStat.Dragging = false;

            Rect realOuterPosition = OuterPosition;
            realOuterPosition.x += BrowserRect.x;
            realOuterPosition.y += BrowserRect.y;
            if( realOuterPosition.Contains(GetMouseCord()) && E.type == EventType.ScrollWheel )
                OuterScrollPosition.x += Mathf.Clamp(E.delta.x,-2f,2f)*20;
        }

        if(OuterPosition.width >= OuterViewRect.width)
        {
            OuterPosition.height+=20;
            OuterViewRect.height+=20;
        }
        OuterScrollPosition = GUI.BeginScrollView (OuterPosition, OuterScrollPosition, OuterViewRect);
        GUI.BeginGroup (OuterViewRect);

        for(int i=0; i<ScrollPositions.Length; ++i)
        {
            int ButtonHeight = 20;
            int[] PathIndexes = GetPathIndexesAt( OpenPaths[i] );
            Rect Position = GetRect(i, horiznontalSpace, (int)OuterViewRect.height);
            Rect viewRect = Position;
            viewRect.height = PathIndexes.Length*ButtonHeight + (PathIndexes.Length-1)*verticalSpace;
            viewRect.width -=17;
            viewRect.x = 0;
            viewRect.y = 0;
            // Make the buttons fill the space available:
            if(PathIndexes.Length*ButtonHeight + (PathIndexes.Length-1)*verticalSpace <= Position.height) viewRect.width += 15;

            ScrollPositions[i] = GUI.BeginScrollView (Position, ScrollPositions[i], viewRect); // Draw Column i.
            viewRect.height = ButtonHeight;
            for(int j=0; j<PathIndexes.Length; ++j)
            {
                int index = PathIndexes[j];

                if(i+1<OpenPaths_Reduced.Length && PathTree[index].Name == OpenPaths_Reduced[i+1]) GUI.backgroundColor = Color.blue;
                else GUI.backgroundColor = Color.white;

                Vector2 posbackup = ScrollPositions[i]; // Prevent it from scrolling to the top on button click.
                if(GUI.Button(viewRect, PathTree[index].Name))
                {
                    OuterScrollPosition.x = Mathf.Infinity; // Scroll to end of outer scroll view.
                    if(PathTree[index].File)
                    {
                        if(i==OpenPaths.Length-1) AddWidth();
                        AddScrollPosition(i);
                    }
                    else
                    {
                        if(i==OpenPaths.Length-1) AddWidth();
                        AddScrollPosition(i+1);
                    }
                    AddPath(PathTree[index].Parent + "/" + PathTree[index].Name, i+1);
                }
                ScrollPositions[i] = posbackup;
                viewRect.y += ButtonHeight+verticalSpace;
            }
            GUI.EndScrollView();

            Position.x += Position.width;            // Draw Column Resizer Bar:
            Position.width = horiznontalSpace-2;
            GUI.Box(Position, "");
            Rect realPosition = Position;            // Make it function:
            realPosition.x -= OuterScrollPosition.x - OuterPosition.x-2;
            //realPosition.y -= OuterScrollPosition.y;
            realPosition.x += BrowserRect.x;
            realPosition.y += BrowserRect.y;
            if( Input.GetMouseButtonDown(0) && realPosition.Contains(GetMouseCord()) )
            {
                DragStat.Dragging = true;
                DragStat.startMouse = Input.mousePosition;
                DragStat.startPosition = new Vector2(Widths[i], 0);
                DragStat.type = DragType.Column;
                DragStat.column = i;
            } else
                if(DragStat.Dragging && DragStat.type==DragType.Column && DragStat.column==i)
            {
                if(realPosition.x > BrowserRect.x+BrowserRect.width) BrowserRect.width = realPosition.x-BrowserRect.x;
                int newWidth = (int)(DragStat.startPosition.x - DragStat.startMouse.x + Input.mousePosition.x);
                if(newWidth < minWidth) newWidth=minWidth;
                Widths[i] = newWidth;
            }
        }
        GUI.EndGroup ();
        GUI.EndScrollView();

        //GUI.Button(new Rect(10, 20, 400, 20), "Can't drag me");
        //GUI.DragWindow();

        if(Input.GetMouseButtonDown(0))
        {
            Rect topBar = BrowserRect;
            topBar.height = 15;
            if( topBar.Contains(GetMouseCord()) )
            {
                DragStat.Dragging = true;
                DragStat.startMouse = GetMouseCord();
                DragStat.startPosition = new Vector2(BrowserRect.x, BrowserRect.y);
                DragStat.type = DragType.Window;
            }
        }
        if(DragStat.Dragging && DragStat.type==DragType.Window)
        {
            Vector2 MouseCord = GetMouseCord();
            Vector2 newPos = DragStat.startPosition - new Vector2(    DragStat.startMouse.x - MouseCord.x,
                                                                  DragStat.startMouse.y - MouseCord.y);
            BrowserRect.x = newPos.x;
            BrowserRect.y = newPos.y;
        }
    }