コード例 #1
0
        // Called by GraphDataStore.Subscribe after the model has been changed
        protected override void ModelChanged(GraphData graphData, IGraphDataAction changeAction)
        {
            switch (changeAction)
            {
            case ChangeExposedFlagAction changeExposedFlagAction:
                ViewModel.isInputExposed = Model.generatePropertyBlock;
                DirtyNodes(ModificationScope.Graph);
                m_BlackboardPropertyView.UpdateFromViewModel();
                break;

            case ChangePropertyValueAction changePropertyValueAction:
                DirtyNodes(ModificationScope.Graph);
                m_BlackboardPropertyView.MarkDirtyRepaint();
                break;

            case ResetReferenceNameAction resetReferenceNameAction:
                DirtyNodes(ModificationScope.Graph);
                break;

            case ChangeReferenceNameAction changeReferenceNameAction:
                DirtyNodes(ModificationScope.Graph);
                break;

            case ChangeDisplayNameAction changeDisplayNameAction:
                ViewModel.inputName = Model.displayName;
                DirtyNodes(ModificationScope.Topological);
                m_BlackboardPropertyView.UpdateFromViewModel();
                break;
            }
        }
コード例 #2
0
        void NotifyEventHandler(ISGControlledElement eventHandler, IGraphDataAction changeAction)
        {
            SGControllerChangedEvent e = new SGControllerChangedEvent();

            e.controller = this;
            e.target     = eventHandler;
            e.change     = changeAction;
            eventHandler.OnControllerChanged(ref e);
            if (e.isPropagationStopped)
            {
                return;
            }
            if (eventHandler is VisualElement)
            {
                var element = eventHandler as VisualElement;
                eventHandler = element.GetFirstOfType <ISGControlledElement>();
                while (eventHandler != null)
                {
                    eventHandler.OnControllerChanged(ref e);
                    if (e.isPropagationStopped)
                    {
                        break;
                    }
                    eventHandler = (eventHandler as VisualElement).GetFirstAncestorOfType <ISGControlledElement>();
                }
            }
        }
コード例 #3
0
        // Called by GraphDataStore.Subscribe after the model has been changed
        protected override void ModelChanged(GraphData graphData, IGraphDataAction changeAction)
        {
            switch (changeAction)
            {
            // If newly added input doesn't belong to any of the sections, add it to the appropriate default section
            case AddShaderInputAction addBlackboardItemAction:
                if (IsInputInSection(addBlackboardItemAction.shaderInputReference))
                {
                    var blackboardRow = InsertBlackboardRow(addBlackboardItemAction.shaderInputReference);

                    // Rows should auto-expand when an input is first added
                    // blackboardRow.expanded = true;

                    var propertyView = blackboardRow.Q <BlackboardPropertyView>();
                    if (addBlackboardItemAction.addInputActionType == AddShaderInputAction.AddActionSource.AddMenu)
                    {
                        propertyView.OpenTextEditor();
                    }
                }
                break;

            case DeleteShaderInputAction deleteShaderInputAction:
                foreach (var shaderInput in deleteShaderInputAction.shaderInputsToDelete)
                {
                    if (IsInputInSection(shaderInput))
                    {
                        RemoveBlackboardRow(shaderInput);
                    }
                }
                break;

            case HandleUndoRedoAction handleUndoRedoAction:
                foreach (var shaderInput in graphData.removedInputs)
                {
                    if (IsInputInSection(shaderInput))
                    {
                        RemoveBlackboardRow(shaderInput);
                    }
                }

                foreach (var shaderInput in graphData.addedInputs)
                {
                    if (IsInputInSection(shaderInput))
                    {
                        InsertBlackboardRow(shaderInput);
                    }
                }
                break;

            case CopyShaderInputAction copyShaderInputAction:
                if (IsInputInSection(copyShaderInputAction.copiedShaderInput))
                {
                    InsertBlackboardRow(copyShaderInputAction.copiedShaderInput, copyShaderInputAction.insertIndex);
                }
                break;
            }
        }
コード例 #4
0
        protected void NotifyChange(IGraphDataAction changeAction)
        {
            var eventHandlers = m_EventHandlers.ToArray(); // Some notification may trigger Register/Unregister so duplicate the collection.

            foreach (var eventHandler in eventHandlers)
            {
                UnityEngine.Profiling.Profiler.BeginSample("NotifyChange:" + eventHandler.GetType().Name);
                NotifyEventHandler(eventHandler, changeAction);
                UnityEngine.Profiling.Profiler.EndSample();
            }
        }
コード例 #5
0
        // Called by GraphDataStore.Subscribe after the model has been changed
        protected override void ModelChanged(GraphData graphData, IGraphDataAction changeAction)
        {
            switch (changeAction)
            {
            case ChangeExposedFlagAction changeExposedFlagAction:
                // ModelChanged is called overzealously on everything
                // but we only care if the action pertains to our Model
                if (changeExposedFlagAction.shaderInputReference == Model)
                {
                    ViewModel.isInputExposed = Model.generatePropertyBlock;
                    if (changeExposedFlagAction.oldIsExposedValue != changeExposedFlagAction.newIsExposedValue)
                    {
                        DirtyNodes(ModificationScope.Graph);
                    }
                    m_SgBlackboardField.UpdateFromViewModel();
                }
                break;

            case ChangePropertyValueAction changePropertyValueAction:
                if (changePropertyValueAction.shaderInputReference == Model)
                {
                    DirtyNodes(ModificationScope.Graph);
                    m_SgBlackboardField.MarkDirtyRepaint();
                }
                break;

            case ResetReferenceNameAction resetReferenceNameAction:
                if (resetReferenceNameAction.shaderInputReference == Model)
                {
                    DirtyNodes(ModificationScope.Graph);
                }
                break;

            case ChangeReferenceNameAction changeReferenceNameAction:
                if (changeReferenceNameAction.shaderInputReference == Model)
                {
                    DirtyNodes(ModificationScope.Graph);
                }
                break;

            case ChangeDisplayNameAction changeDisplayNameAction:
                if (changeDisplayNameAction.shaderInputReference == Model)
                {
                    ViewModel.inputName = Model.displayName;
                    DirtyNodes(ModificationScope.Topological);
                    m_SgBlackboardField.UpdateFromViewModel();
                }
                break;
            }
        }
コード例 #6
0
 void RequestModelChange(IGraphDataAction changeAction)
 {
     node.owner?.owner.graphDataStore.Dispatch(changeAction);
 }
コード例 #7
0
        // Called by GraphDataStore.Subscribe after the model has been changed
        protected override void ModelChanged(GraphData graphData, IGraphDataAction changeAction)
        {
            // If categoryData associated with this controller is removed by an operation, destroy controller and views associated
            if (graphData.ContainsCategory(Model) == false)
            {
                this.Destroy();
                return;
            }

            switch (changeAction)
            {
            case AddShaderInputAction addBlackboardItemAction:
                if (addBlackboardItemAction.shaderInputReference != null && IsInputInCategory(addBlackboardItemAction.shaderInputReference))
                {
                    var blackboardRow = FindBlackboardRow(addBlackboardItemAction.shaderInputReference);
                    if (blackboardRow == null)
                    {
                        blackboardRow = InsertBlackboardRow(addBlackboardItemAction.shaderInputReference);
                    }
                    // Rows should auto-expand when an input is first added
                    // blackboardRow.expanded = true;
                    var propertyView = blackboardRow.Q <SGBlackboardField>();
                    if (addBlackboardItemAction.addInputActionType == AddShaderInputAction.AddActionSource.AddMenu)
                    {
                        propertyView.OpenTextEditor();
                    }
                }
                break;

            case CopyShaderInputAction copyShaderInputAction:
                // In the specific case of only-one keywords like Material Quality and Raytracing, they can get copied, but because only one can exist, the output copied value is null
                if (copyShaderInputAction.copiedShaderInput != null && IsInputInCategory(copyShaderInputAction.copiedShaderInput))
                {
                    var blackboardRow = InsertBlackboardRow(copyShaderInputAction.copiedShaderInput, copyShaderInputAction.insertIndex);
                    if (blackboardRow != null)
                    {
                        var graphView    = ViewModel.parentView.GetFirstAncestorOfType <MaterialGraphView>();
                        var propertyView = blackboardRow.Q <SGBlackboardField>();
                        graphView?.AddToSelectionNoUndoRecord(propertyView);
                    }
                }
                break;

            case AddItemToCategoryAction addItemToCategoryAction:
                // If item was added to category that this controller manages, then add blackboard row to represent that item
                if (addItemToCategoryAction.itemToAdd != null && addItemToCategoryAction.categoryGuid == ViewModel.associatedCategoryGuid)
                {
                    InsertBlackboardRow(addItemToCategoryAction.itemToAdd, addItemToCategoryAction.indexToAddItemAt);
                }
                else
                {
                    // If the added input has been added to a category other than this one, and it used to belong to this category,
                    // Then cleanup the controller and view that used to represent that input
                    foreach (var key in m_BlackboardItemControllers.Keys)
                    {
                        var blackboardItemController = m_BlackboardItemControllers[key];
                        if (blackboardItemController.Model == addItemToCategoryAction.itemToAdd)
                        {
                            RemoveBlackboardRow(addItemToCategoryAction.itemToAdd);
                            break;
                        }
                    }
                }
                break;

            case DeleteCategoryAction deleteCategoryAction:
                if (deleteCategoryAction.categoriesToRemoveGuids.Contains(ViewModel.associatedCategoryGuid))
                {
                    this.Destroy();
                    return;
                }

                break;

            case ChangeCategoryIsExpandedAction changeIsExpandedAction:
                if (changeIsExpandedAction.categoryGuids.Contains(ViewModel.associatedCategoryGuid))
                {
                    ViewModel.isExpanded = changeIsExpandedAction.isExpanded;
                    m_BlackboardCategoryView.TryDoFoldout(changeIsExpandedAction.isExpanded);
                }
                break;

            case ChangeCategoryNameAction changeCategoryNameAction:
                if (changeCategoryNameAction.categoryGuid == ViewModel.associatedCategoryGuid)
                {
                    ViewModel.name = Model.name;
                    m_BlackboardCategoryView.title = ViewModel.name;
                }
                break;
            }
        }
コード例 #8
0
 protected override void RequestModelChange(IGraphDataAction changeAction)
 {
     DataStore.Dispatch(changeAction);
 }