// ----------------------------------------------------------------------------------------- public void Generate_Subscriber_Grid_Spacing_Field() { var v2 = new Vector2Property(); v2.PropertyName = _TranzmitGraphView.GridLayoutSpacing_Subscriber.PropertyName; v2.PropertyValue = _TranzmitGraphView.GridLayoutSpacing_Subscriber.PropertyValue; var visualElement = new VisualElement(); var blackboardField = new BlackboardField { text = v2.PropertyName, typeText = "" }; visualElement.Add(blackboardField); var field = new Vector2Field("Value:"); field.value = v2.PropertyValue; field.RegisterValueChangedCallback(ChangeEvent => { _TranzmitGraphView.GridLayoutSpacing_Subscriber.PropertyValue = field.value; if (_TranzmitGraphView.CurrentArrangementType == Tranzmit_Graph_View.ArrangementTypes.Grid) { _TranzmitGraphView.Arrange_Subscriber_Results(Tranzmit_Graph_View.ArrangementTypes.Grid); } }); var blackBoardValueRow = new BlackboardRow(blackboardField, field); visualElement.Add(blackBoardValueRow); _TranzmitGraphView.Blackboard.Add(visualElement); }
private VisualElement GenerateBlackboardField(ExposedProperty property) { var container = new VisualElement(); var blackboardField = new BlackboardField { text = property.propertyName, typeText = "String", }; container.Add(blackboardField); var propertyValueTextField = new TextField("Value:"); propertyValueTextField.Q(className: "unity-label").style.minWidth = 50; propertyValueTextField.value = property.propertyValue; propertyValueTextField.RegisterValueChangedCallback(evt => { int changingPropertyIndex = graphView.exposedProperties.FindIndex( exposedProperty => exposedProperty.propertyName == property.propertyName); graphView.exposedProperties[changingPropertyIndex].propertyValue = evt.newValue; }); var blackboardValueRow = new BlackboardRow(propertyValueTextField, propertyValueTextField); container.Add(blackboardValueRow); return(container); }
// ----------------------------------------------------------------------------------------- public void Generate_Broadcaster_Vertical_Spacing_Field() { var floatProp = new FloatProperty(); floatProp.PropertyName = _TranzmitGraphView.VerticalYSpacing_Broadcaster.PropertyName; floatProp.PropertyValue = _TranzmitGraphView.VerticalYSpacing_Broadcaster.PropertyValue; var visualElement = new VisualElement(); var blackboardField = new BlackboardField { text = floatProp.PropertyName, typeText = "" }; visualElement.Add(blackboardField); var field = new FloatField("Value:"); field.value = floatProp.PropertyValue; field.RegisterValueChangedCallback(ChangeEvent => { _TranzmitGraphView.VerticalYSpacing_Broadcaster.PropertyValue = field.value; if (_TranzmitGraphView.CurrentArrangementType == Tranzmit_Graph_View.ArrangementTypes.Vertical) { _TranzmitGraphView.Arrange_Broadcaster_Results(Tranzmit_Graph_View.ArrangementTypes.Vertical); } }); var blackBoardValueRow = new BlackboardRow(blackboardField, field); visualElement.Add(blackBoardValueRow); _TranzmitGraphView.Blackboard.Add(visualElement); }
public Blackboard(VisualElement visualParent, GraphView graph) { m_visualParent = visualParent; UnityEditor.Experimental.GraphView.Blackboard bb = new UnityEditor.Experimental.GraphView.Blackboard(graph); //bb.subTitle = string.Empty; //m_visualParent.Add(bb); graph.Add(bb); bb.title = "Test Blackboard"; BlackboardSection bbSection = new BlackboardSection(); bbSection.title = "Section Test Name"; bbSection.headerVisible = true; bb.Add(bbSection); BlackboardField bbField = new BlackboardField(); bbField.title = "TestVariable"; bbField.text = "TestText"; //bbSection.Add(bbField); BlackboardRow bbRow = new BlackboardRow(bbField, new VisualElement()); bbSection.Add(bbRow); bbSection.Add(bbRow); Debug.Log($"Is Field Droppable {bbField.IsDroppable()}"); }
private void ElementDeletedCallback(VisualElement ve) { if (m_MathBook == null) { return; } switch (ve.userData) { case MathNode node: m_GraphView.window.DestroyNode(node); break; case MathPlacemat placemat: m_GraphView.window.DestroyPlacemat(placemat); break; case MathStickyNote stickyNote: m_GraphView.window.DestroyStickyNote(stickyNote); break; case MathBookField mathBookField: m_MathBook.inputOutputs.RemoveField(mathBookField); // Removes the containing row from its parent section BlackboardRow row = ve.GetFirstAncestorOfType <BlackboardRow>(); if (row != null) { row.RemoveFromHierarchy(); } break; } }
internal void AddPropertyToBlackBoard(ExposedProperty exposedProperty) { var localPropertyName = exposedProperty.PropertyName; var localPropertyValue = exposedProperty.PropertyValue; while (ExposedProperties.Any(x => x.PropertyName == localPropertyName)) { localPropertyName = $"{localPropertyName}(1)"; // Username || Username(1) } var property = new ExposedProperty(); property.PropertyName = localPropertyName; property.PropertyValue = localPropertyValue; ExposedProperties.Add(property); var container = new VisualElement(); var blackboardField = new BlackboardField { text = property.PropertyName, typeText = "string property" }; var propertyValueTextField = new TextField("Value: ") { value = localPropertyValue }; propertyValueTextField.RegisterValueChangedCallback(evt => { var changingPropertyIndex = ExposedProperties.FindIndex(x => x.PropertyName == property.PropertyName); ExposedProperties[changingPropertyIndex].PropertyValue = evt.newValue; }); var blackBoardValueRow = new BlackboardRow(blackboardField, propertyValueTextField); container.Add(blackBoardValueRow); Blackboard.Add(container); }
// ----------------------------------------------------------------------------------------- public void Generate_BlackBoard_Error_Color_Field() { var color = new ColorProperty(); color.PropertyName = _TranzmitGraphView.ErrorColor.PropertyName; color.PropertyValue = _TranzmitGraphView.ErrorColor.PropertyValue; var visualElement = new VisualElement(); var blackboardField = new BlackboardField { text = color.PropertyName, typeText = "" }; visualElement.Add(blackboardField); var field = new ColorField("Value:"); field.value = color.PropertyValue; field.RegisterValueChangedCallback(ChangeEvent => { _TranzmitGraphView.ErrorColor.PropertyValue = field.value; _TranzmitGraphView.UpdateErrorColorsOnGraphElements(); }); var blackBoardValueRow = new BlackboardRow(blackboardField, field); visualElement.Add(blackBoardValueRow); _TranzmitGraphView.Blackboard.Add(visualElement); }
/// <summary> /// The Blackboard contains the values of each Exposed Property /// This Method allows us to create a new exposed property and adds it to the BlackBoard /// </summary> /// <param name="exposedProperty"></param> /// <param name="refreshing"></param> public void AddPropertyToBlackBoard(Runtime.ExposedProperty exposedProperty, bool refreshing = false) { var localPropertyName = exposedProperty.PropertyName; var localPropertyValue = exposedProperty.PropertyValue; while (ExposedProperties.Any(x => x.PropertyName == localPropertyName) && !refreshing) { localPropertyName = $"{localPropertyName}(1)"; } if (!refreshing) { var property = new Runtime.ExposedProperty(); property.PropertyName = localPropertyName; property.PropertyValue = localPropertyValue; ExposedProperties.Add(property); } int j = ExposedProperties.Count - 1; var container = new VisualElement(); var blackboardField = new BlackboardField { text = localPropertyName, typeText = "string" }; blackboardField.Add(new Button(() => { RemovePropertyFromBlackboard(j); }) { text = "x" }); container.Add(blackboardField); var propertyValueTextField = new TextField(label: "Value:") { value = localPropertyValue }; propertyValueTextField.RegisterValueChangedCallback(evt => { int i = j; var changingPropertyIndex = ExposedProperties.FindIndex(x => x.PropertyName == localPropertyName); ExposedProperties[i].PropertyValue = evt.newValue; }); var blackBoardValueRow = new BlackboardRow(blackboardField, propertyValueTextField); container.Add(blackBoardValueRow); _blackboard.Add(container); if (_dialogueGraph.GetAutoSave()) { _dialogueGraph.RequestDataOperation(true); } }
void OnBlackboardDataRenamed(string _oldName, string _newName) { BlackboardRow blackboardRow = fields[_oldName]; (blackboardRow.Q(className: "blackboardField") as BlackboardField).text = _newName; fields.Remove(_oldName); fields[_newName] = blackboardRow; MarkDirtyRepaint(); }
public IEnumerator BlackboardSelectionIsRestoredWhenEnteringPlaymode_AddFieldsAfterAddingBBToGV() { { // Create initial blackboard. var blackboard = new Blackboard(); blackboard.SetupBuildAndUpdate(null, CommandDispatcher, graphView); var inSection = new BlackboardSection(blackboard, "Section 1"); blackboard.Add(inSection); var field = new BlackboardField { viewDataKey = "bfield" }; var propertyView = new Label("Prop"); var row = new BlackboardRow(); row.Add(field); row.Add(propertyView); inSection.Add(row); graphView.AddElement(blackboard); CommandDispatcher.Dispatch(new SelectElementsCommand(SelectElementsCommand.SelectionMode.Add, row.Model)); Assert.True(row.IsSelected()); } // Allow 1 frame to let the persistent data get saved yield return(null); // This will re-create the window, flushing all temporary state yield return(new EnterPlayMode()); // Allow 1 frame to let the persistence be restored yield return(null); { // Add blackboard to graphview first then add field to blackboard. var blackboard = new Blackboard(); blackboard.SetupBuildAndUpdate(null, CommandDispatcher, graphView); graphView.AddElement(blackboard); var inSection = new BlackboardSection(blackboard, "Section 1"); blackboard.Add(inSection); var field = new BlackboardField { viewDataKey = "bfield" }; var propertyView = new Label("Prop"); var row = new BlackboardRow(); row.Add(field); row.Add(propertyView); inSection.Add(row); Assert.True(row.IsSelected()); } }
public void AddFromData(UdonNodeData nodeData) { UdonNodeDefinition definition = UdonEditorManager.Instance.GetNodeDefinition(nodeData.fullName); if (definition != null) { BlackboardRow row = new BlackboardRow(new UdonParameterField(_graph, nodeData), new UdonParameterProperty(_graph, definition, nodeData)); contentContainer.Add(row); _idToRow.Add(nodeData.uid, row); } }
public void AddPropertyToBlackBoard(ExposedVariable exposedVariable) { var localVariableName = exposedVariable.variableName; var localVariableValue = exposedVariable.variableValue; int iterator = 1; while (exposedVariables.Any(x => x.variableName == localVariableName)) { localVariableName = $"{localVariableName}({iterator})"; iterator++; /* FIX Later * if (localVariableName.Contains($"({iterator - 1})")) { * localVariableName = $"{localVariableName.Substring(0, localVariableName.Length -3}" +"({iterator})"; * } */ } var variable = new ExposedVariable(); variable.variableName = localVariableName; variable.variableValue = localVariableValue; exposedVariables.Add(variable); var container = new VisualElement(); var blackboardField = new BlackboardField { text = variable.variableName, typeText = "int variable" }; // blackboardField.RegisterCallback<DragAndDrop>(evt => { }); container.Add(blackboardField); var variableValueTextField = new TextField("Value:") { value = variable.variableValue }; variableValueTextField.RegisterValueChangedCallback(evt => { var changingVariableIndex = exposedVariables.FindIndex(x => x.variableName == variable.variableName); exposedVariables[changingVariableIndex].variableValue = evt.newValue; }); var blackboardValueRow = new BlackboardRow(blackboardField, variableValueTextField); container.Add(blackboardValueRow); blackboard.Add(container); }
protected virtual void UpdateParameterList() { content.Clear(); foreach (var param in graphAsset.uniExposedParameters) { var fieldView = new UniExposedParameterFieldView(graphAsset, param, Remove); var propertyView = new UniExposedParameterPropertyView(graphView, param); var row = new BlackboardRow(fieldView, propertyView); content.Add(row); } }
public IEnumerator BlackboardSelectionIsRestoredWhenEnteringPlaymode_AddFieldsBeforeAddingBBToGV() { { // Create initial blackboard. var blackboard = new Blackboard(); var inSection = new BlackboardSection(); blackboard.Add(inSection); var field = new BlackboardField() { viewDataKey = "bfield" }; var propertyView = new Label("Prop"); var row = new BlackboardRow(field, propertyView); inSection.Add(row); graphView.AddElement(blackboard); graphView.AddToSelection(field); Assert.True(field.selected); } // Allow 1 frame to let the persistent data get saved yield return(null); // This will re-create the window, flushing all temporary state yield return(new EnterPlayMode()); // Allow 1 frame to let the persistence be restored yield return(null); { // Add field to blackboard first then add blackboard to graphview. var blackboard = new Blackboard(); var inSection = new BlackboardSection(); blackboard.Add(inSection); var field = new BlackboardField() { viewDataKey = "bfield" }; var propertyView = new Label("Prop"); var row = new BlackboardRow(field, propertyView); inSection.Add(row); graphView.AddElement(blackboard); Assert.True(field.selected); } }
public void AddPropertyToBlackBoard(ExposedProperty exposedProperty) { int duplicateNameIndex = 1; string localPropertyName = exposedProperty.PropertyName; string localPropertyValue = exposedProperty.PropertyValue; while (ExposedProperties.Any(x => x.PropertyName == localPropertyName)) { localPropertyName = $"{localPropertyName}{duplicateNameIndex}"; // Name || Name1 || Name12 duplicateNameIndex++; } ExposedProperty property = new ExposedProperty(); property.PropertyName = localPropertyName; property.PropertyValue = localPropertyValue; ExposedProperties.Add(property); VisualElement container = new VisualElement(); BlackboardField field = new BlackboardField { text = property.PropertyName, typeText = "string", }; container.Add(field); TextField propertyValueTextField = new TextField("Value : ") { value = localPropertyValue, style = { width = new Length(80, LengthUnit.Percent) } }; propertyValueTextField.RegisterValueChangedCallback(delegate(ChangeEvent <string> evt) { int changingPropertyIndex = ExposedProperties.FindIndex(x => x.PropertyName == property.PropertyName); ExposedProperties[changingPropertyIndex].PropertyValue = evt.newValue; }); BlackboardRow blackboardRow = new BlackboardRow(field, propertyValueTextField); container.Add(blackboardRow); if (Blackboard != null) { Blackboard.Add(container); } }
protected virtual void UpdateParameterList() { content.Clear(); foreach (var param in graphView.graph.exposedParameters) { var row = new BlackboardRow(new ExposedParameterFieldView(graphView, param), new ExposedParameterPropertyView(graphView, param)); row.expanded = param.settings.expanded; row.RegisterCallback <GeometryChangedEvent>(e => { param.settings.expanded = row.expanded; }); content.Add(row); } }
private void AddBlackboardRow(BlackboardElement blackboardEle, SerializedProperty serializedBlackboardEle, int index) { BlackboardElementView elementView = new BlackboardElementView(blackboardEle, serializedBlackboardEle, () => { DeleteElement(index); }); PropertyField propF = new PropertyField(serializedBlackboardEle .FindPropertyRelative(BlackboardElement.ValueWrapper_VarName) .FindPropertyRelative(BlackboardElement.Value_VarName)); propF.Bind(serializedBlackboardEle.serializedObject); BlackboardRow br = new BlackboardRow(elementView, propF); m_allElementRows.Add(br); Add(br); }
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 CharacterProperty(string propertyName, string propertyValue, DialogueGraphView dialogueGraphView) { graphView = dialogueGraphView; propertyType = BlackboardType.Character; PropertyName = propertyName; PropertyValue = propertyValue; propertyElement = new VisualElement(); var blackboardField = new BlackboardField { text = propertyName, typeText = "Character" }; blackboardField.Q <Label>("typeLabel").style.flexBasis = StyleKeyword.Auto; blackboardField.capabilities &= ~Capabilities.Deletable; blackboardField.RegisterCallback <ContextualMenuPopulateEvent>(PopulateDeleteOption); blackboardField.Add(new Button(() => { graphView.RemovePropertyFromBlackboard(this.PropertyName); }) { text = "X" }); propertyElement.Add(blackboardField); var propertyValueTextField = new TextField("Value:") { value = PropertyValue }; propertyValueTextField.Q <Label>().style.minWidth = StyleKeyword.Auto; propertyValueTextField.RegisterValueChangedCallback(evt => { var changingPropertyIndex = graphView.exposedProperties.FindIndex(x => x.PropertyName == this.PropertyName); if (changingPropertyIndex < 0) { return; } graphView.exposedProperties[changingPropertyIndex].PropertyValue = evt.newValue; propertyValueTextField.value = evt.newValue; }); var blackboardValueRow = new BlackboardRow(blackboardField, propertyValueTextField); propertyElement.Add(blackboardValueRow); }
public void AddPropertyToBlackBoard(ExposedProperty property, bool loadMode = false) { var localPropertyName = property.PropertyName; var localPropertyValue = property.PropertyValue; // var localPropertySprite = property.PropertySprite; var localPropertyNameCharacter = property.PropertyNameCharacter; if (!loadMode) { while (ExposedProperties.Any(x => x.PropertyName == localPropertyName)) { localPropertyName = $"{localPropertyName}(1)"; } } var item = ExposedProperty.CreateInstance(); item.PropertyName = localPropertyName; item.PropertyValue = localPropertyValue; item.PropertyNameCharacter = localPropertyNameCharacter; // item.PropertySprite = localPropertySprite; ExposedProperties.Add(item); var container = new VisualElement(); //Serch Elements in BlackBoard var field = new BlackboardField { text = localPropertyName, typeText = "string" }; container.Add(field); var propertyValueTextField = new TextField("Value:") { value = localPropertyValue }; propertyValueTextField.RegisterValueChangedCallback(evt => { var index = ExposedProperties.FindIndex(x => x.PropertyName == item.PropertyName); ExposedProperties[index].PropertyValue = evt.newValue; }); var sa = new BlackboardRow(field, propertyValueTextField); container.Add(sa); Blackboard.Add(container); }
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()) { Model = 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); } }
internal void AddPropertyToBlackBoard(ExposedProperty exposedProperty) { //local var for the blackboard prop var localPropertyName = exposedProperty.PropertyName; var localPropertyValue = exposedProperty.PropertyValue; //loop through and find the any duplicts and another +1 to name while (ExposedProperties.Any(x => x.PropertyName == localPropertyName)) { localPropertyName = $"{localPropertyName}(1)"; // } var property = new ExposedProperty(); property.PropertyName = localPropertyName; property.PropertyValue = localPropertyValue; ExposedProperties.Add(property); var container = new VisualElement(); var blackboardField = new BlackboardField { text = property.PropertyName, typeText = "string property" }; container.Add(blackboardField); //add value fiels into black board var propertyValueTextField = new TextField("value") { value = localPropertyValue }; propertyValueTextField.RegisterValueChangedCallback(evt => { var changingPropertyIndex = ExposedProperties.FindIndex(x => x.PropertyName == property.PropertyName); ExposedProperties[changingPropertyIndex].PropertyValue = evt.newValue; }); var blackBoardValueRow = new BlackboardRow(blackboardField, propertyValueTextField); container.Add(blackBoardValueRow); Blackboard.Add(container); }
void AddProperty(INodeProperty property, bool create = false, int index = -1) { if (m_PropertyRows.ContainsKey(property.guid)) { return; } if (create) { property.displayName = m_Graph.SanitizePropertyName(property.displayName); } var field = new BlackboardField(m_ExposedIcon, property.displayName, property.propertyType.ToString()) { userData = property }; var row = new BlackboardRow(field, new BlackboardFieldPropertyView(m_Graph, property)); row.userData = property; if (index < 0) { index = m_PropertyRows.Count; } if (index == m_PropertyRows.Count) { m_Section.Add(row); } else { m_Section.Insert(index, row); } m_PropertyRows[property.guid] = row; if (create) { row.expanded = true; m_Graph.owner.RegisterCompleteObjectUndo("Create Property"); m_Graph.AddShaderProperty(property); field.OpenTextEditor(); } }
public void AddFieldView(string _name, ICZType _data) { BlackboardField blackboardField = new BlackboardField() { text = _name, typeText = _data.ValueType.Name, userData = _data }; blackboardField.RegisterCallback <MouseEnterEvent>(evt => { GraphView.nodes.ForEach(node => { if (node is ParameterNodeView parameterNodeView && parameterNodeView.T_Model.Name == blackboardField.text) { parameterNodeView.HighlightOn(); } }); }); blackboardField.RegisterCallback <MouseLeaveEvent>(evt => { GraphView.nodes.ForEach(node => { if (node is ParameterNodeView parameterNodeView && parameterNodeView.T_Model.Name == blackboardField.text) { parameterNodeView.HighlightOff(); } }); }); BindableElement fieldDrawer = UIElementsFactory.CreateField("", _data.ValueType, _data.GetValue(), _newValue => { _data.SetValue(_newValue); if (_data.GetValue() != null) { blackboardField.typeText = _data.ValueType.Name; } }); BlackboardRow blackboardRow = new BlackboardRow(blackboardField, fieldDrawer); contentContainer.Add(blackboardRow); fields[_name] = blackboardRow; }
public void AddFromData(UdonNodeData nodeData) { // don't add internal variables, which start with __ // Todo: handle all "__" variables instead, need to tell community first and let the word spread string newVariableName = (string)nodeData.nodeValues[(int)UdonParameterProperty.ValueIndices.name].Deserialize(); if (newVariableName.StartsWithCached("__returnValue")) { return; } UdonNodeDefinition definition = UdonEditorManager.Instance.GetNodeDefinition(nodeData.fullName); if (definition != null) { BlackboardRow row = new BlackboardRow(new UdonParameterField(_graph, nodeData), new UdonParameterProperty(_graph, definition, nodeData)); contentContainer.Add(row); _idToRow.Add(nodeData.uid, row); } }
public void AddPropertyToBlackboard(ExposedProperty exposedProperty) { List <string> existingNamesList = (from p in ExposedProperties select p.PropertyName).ToList(); var localPropertyName = StringUtils.IncrementName(exposedProperty.PropertyName, existingNamesList); var localPropertyValue = exposedProperty.PropertyValue; var property = new ExposedProperty { PropertyName = localPropertyName, PropertyValue = localPropertyValue }; ExposedProperties.Add(property); var container = new VisualElement(); var blackboardField = new BlackboardField { text = property.PropertyName, typeText = "string" }; container.Add(blackboardField); var propertyValueTextField = new TextField("Value:") { value = property.PropertyValue }; propertyValueTextField.RegisterValueChangedCallback(evt => { var changingPropertyIndex = ExposedProperties.FindIndex(x => x.PropertyName == property.PropertyName); ExposedProperties[changingPropertyIndex].PropertyValue = evt.newValue; }); var blackboardValueRow = new BlackboardRow(blackboardField, propertyValueTextField); container.Add(blackboardValueRow); Blackboard.Add(container); }
void AddInputRow(ShaderInput input, bool addToGraph = false, int index = -1) { if (m_InputRows.ContainsKey(input)) { return; } if (addToGraph) { m_Graph.owner.RegisterCompleteObjectUndo("Create Graph Input"); // this pathway is mostly used for adding newly inputs to the graph // so this is setting up the default state for those inputs // here we flag it exposed, if the input type is exposable input.generatePropertyBlock = input.isExposable; m_Graph.AddGraphInput(input); // TODO: index after currently selected property } BlackboardFieldView field = null; BlackboardRow row = null; switch (input) { case AbstractShaderProperty property: { var icon = (m_Graph.isSubGraph || property.isExposed) ? exposedIcon : null; field = new BlackboardFieldView(m_Graph, property, icon, property.displayName, property.GetPropertyTypeString()) { userData = property }; field.RegisterCallback <AttachToPanelEvent>(UpdateSelectionAfterUndoRedo); property.onBeforeVersionChange += (_) => m_Graph.owner.RegisterCompleteObjectUndo($"Change {property.displayName} Version"); void UpdateField() { field.typeText = property.GetPropertyTypeString(); field.InspectorUpdateTrigger(); } property.onAfterVersionChange += UpdateField; row = new BlackboardRow(field, null); if (index < 0 || index > m_InputRows.Count) { index = m_InputRows.Count; } if (index == m_InputRows.Count) { m_PropertySection.Add(row); } else { m_PropertySection.Insert(index, row); } break; } case ShaderKeyword keyword: { var icon = (m_Graph.isSubGraph || keyword.isExposed) ? exposedIcon : null; string typeText = keyword.keywordType.ToString() + " Keyword"; typeText = keyword.isBuiltIn ? "Built-in " + typeText : typeText; field = new BlackboardFieldView(m_Graph, keyword, icon, keyword.displayName, typeText) { userData = keyword }; field.RegisterCallback <AttachToPanelEvent>(UpdateSelectionAfterUndoRedo); row = new BlackboardRow(field, null); if (index < 0 || index > m_InputRows.Count) { index = m_InputRows.Count; } if (index == m_InputRows.Count) { m_KeywordSection.Add(row); } else { m_KeywordSection.Insert(index, row); } break; } default: throw new ArgumentOutOfRangeException(); } field.RegisterCallback <MouseEnterEvent>(evt => OnMouseHover(evt, input)); field.RegisterCallback <MouseLeaveEvent>(evt => OnMouseHover(evt, input)); field.RegisterCallback <DragUpdatedEvent>(OnDragUpdatedEvent); // These callbacks are used for the property dragging scroll behavior field.RegisterCallback <DragEnterEvent>(evt => blackboard.ShowScrollBoundaryRegions()); field.RegisterCallback <DragExitedEvent>(evt => blackboard.HideScrollBoundaryRegions()); // Removing the expand button from the blackboard, its added by default var expandButton = row.Q <Button>("expandButton"); expandButton.RemoveFromHierarchy(); m_InputRows[input] = row; if (!addToGraph) { m_InputRows[input].expanded = SessionState.GetBool($"Unity.ShaderGraph.Input.{input.objectId}.isExpanded", false); } else { row.expanded = true; field.OpenTextEditor(); if (input as ShaderKeyword != null) { m_Graph.OnKeywordChangedNoValidate(); } } }
VisualElement MakeFieldRow(FieldModel fieldModel) { var field = new BlackboardField(null, fieldModel.Name, fieldModel.Type?.FriendlyName() ?? "<unknown>"); field.userData = fieldModel; var propertyView = new VisualElement(); var fieldRow = new BlackboardRow(field, propertyView) { userData = fieldModel }; fieldRow.expanded = m_ExpandedRows.Contains(fieldModel); field.Add(new Button(() => DeleteField(fieldRow, fieldModel)) { name = "deleteComponentIcon" }); var fieldType = new Button() { text = fieldModel.Type?.FriendlyName() ?? "<unknown>" }; fieldType.clickable.clicked += () => { InitializeTypeItemsAndCache(); // delay init as the type cache seems to have a weird timing issue otherwise SearcherWindow.Show(this, new Searcher.Searcher(new SearcherDatabase(TypeItems), new TypeSearcherAdapter("Pick a type")), item => { PickTypeSearcherItem titem = item as PickTypeSearcherItem; if (titem == null) { return(true); } fieldModel.Type = titem.Type; fieldType.text = titem.Type.FriendlyName(); if (titem.Shared) { SetStructType(CurrentStruct, StructType.SharedComponent); } SetModelDirty(); return(true); }, Event.current.mousePosition, null); }; propertyView.Add(new PropertyRow("Type", fieldType)); var toggle = new Toggle() { value = fieldModel.HideInInspector }; toggle.RegisterValueChangedCallback(e => { fieldModel.HideInInspector = e.newValue; SetModelDirty(); }); propertyView.Add(new PropertyRow("Hide in inspector", toggle)); // TODO ugly if (!fieldModel.Type.IsValueType && fieldModel.Type != typeof(GameObject)) { propertyView.Add(new Label("This is a reference type and requires the component to be a shared component")); } return(fieldRow); }
void DeleteField(BlackboardRow field, FieldModel fieldModel) { fieldModel.RemoveFromStruct(); field.RemoveFromHierarchy(); SetModelDirty(); }
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; }