// 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; } }