Esempio n. 1
0
        public void RebuildSections(Blackboard blackboard)
        {
            m_Blackboard = blackboard;
            m_Store      = blackboard.Store;
            var currentGraphModel = (VSGraphModel)blackboard.Store.GetState().CurrentGraphModel;

            blackboard.ClearContents();

            if (blackboard.Sections != null && blackboard.Sections.Count > 1)
            {
                blackboard.Sections[k_GraphDeclarationsSection].title     = k_GraphDeclarationsSectionTitle;
                blackboard.Sections[k_InputPortDeclarationsSection].title = k_InputPortDeclarationsSectionTitle;
            }

            foreach (VariableDeclarationModel declaration in currentGraphModel.VariableDeclarations)
            {
                var blackboardField = new BlackboardVariableField(blackboard.Store, declaration, blackboard.GraphView);
                var blackboardVariablePropertyView = new DotsVariablePropertyView(blackboard.Store, declaration, blackboard.Rebuild, m_Stencil);
                if (declaration.DataType != TypeHandle.ExecutionFlow)
                {
                    blackboardVariablePropertyView = (DotsVariablePropertyView)blackboardVariablePropertyView.WithLocalInputOutputToggle().WithTypeSelector();
                    if (declaration.IsGraphVariable())
                    {
                        blackboardVariablePropertyView = (DotsVariablePropertyView)blackboardVariablePropertyView.WithInitializationField();
                    }
                }
                blackboardVariablePropertyView = (DotsVariablePropertyView)blackboardVariablePropertyView.WithTooltipField();
                var blackboardRow = new BlackboardRow(
                    blackboardField,
                    blackboardVariablePropertyView)
                {
                    userData = declaration,
                    expanded = true, // TODO not pretty
                };
                if (blackboard.Sections != null)
                {
                    if (declaration.IsInputOrOutputTrigger())
                    {
                        blackboard.Sections[k_InputPortDeclarationsSection].Add(blackboardRow);
                    }
                    else
                    {
                        blackboard.Sections[k_GraphDeclarationsSection].Add(blackboardRow);
                    }
                }
                blackboard.GraphVariables.Add(blackboardField);
            }
        }
        public void RebuildSections(Blackboard blackboard)
        {
            m_Store = blackboard.Store;
            var currentGraphModel = (VSGraphModel)blackboard.Store.GetState().CurrentGraphModel;

            blackboard.ClearContents();

            if (blackboard.Sections != null && blackboard.Sections.Count > 1)
            {
                blackboard.Sections[k_InputPortDeclarationsSection].title  = k_InputPortDeclarationsSectionTitle;
                blackboard.Sections[k_OutputPortDeclarationsSection].title = k_OutputPortDeclarationsSectionTitle;
            }

            if (currentGraphModel.NodeModels == null)
            {
                return;
            }

            foreach (VariableDeclarationModel declaration in currentGraphModel.VariableDeclarations)
            {
                var blackboardField = new BlackboardVariableField(blackboard.Store, declaration, blackboard.GraphView);
                var blackboardRow   = new BlackboardRow(
                    blackboardField,
                    new BlackboardVariablePropertyView(blackboard.Store, declaration, blackboard.Rebuild, m_Stencil)
                    .WithTypeSelector()
                    .WithTooltipField())
                {
                    userData = declaration,
                    expanded = true, // TODO not pretty
                };
                if (blackboard.Sections != null)
                {
                    switch (declaration.Modifiers)
                    {
                    case ModifierFlags.ReadOnly:
                        blackboard.Sections[k_InputPortDeclarationsSection].Add(blackboardRow);
                        break;

                    case ModifierFlags.WriteOnly:
                        blackboard.Sections[k_OutputPortDeclarationsSection].Add(blackboardRow);
                        break;
                    }
                }
                blackboard.GraphVariables.Add(blackboardField);
            }
        }
        public void RebuildSections(Blackboard blackboard)
        {
            m_Store = blackboard.Store;
            var currentGraphModel = (VSGraphModel)blackboard.Store.GetState().CurrentGraphModel;

            blackboard.ClearContents();

            if (blackboard.Sections != null && blackboard.Sections.Count > 1)
            {
                blackboard.Sections[k_InputPortDeclarationsSection].title  = k_InputPortDeclarationsSectionTitle;
                blackboard.Sections[k_OutputPortDeclarationsSection].title = k_OutputPortDeclarationsSectionTitle;
            }

            if (currentGraphModel.NodeModels == null)
            {
                return;
            }

            foreach (VariableDeclarationModel declaration in currentGraphModel.VariableDeclarations)
            {
                var blackboardField = new BlackboardVariableField(blackboard.Store, declaration, blackboard.GraphView);
                if (blackboard.Sections != null)
                {
                    switch (declaration.Modifiers)
                    {
                    case ModifierFlags.ReadOnly:
                        blackboard.Sections[k_InputPortDeclarationsSection].Add(blackboardField);
                        break;

                    case ModifierFlags.WriteOnly:
                        blackboard.Sections[k_OutputPortDeclarationsSection].Add(blackboardField);
                        break;
                    }
                }
                blackboard.GraphVariables.Add(blackboardField);
            }
        }
        public void RebuildSections(Blackboard blackboard)
        {
            m_Blackboard = blackboard;

            blackboard.styleSheets.Add(k_BlackboardStyleSheet);
            // @TODO: This might need to be reviewed in favor of a better / more scalable approach (non preprocessor based)
            // that would ideally bring the same level of backward/forward compatibility and/or removed when a 2013 beta version lands.
#if UNITY_2019_3_OR_NEWER
            blackboard.styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(UICreationHelper.TemplatePath + "BlackboardECS.2019.3.uss"));
#endif

            // Fetch expanded states as well as active component query toggles (note that this doesn't not apply to
            // elements that do not survive a domain reload)
            var expandedRows = new Dictionary <object, bool>();

            foreach (BlackboardSection blackBoardSection in blackboard.Sections)
            {
                blackBoardSection.Query <ExpandableRow>().ForEach(row =>
                {
                    switch (row.userData)
                    {
                    case IVariableDeclarationModel model:
                        {
                            var queryDeclarationModel = model as ComponentQueryDeclarationModel;
                            bool expanded             = row.Expanded;
                            if (!expanded && queryDeclarationModel != null)
                            {
                                expanded = queryDeclarationModel.ExpandOnCreateUI;
                            }
                            expandedRows[model] = expanded;
                            break;
                        }

                    case string str:
                        expandedRows[str] = row.Expanded;
                        break;
                    }
                });

                blackBoardSection.Query <BlackboardRow>().ForEach(row =>
                {
                    switch (row.userData)
                    {
                    case IVariableDeclarationModel model:
                        expandedRows[model] = row.expanded;
                        break;

                    case Tuple <IVariableDeclarationModel, bool> modelTuple:
                        expandedRows[modelTuple.Item1] = row.expanded;
                        break;
                    }
                });
            }

            List <ISelectable> selectionCopy = blackboard.selection.ToList();

            // TODO: This is too hardcore.  We need to let all unrolling happen smoothly.
            blackboard.ClearContents();

            var state          = blackboard.Store.GetState();
            var graphVariables = ((IVSGraphModel)state.CurrentGraphModel).GraphVariableModels.ToList();

            // Fill component queries section
            var componentQueryDeclarationModels = graphVariables.OfType <ComponentQueryDeclarationModel>().ToList();
            var nbModels = componentQueryDeclarationModels.Count;
            if (nbModels > 0)
            {
                blackboard.Sections[k_ComponentQueriesSection]
                .Add(new ComponentQueriesRow(componentQueryDeclarationModels,
                                             blackboard,
                                             m_Stencil,
                                             blackboard.Rebuild));
                blackboard.Sections[k_ComponentQueriesSection].title = $"{k_ComponentQueriesSectionTitle} ({nbModels})";
            }

            // Fill variables section
            var variables = graphVariables.Where(v => !(v is ComponentQueryDeclarationModel)).ToList();
            blackboard.Sections[k_VariablesSection].title = $"{k_VariableSectionTitle} ({variables.Count})";

            foreach (var variable in variables)
            {
                var blackboardField = new BlackboardVariableField(blackboard.Store, variable, blackboard.GraphView);
                var blackboardRow   = new BlackboardRow(
                    blackboardField,
                    CreateExtendedFieldView(blackboard.Store, variable, m_Stencil, blackboard.Rebuild))
                {
                    userData = variable,
                    expanded = expandedRows.TryGetValue(variable, out var isExpended) && isExpended
                };

                blackboard.Sections[k_VariablesSection].Add(blackboardRow);
                blackboard.GraphVariables.Add(blackboardField);
                blackboard.RestoreSelectionForElement(blackboardField);
            }

            // Fill local scope section
            foreach (Tuple <IVariableDeclarationModel, bool> variableDeclarationModelTuple in blackboard.GraphView.UIController
                     .GetAllVariableDeclarationsFromSelection(selectionCopy))
            {
                var blackboardField = new BlackboardVariableField(blackboard.Store, variableDeclarationModelTuple.Item1, blackboard.GraphView);

                if (variableDeclarationModelTuple.Item1.VariableType == VariableType.FunctionParameter)
                {
                    blackboardField.AddToClassList("parameter");
                }

                if (variableDeclarationModelTuple.Item2)
                {
                    var blackboardRow = new BlackboardRow(blackboardField,
                                                          CreateExtendedFieldView(blackboard.Store,
                                                                                  variableDeclarationModelTuple.Item1,
                                                                                  m_Stencil,
                                                                                  blackboard.Rebuild))
                    {
                        userData = variableDeclarationModelTuple
                    };
                    blackboard.Sections[k_CurrentScopeSection].Add(blackboardRow);
                }
                else
                {
                    blackboardField.AddToClassList("readonly");
                    blackboard.Sections[k_CurrentScopeSection].Add(blackboardField);
                }

                blackboard.GraphVariables.Add(blackboardField);
                blackboard.RestoreSelectionForElement(blackboardField);
            }

            // Apply expanded states for (weak) elements that could not survive a domain reload
            bool expandedValue;
            foreach (BlackboardSection blackBoardSection in blackboard.Sections)
            {
                blackBoardSection.Query <ExpandableRow>().ForEach(row =>
                {
                    var model = row.userData is IVariableDeclarationModel data ? data : null;
                    if (model != null && expandedRows.TryGetValue(model, out expandedValue))
                    {
                        row.Expanded = expandedValue;
                    }
                    else if (row.userData is string str && expandedRows.TryGetValue(str, out expandedValue))
                    {
                        row.Expanded = expandedValue;
                    }
                });

                blackBoardSection.Query <BlackboardRow>().ForEach(row =>
                {
                    if (row.userData is IVariableDeclarationModel model && expandedRows.TryGetValue(model, out expandedValue))
                    {
                        row.expanded = expandedValue;
                    }
Esempio n. 5
0
        public void RebuildSections(Blackboard blackboard)
        {
            VSGraphModel currentGraphModel = (VSGraphModel)blackboard.Store.GetState().CurrentGraphModel;

            Dictionary <IVariableDeclarationModel, bool> expandedRows = new Dictionary <IVariableDeclarationModel, bool>();

            foreach (BlackboardSection blackBoardSection in blackboard.Sections)
            {
                foreach (VisualElement visualElement in blackBoardSection.Children())
                {
                    if (visualElement is BlackboardRow row)
                    {
                        if (row.userData is IVariableDeclarationModel model)
                        {
                            expandedRows[model] = row.expanded;
                        }
                        else if (row.userData is Tuple <IVariableDeclarationModel, bool> modelTuple)
                        {
                            expandedRows[modelTuple.Item1] = row.expanded;
                        }
                    }
                }
            }

            blackboard.ClearContents();

            if (CanDisplayThisToken)
            {
                var thisNodeModel = currentGraphModel.NodeModels.OfType <ThisNodeModel>().FirstOrDefault();
                var thisField     = new BlackboardThisField(blackboard.GraphView, thisNodeModel, currentGraphModel);
                blackboard.Sections[k_MainSection].Add(thisField);
                blackboard.GraphVariables.Add(thisField);
                blackboard.RestoreSelectionForElement(thisField);
            }

            // Fetch all fields from the GraphModel in the main section
            foreach (IVariableDeclarationModel variableDeclarationModel in ((IVSGraphModel)currentGraphModel).GraphVariableModels)
            {
                var blackboardField = new BlackboardVariableField(blackboard.Store, variableDeclarationModel, blackboard.GraphView);
                var blackboardRow   = new BlackboardRow(
                    blackboardField,
                    CreateExtendedFieldView(blackboard.Store, variableDeclarationModel, blackboard.Rebuild))
                {
                    userData = variableDeclarationModel,
                    expanded = expandedRows.TryGetValue(variableDeclarationModel, out var expandedValue) && expandedValue
                };
                blackboard.Sections[k_MainSection].Add(blackboardRow);
                blackboard.GraphVariables.Add(blackboardField);
                blackboard.RestoreSelectionForElement(blackboardField);
            }

            if (blackboard.selection != null)
            {
                // Fill local scope section
                foreach (Tuple <IVariableDeclarationModel, bool> variableDeclarationModelTuple in blackboard.GraphView.UIController
                         .GetAllVariableDeclarationsFromSelection(blackboard.selection))
                {
                    var blackboardField = new BlackboardVariableField(blackboard.Store, variableDeclarationModelTuple.Item1, blackboard.GraphView);

                    if (variableDeclarationModelTuple.Item1.VariableType == VariableType.FunctionParameter)
                    {
                        blackboardField.AddToClassList("parameter");
                    }

                    if (variableDeclarationModelTuple.Item2)
                    {
                        var blackboardRow = new BlackboardRow(
                            blackboardField,
                            CreateExtendedFieldView(blackboard.Store, variableDeclarationModelTuple.Item1, blackboard.Rebuild))
                        {
                            userData = variableDeclarationModelTuple,
                            expanded = expandedRows.TryGetValue(variableDeclarationModelTuple.Item1, out var expandedValue) && expandedValue
                        };
                        blackboard.Sections[k_CurrentScopeVariableDeclarationsSection].Add(blackboardRow);
                    }
                    else
                    {
                        blackboardField.AddToClassList("readonly");
                        blackboard.Sections[k_CurrentScopeVariableDeclarationsSection].Add(blackboardField);
                    }

                    blackboard.GraphVariables.Add(blackboardField);

                    blackboard.RestoreSelectionForElement(blackboardField);
                }
            }
        }
 internal void ResetBlackboard()
 {
     Blackboard.ClearContents();
     Blackboard.Clear();
 }