VisualElement CreateGUI(CustomFunctionNode node, InspectableAttribute attribute, out VisualElement propertyVisualElement) { var propertySheet = new PropertySheet(PropertyDrawerUtils.CreateLabel($"{node.name} Node", 0, FontStyle.Bold)); PropertyDrawerUtils.AddDefaultNodeProperties(propertySheet, node, m_setNodesAsDirtyCallback, m_updateNodeViewsCallback); var inputListView = new ReorderableSlotListView(node, SlotType.Input, true); inputListView.OnAddCallback += list => inspectorUpdateDelegate(); inputListView.OnRemoveCallback += list => inspectorUpdateDelegate(); inputListView.OnListRecreatedCallback += () => inspectorUpdateDelegate(); propertySheet.Add(inputListView); var outputListView = new ReorderableSlotListView(node, SlotType.Output, true); outputListView.OnAddCallback += list => inspectorUpdateDelegate(); outputListView.OnRemoveCallback += list => inspectorUpdateDelegate(); outputListView.OnListRecreatedCallback += () => inspectorUpdateDelegate(); propertySheet.Add(outputListView); propertySheet.Add(new HlslFunctionView(node)); propertyVisualElement = null; return(propertySheet); }
public void LoadGraph() { m_Object = ScriptableObject.CreateInstance <TestGraphObject>(); m_Object.Initialize(kGraphName); m_Graph = m_Object.graph; Assert.NotNull(m_Graph, $"Invalid graph data found for {kGraphName}"); m_CFNode = m_Graph.GetNodes <CustomFunctionNode>().FirstOrDefault(); Assert.NotNull(m_CFNode, $"No CustomFunctionNode found in {kGraphName}."); }
public void LoadGraph() { List <PropertyCollector.TextureInfo> lti; var lsadp = new List <string>(); ShaderGraphImporter.GetShaderText(kGraphName, out lti, lsadp, out m_Graph); Assert.NotNull(m_Graph, $"Invalid graph data found for {kGraphName}"); m_CFNode = m_Graph.GetNodes <CustomFunctionNode>().FirstOrDefault(); Assert.NotNull(m_CFNode, $"No CustomFunctionNode found in {kGraphName}."); }
private void Draw(CustomFunctionNode node) { var currentControls = this.Children().ToArray(); for (int i = 0; i < currentControls.Length; i++) { currentControls[i].RemoveFromHierarchy(); } m_Type = new EnumField(node.sourceType); m_Type.RegisterValueChangedCallback(s => { if ((HlslSourceType)s.newValue != node.sourceType) { node.owner.owner.RegisterCompleteObjectUndo("Change Function Type"); node.sourceType = (HlslSourceType)s.newValue; Draw(node); node.ValidateNode(); node.Dirty(ModificationScope.Graph); } }); m_FunctionName = new TextField { value = node.functionName, multiline = false }; m_FunctionName.RegisterCallback <FocusInEvent>(s => { if (m_FunctionName.value == CustomFunctionNode.defaultFunctionName) { m_FunctionName.value = ""; } }); m_FunctionName.RegisterCallback <FocusOutEvent>(s => { if (m_FunctionName.value == "") { m_FunctionName.value = CustomFunctionNode.defaultFunctionName; } else { m_FunctionName.value = NodeUtils.ConvertToValidHLSLIdentifier(m_FunctionName.value); } if (m_FunctionName.value != node.functionName) { node.owner.owner.RegisterCompleteObjectUndo("Change Function Name"); node.functionName = m_FunctionName.value; node.ValidateNode(); node.Dirty(ModificationScope.Graph); } }); string path = AssetDatabase.GUIDToAssetPath(node.functionSource); m_FunctionSource = new ObjectField() { value = AssetDatabase.LoadAssetAtPath <TextAsset>(path), objectType = typeof(TextAsset) }; m_FunctionSource.RegisterValueChangedCallback(s => { long localId; string guidString = string.Empty; if (s.newValue != null) { AssetDatabase.TryGetGUIDAndLocalFileIdentifier((TextAsset)s.newValue, out guidString, out localId); } if (guidString != node.functionSource) { node.owner.owner.RegisterCompleteObjectUndo("Change Function Source"); node.functionSource = guidString; node.ValidateNode(); node.Dirty(ModificationScope.Graph); } }); m_FunctionBody = new TextField { value = node.functionBody, multiline = true }; m_FunctionBody.RegisterCallback <FocusInEvent>(s => { if (m_FunctionBody.value == CustomFunctionNode.defaultFunctionBody) { m_FunctionBody.value = ""; } }); m_FunctionBody.RegisterCallback <FocusOutEvent>(s => { if (m_FunctionBody.value == "") { m_FunctionBody.value = CustomFunctionNode.defaultFunctionBody; } if (m_FunctionBody.value != node.functionBody) { node.owner.owner.RegisterCompleteObjectUndo("Change Function Body"); node.functionBody = m_FunctionBody.value; node.ValidateNode(); node.Dirty(ModificationScope.Graph); } }); VisualElement typeRow = new VisualElement() { name = "Row" }; { typeRow.Add(new Label("Type")); typeRow.Add(m_Type); } Add(typeRow); VisualElement nameRow = new VisualElement() { name = "Row" }; { nameRow.Add(new Label("Name")); nameRow.Add(m_FunctionName); } Add(nameRow); switch (node.sourceType) { case HlslSourceType.File: VisualElement sourceRow = new VisualElement() { name = "Row" }; { sourceRow.Add(new Label("Source")); sourceRow.Add(m_FunctionSource); } Add(sourceRow); break; case HlslSourceType.String: VisualElement bodyRow = new VisualElement() { name = "Row" }; { bodyRow.Add(new Label("Body")); bodyRow.style.height = 200; bodyRow.Add(m_FunctionBody); } Add(bodyRow); break; } }
internal HlslFunctionView(CustomFunctionNode node) { styleSheets.Add(Resources.Load <StyleSheet>("Styles/HlslFunctionView")); Draw(node); }
private void Draw(CustomFunctionNode node) { var currentControls = this.Children().ToArray(); for (int i = 0; i < currentControls.Length; i++) { currentControls[i].RemoveFromHierarchy(); } m_Type = new EnumField(node.sourceType); m_Type.RegisterValueChangedCallback(s => { node.owner.owner.RegisterCompleteObjectUndo("Function Change"); node.sourceType = (HlslSourceType)s.newValue; Draw(node); node.Dirty(ModificationScope.Graph); }); m_FunctionName = new TextField { value = node.functionName, multiline = false }; m_FunctionName.RegisterValueChangedCallback(s => { node.owner.owner.RegisterCompleteObjectUndo("Function Change"); node.functionName = s.newValue; }); m_FunctionName.RegisterCallback <FocusOutEvent>(s => { node.Dirty(ModificationScope.Graph); }); m_FunctionSource = new TextField { value = node.functionSource, multiline = false }; m_FunctionSource.RegisterValueChangedCallback(s => { node.owner.owner.RegisterCompleteObjectUndo("Function Change"); node.functionSource = s.newValue; }); m_FunctionSource.RegisterCallback <FocusOutEvent>(s => { node.Dirty(ModificationScope.Graph); }); m_FunctionBody = new TextField { value = node.functionBody, multiline = true }; m_FunctionBody.RegisterValueChangedCallback(s => { node.owner.owner.RegisterCompleteObjectUndo("Function Change"); node.functionBody = s.newValue; }); m_FunctionBody.RegisterCallback <FocusOutEvent>(s => { node.Dirty(ModificationScope.Graph); }); VisualElement typeRow = new VisualElement() { name = "Row" }; { typeRow.Add(new Label("Type")); typeRow.Add(m_Type); } Add(typeRow); VisualElement nameRow = new VisualElement() { name = "Row" }; { nameRow.Add(new Label("Name")); nameRow.Add(m_FunctionName); } Add(nameRow); switch (node.sourceType) { case HlslSourceType.File: VisualElement sourceRow = new VisualElement() { name = "Row" }; { sourceRow.Add(new Label("Source")); sourceRow.Add(m_FunctionSource); } Add(sourceRow); break; case HlslSourceType.String: VisualElement bodyRow = new VisualElement() { name = "Row" }; { bodyRow.Add(new Label("Body")); bodyRow.style.height = 200; bodyRow.Add(m_FunctionBody); } Add(bodyRow); break; } }
/// <summary> /// Visits the specified node. /// </summary> /// <param name="node">The node.</param> public void Visit(CustomFunctionNode node) { using (new DestinationNodeContext(node)) { var parsedFunction = node.FunctionName; for (var i = 0; i < node.Expressions.Count; i++) { StartTempMode(node); node.Expressions[i].AcceptVisitor(this); var var = EndTempMode(node); parsedFunction = parsedFunction.Replace("?" + (i + 1).ToString(), var); } AppendToResult(parsedFunction); } }
public void Visit(CustomFunctionNode node) { string parsedFunction = node.FunctionName; for (int i = 0; i < node.Expressions.Count; i++) { StartTempMode(); node.Expressions[i].AcceptVisitor(this); string var = EndTempMode(); parsedFunction = parsedFunction.Replace("?" + (i + 1).ToString(), var); } AppendToResult(parsedFunction); }
/// <summary> /// To the custom function node node. /// </summary> /// <param name="customFunction">The custom function.</param> /// <returns>CustomFunctionNode.</returns> private CustomFunctionNode ToCustomFunctionNodeNode(ExpressionObjectBase customFunction) { var customFunctionNode = new CustomFunctionNode(customFunction.FunctionName); foreach (var connection in customFunction.ConnectorsIn) { customFunctionNode.Expressions.Add(ToExpressionNode(connection.Connection.Source.Connection.Source.Owner, connection.Connection.Source.Connection)); } return customFunctionNode; }