コード例 #1
0
        //...
        void OnEnable()
        {
            titleContent = new GUIContent("Finder", StyleSheet.canvasIcon);

            wantsMouseMove                             = true;
            wantsMouseEnterLeaveWindow                 = true;
            GraphEditor.onCurrentGraphChanged         -= GraphChanged;
            GraphEditor.onCurrentGraphChanged         += GraphChanged;
            Graph.onGraphSerialized                   -= OnGraphSerialized;
            Graph.onGraphSerialized                   += OnGraphSerialized;
            GraphEditorUtility.onActiveElementChanged -= OnActiveElementChanged;
            GraphEditorUtility.onActiveElementChanged += OnActiveElementChanged;

            graphElement     = null;
            search           = null;
            lastHoverElement = null;
            scrollPos        = default(Vector2);
            willRepaint      = true;

            if (GraphEditor.currentGraph != null)
            {
                FetchElements(GraphEditor.currentGraph);
            }
        }
コード例 #2
0
        ///----------------------------------------------------------------------------------------------

        //Initialize the graph elements
        void FetchElements(Graph graph)
        {
            graphElement = graph.GetFlatGraphHierarchy();
            willRepaint  = true;
        }
コード例 #3
0
        ///Focus element. This also Pings it. User click.
        void FocusElement(HierarchyTree.Element e)
        {
            var element = e.GetFirstParentReferenceOfType <IGraphElement>();

            EditorApplication.delayCall += () => GraphEditor.FocusElement(element, true);
        }
コード例 #4
0
        //...
        void DoElement(HierarchyTree.Element element, Rect parentElementRect = default(Rect))
        {
            if (element.children == null)
            {
                return;
            }


            foreach (var child in element.children)
            {
                var elementRect = default(Rect);

                if (child.reference == null)
                {
                    continue;
                }

                //Dont show undefined parameters.
                //TODO: I dont like this "special case" here
                if (child.reference is BBParameter)
                {
                    var bbPram = (BBParameter)child.reference;
                    if (!bbPram.isDefined)
                    {
                        continue;
                    }
                }

                var toString   = child.reference.ToString();
                var typeName   = child.reference.GetType().FriendlyName();
                var searchText = toString + " " + typeName;

                if (string.IsNullOrEmpty(search) || StringUtils.SearchMatch(search, searchText))
                {
                    GUI.color = EditorGUIUtility.isProSkin? Color.white : Colors.Grey(0.8f);
                    GUILayout.BeginHorizontal("box");
                    GUILayout.Space(indent * INDENT_WIDTH);
                    GUI.color = Color.white;


                    var displayText = string.Format("<b>{0}</b>{1}", toString, Prefs.finderShowTypeNames? " (" + typeName + ")" : string.Empty);
                    GUILayout.Label(string.Format("<size=9>{0}</size>", displayText));
                    GUILayout.EndHorizontal();

                    elementRect = GUILayoutUtility.GetLastRect();

                    EditorGUIUtility.AddCursorRect(elementRect, MouseCursor.Link);
                    if (elementRect.Contains(Event.current.mousePosition))
                    {
                        if (child != lastHoverElement)
                        {
                            lastHoverElement = child;
                            willRepaint      = true;
                            PingElement(child);
                        }
                        GUI.color = new Color(0.5f, 0.5f, 1, 0.3f);
                        GUI.DrawTexture(elementRect, EditorGUIUtility.whiteTexture);
                        GUI.color = Color.white;
                        if (Event.current.type == EventType.MouseDown)
                        {
                            FocusElement(child);
                            Event.current.Use();
                        }
                    }

                    if (GraphEditorUtility.activeElement == child.reference)
                    {
                        GUI.color = new Color(0.5f, 0.5f, 1, 0.1f);
                        GUI.DrawTexture(elementRect, EditorGUIUtility.whiteTexture);
                        GUI.color = Color.white;
                    }
                }

                indent++;
                DoElement(child, elementRect);
                indent--;

                if (elementRect != default(Rect))
                {
                    var rootOrNotParentHidden = indent == INDENT_START || parentElementRect != default(Rect);

                    var lineVer = new Rect();
                    lineVer.xMin  = elementRect.xMin + (indent * INDENT_WIDTH) - (INDENT_WIDTH / 2);
                    lineVer.width = 2;
                    lineVer.yMin  = parentElementRect.yMax + 6;
                    lineVer.yMax  = elementRect.yMax - (elementRect.height / 2);

                    var lineHor = new Rect();
                    lineHor.xMin   = rootOrNotParentHidden? lineVer.xMin : (INDENT_WIDTH / 2);
                    lineHor.xMax   = lineVer.xMin + (INDENT_WIDTH / 2);
                    lineHor.yMin   = lineVer.yMax - 2;
                    lineHor.height = 2;

                    GUI.color = Colors.Grey(EditorGUIUtility.isProSkin? 0.6f : 0.3f);
                    if (rootOrNotParentHidden)
                    {
                        GUI.DrawTexture(lineVer, Texture2D.whiteTexture);
                    }
                    GUI.DrawTexture(lineHor, Texture2D.whiteTexture);
                    GUI.color = Color.white;
                }


                if (indent == INDENT_START && string.IsNullOrEmpty(search))
                {
                    EditorUtils.Separator();
                }
            }
        }