private void AddButton(ReorderableList list)
        {
            GenericMenu        menu  = new GenericMenu();
            List <System.Type> types = FlowchartEditor.FindAllDerivedTypes <Variable>();

            // Add variable types without a category
            foreach (var type in types)
            {
                VariableInfoAttribute variableInfo = VariableEditor.GetVariableInfo(type);
                if (variableInfo == null ||
                    variableInfo.Category != "")
                {
                    continue;
                }

                AddVariableInfo addVariableInfo = new AddVariableInfo();
                addVariableInfo.flowchart    = TargetFlowchart;
                addVariableInfo.variableType = type;

                GUIContent typeName = new GUIContent(variableInfo.VariableType);

                menu.AddItem(typeName, false, AddVariable, addVariableInfo);
            }

            // Add types with a category
            foreach (var type in types)
            {
                VariableInfoAttribute variableInfo = VariableEditor.GetVariableInfo(type);
                if (variableInfo == null ||
                    variableInfo.Category == "")
                {
                    continue;
                }

                AddVariableInfo info = new AddVariableInfo();
                info.flowchart    = TargetFlowchart;
                info.variableType = type;

                GUIContent typeName = new GUIContent(variableInfo.Category + "/" + variableInfo.VariableType);

                menu.AddItem(typeName, false, AddVariable, info);
            }

            menu.ShowAsContext();
        }
Esempio n. 2
0
        protected virtual void DrawOverlay(Flowchart flowchart)
        {
            GUILayout.Space(8);

            GUILayout.BeginHorizontal();

            GUILayout.Space(8);

            if (GUILayout.Button(new GUIContent(addTexture, "Add a new block")))
            {
                Vector2 newNodePosition = new Vector2(50 - flowchart.ScrollPos.x,
                                                      50 - flowchart.ScrollPos.y);
                CreateBlock(flowchart, newNodePosition);
            }

            GUILayout.Space(8);

            flowchart.Zoom = GUILayout.HorizontalSlider(flowchart.Zoom, minZoomValue, maxZoomValue, GUILayout.Width(100));

            GUILayout.FlexibleSpace();

            GUILayout.BeginVertical();
            GUILayout.Label(flowchart.name, EditorStyles.whiteBoldLabel);
            if (flowchart.Description.Length > 0)
            {
                GUILayout.Label(flowchart.Description, EditorStyles.helpBox);
            }
            GUILayout.EndVertical();

            GUILayout.EndHorizontal();

            GUILayout.FlexibleSpace();

            GUILayout.BeginHorizontal();

            GUILayout.BeginVertical(GUILayout.Width(440));

            GUILayout.FlexibleSpace();

            flowchart.VariablesScrollPos = GUILayout.BeginScrollView(flowchart.VariablesScrollPos, GUILayout.MaxHeight(position.height * 0.75f));

            GUILayout.FlexibleSpace();

            GUILayout.Space(8);

            FlowchartEditor flowchartEditor = Editor.CreateEditor(flowchart) as FlowchartEditor;

            flowchartEditor.DrawVariablesGUI();
            DestroyImmediate(flowchartEditor);

            Rect variableWindowRect = GUILayoutUtility.GetLastRect();

            if (flowchart.VariablesExpanded &&
                flowchart.Variables.Count > 0)
            {
                variableWindowRect.y      -= 20;
                variableWindowRect.height += 20;
            }
            if (Event.current.type == EventType.Repaint)
            {
                mouseOverVariables = variableWindowRect.Contains(Event.current.mousePosition);
            }

            GUILayout.EndScrollView();

            GUILayout.EndVertical();

            GUILayout.FlexibleSpace();

            GUILayout.EndHorizontal();
        }