IsConnectedToStudio() public static method

public static IsConnectedToStudio ( ) : bool
return bool
Beispiel #1
0
        public void OnGUI()
        {
            var borderIcon = EditorGUIUtility.Load("FMOD/Border.png") as Texture2D;
            var border     = new GUIStyle(GUI.skin.box);

            border.normal.background = borderIcon;
            GUI.Box(new Rect(1, 1, position.width - 1, position.height - 1), GUIContent.none, border);

            #if UNITY_2017_3_OR_NEWER
            if (Event.current.type == EventType.Layout)
            #else
            if (Event.current.type == EventType.layout)
            #endif
            {
                isConnected = EditorUtils.IsConnectedToStudio();
            }

            if (!isConnected)
            {
                this.ShowNotification(new GUIContent("FMOD Studio not running"));
                return;
            }

            this.RemoveNotification();

            if (rootFolder == null)
            {
                BuildTree();
                currentFolder = rootFolder;
            }

            var arrowIcon = EditorGUIUtility.Load("FMOD/ArrowIcon.png") as Texture;
            var hoverIcon = EditorGUIUtility.Load("FMOD/SelectedAlt.png") as Texture2D;
            var titleIcon = EditorGUIUtility.Load("IN BigTitle") as Texture2D;


            var nextEntry = currentFolder;

            var filteredEntries = currentFolder.entries.FindAll((x) => x.name.StartsWith(currentFilter, StringComparison.CurrentCultureIgnoreCase));


            // Process key strokes for the folder list
            {
                if (Event.current.keyCode == KeyCode.UpArrow)
                {
                    #if UNITY_2017_3_OR_NEWER
                    if (Event.current.type == EventType.KeyDown)
                    #else
                    if (Event.current.type == EventType.keyDown)
                    #endif
                    {
                        lastHover = Math.Max(lastHover - 1, 0);
                        if (filteredEntries[lastHover].rect.y < scrollPos.y)
                        {
                            scrollPos.y = filteredEntries[lastHover].rect.y;
                        }
                    }
                    Event.current.Use();
                }
                if (Event.current.keyCode == KeyCode.DownArrow)
                {
                    #if UNITY_2017_3_OR_NEWER
                    if (Event.current.type == EventType.KeyDown)
                    #else
                    if (Event.current.type == EventType.keyDown)
                    #endif
                    {
                        lastHover = Math.Min(lastHover + 1, filteredEntries.Count - 1);
                        if (filteredEntries[lastHover].rect.y + filteredEntries[lastHover].rect.height > scrollPos.y + scrollRect.height)
                        {
                            scrollPos.y = filteredEntries[lastHover].rect.y - scrollRect.height + filteredEntries[lastHover].rect.height * 2;
                        }
                    }
                    Event.current.Use();
                }
                if (Event.current.keyCode == KeyCode.RightArrow)
                {
                    #if UNITY_2017_3_OR_NEWER
                    if (Event.current.type == EventType.KeyDown)
                    #else
                    if (Event.current.type == EventType.keyDown)
                    #endif
                    { nextEntry = filteredEntries[lastHover]; }
                    Event.current.Use();
                }
                if (Event.current.keyCode == KeyCode.LeftArrow)
                {
                    #if UNITY_2017_3_OR_NEWER
                    if (Event.current.type == EventType.KeyDown)
                    #else
                    if (Event.current.type == EventType.keyDown)
                    #endif
                    { if (currentFolder.parent != null)
                      {
                          nextEntry = currentFolder.parent;
                      }
                    }
                    Event.current.Use();
                }
            }


            bool disabled = eventName.Length == 0;
            EditorGUI.BeginDisabledGroup(disabled);
            if (GUILayout.Button("Create Event"))
            {
                CreateEventInStudio();
                this.Close();
            }
            EditorGUI.EndDisabledGroup();

            {
                GUI.SetNextControlName("name");

                EditorGUILayout.LabelField("Name");
                eventName = EditorGUILayout.TextField(eventName);
            }

            {
                EditorGUILayout.LabelField("Bank");
                selectedBank = EditorGUILayout.Popup(selectedBank, banks.Select(x => x.name).ToArray());
            }

            bool updateEventPath = false;
            {
                GUI.SetNextControlName("folder");
                EditorGUI.BeginChangeCheck();
                EditorGUILayout.LabelField("Path");
                eventFolder = GUILayout.TextField(eventFolder);
                if (EditorGUI.EndChangeCheck())
                {
                    updateEventPath = true;
                }
            }

            if (resetCursor)
            {
                resetCursor = false;

                var textEditor = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);
                if (textEditor != null)
                {
                    textEditor.MoveCursorToPosition(new Vector2(9999, 9999));
                }
            }

            // Draw the current folder as a title bar, click to go back one level
            {
                Rect currentRect = EditorGUILayout.GetControlRect();

                var bg = new GUIStyle(GUI.skin.box);
                bg.normal.background = titleIcon;
                Rect bgRect = new Rect(currentRect);
                bgRect.x     = 2;
                bgRect.width = position.width - 4;
                GUI.Box(bgRect, GUIContent.none, bg);


                Rect textureRect = currentRect;
                textureRect.width = arrowIcon.width;
                if (currentFolder.name != null)
                {
                    GUI.DrawTextureWithTexCoords(textureRect, arrowIcon, new Rect(1, 1, -1, -1));
                }


                Rect labelRect = currentRect;
                labelRect.x     += arrowIcon.width + 50;
                labelRect.width -= arrowIcon.width + 50;
                GUI.Label(labelRect, currentFolder.name != null ? currentFolder.name : "Folders", EditorStyles.boldLabel);

                #if UNITY_2017_3_OR_NEWER
                if (Event.current.type == EventType.MouseDown && currentRect.Contains(Event.current.mousePosition) &&
                    currentFolder.parent != null)
                #else
                if (Event.current.type == EventType.mouseDown && currentRect.Contains(Event.current.mousePosition) &&
                    currentFolder.parent != null)
                #endif
                {
                    nextEntry = currentFolder.parent;
                    Event.current.Use();
                }
            }

            var normal = new GUIStyle(GUI.skin.label);
            normal.padding.left = 14;
            var hover = new GUIStyle(normal);
            hover.normal.background = hoverIcon;

            scrollPos = EditorGUILayout.BeginScrollView(scrollPos, false, false);

            for (int i = 0; i < filteredEntries.Count; i++)
            {
                var entry   = filteredEntries[i];
                var content = new GUIContent(entry.name);
                var rect    = EditorGUILayout.GetControlRect();
                if ((rect.Contains(Event.current.mousePosition) && Event.current.type == EventType.MouseMove) || i == lastHover)
                {
                    lastHover = i;

                    GUI.Label(rect, content, hover);
                    #if UNITY_2017_3_OR_NEWER
                    if (rect.Contains(Event.current.mousePosition) && Event.current.type == EventType.MouseDown)
                    #else
                    if (rect.Contains(Event.current.mousePosition) && Event.current.type == EventType.mouseDown)
                    #endif
                    {
                        nextEntry = entry;
                    }
                }
                else
                {
                    GUI.Label(rect, content, normal);
                }

                Rect textureRect = rect;
                textureRect.x     = textureRect.width - arrowIcon.width;
                textureRect.width = arrowIcon.width;
                GUI.DrawTexture(textureRect, arrowIcon);

                #if UNITY_2017_3_OR_NEWER
                if (Event.current.type == EventType.Repaint)
                #else
                if (Event.current.type == EventType.repaint)
                #endif
                {
                    entry.rect = rect;
                }
            }
            EditorGUILayout.EndScrollView();

            #if UNITY_2017_3_OR_NEWER
            if (Event.current.type == EventType.Repaint)
            #else
            if (Event.current.type == EventType.repaint)
            #endif
            {
                scrollRect = GUILayoutUtility.GetLastRect();
            }

            if (currentFolder != nextEntry)
            {
                lastHover     = 0;
                currentFolder = nextEntry;
                UpdateTextFromList();
                Repaint();
            }

            if (updateEventPath)
            {
                UpdateListFromText();
            }

            if (Event.current.type == EventType.MouseMove)
            {
                Repaint();
            }
        }